Giter VIP home page Giter VIP logo

cookiecutter-flask-pythonic's Introduction

cookiecutter-flask-pythonic

Forked from cookiecutter template for a Python package. Forked from audreyr/cookiecutter-pypackage + tony/cookiecutter-pypackage-pythonic.

It is inspired by flask and werkzeug's project style patterns. It is used on the tmuxp, cihai-python and vcspull projects. The app object is based on early versions pypa/warehouse, when it used werkzeug (see warehouse's old app object).

  • Free software: BSD license
  • Vanilla testing setup with unittest and python setup.py test
  • Travis-CI: Ready for Travis Continuous Integration testing
  • Tox testing: Setup to easily test for Python 2.6, 2.7, 3.3
  • Sphinx docs: Documentation ready for generation with, for example, ReadTheDocs. Note: You can install sphinx docs requirements with $ pip install -r docs/requirements.txt.

Additions and changes

  • (feature) app factory can be configured with ini, yaml or json (pypa/warehouse, cihai style) and by specifying options via CLI. Flask-Script only supports -c config_file. Application factory can be wired to support option args and config file (pypa/warehouse, cihai)
  • (feature / removal) - use flask testing client for tests, remove dependency on flask-testing.
  • (feature) config file declaratively pulls blueprints from python paths add them in the app factory.
  • (coverage) unittests against flask api, blueprint example module.

Testing

  • flask/werkzeug-style testsuites. See werkzeug testsuite on github.

  • Use run-tests.py to run all tests, or pass in arguments to test a particular TestSuite, TestCase or Test:

    $ ./run-tests.py
    $ ./run-tests.py yourpackage
    $ ./run-tests.py repo_name.repo_name  # package_name.TestSuite
    $ ./run-tests.py yourpackage.testsuite.test_something
    $ ./run-tests.py testsuite.test_something
    $ ./run-tests.py test_something
    $ ./run-tests.py test_something test_something_docstring
  • setup.py downloads unittest2 for python 2.6.

Python 2.7+3.3

  • from __future__ import absolute_import, division, print_function, \
        with_statement, unicode_literals
  • repo_name/_compat.py module (derived from flask, werkzeug and jinja2.) Why a compatibility module? See Armin Ronacher's post Porting to Python 3 Redux.

Packaging

  • repo_name/__init__.py + repo_name/__about__.py: Metadata in repo_name/__init__.py e.g. __title__, __author__ can be accessed via:

    >>> about = {}
    >>> with open("repo_name/__about__.py") as fp:
    >>>     exec(fp.read(), about)
    >>> print(about['__title__'])
    Your project name

    Keeps setup.py and doc/conf.py in sync with package metadata. pypi and readthedocs distributions build off the latest package data.

    This method avoids cost of tokenizing and importing python file and avoids encountering potential import errors that may arise. It simply opens a vanilla python file and evals it.

    Derived from pypa/warehouse.

  • Relative imports in repo_name/__init__.py.

  • Relative imports in repo_name/testsuite/__init__.py.

  • Relative imports in repo_name/testsuite/{{ cookiecutter.package_name }}.py.

Docs

  • README.rst reStructuredText table for project information.
  • vim modelines for rst in TODO and CHANGELOG.
  • docs/requirements.txt, which can be targetted to install sphinx changelog package on ReadTheDocs. It will also trigger -r ../requirements.txt.
  • sphinx changelog module, (imitation of sqlalchemy, see sqlalchemy changelog)
  • Add TODO and docs/roadmap.rst.
  • Rename CHANGELOG.rst -> CHANGELOG.
  • Add docs/api.rst for documentation of API code. Initial class imported with docstring example.
  • Automatically generate header spacing based on length of cookiecutter variables.

Example data

  • Example TestCase.
  • Example Class w/ docstrings.

Usage

Install cookiecutter:

$ sudo pip install cookiecutter

Generate a Python package project:

$ cookiecutter https://github.com/tony/cookiecutter-flask-pythonic.git

Then:

Not Exactly What You Want?

Don't worry, you have options:

Similar Cookiecutter Templates

Testing

$ pip install -r dev-requirements.txt
$ sniffer
# edit any file in {{cookiecutter.repo_name}}
# todo: add run-tests.py for one-time runs

Fork This / Create Your Own

If you have differences in your preferred setup, I encourage you to fork this to create your own version. Or create your own; it doesn't strictly have to be a fork.

  • Once you have your own version working, add it to the Similar Cookiecutter Templates list above with a brief description.
  • It's up to you whether or not to rename your fork/own version. Do whatever you think sounds good.

Or Submit a Pull Request

I also accept pull requests on this, if they're small, atomic, and if they make my own packaging experience better.

cookiecutter-flask-pythonic's People

Contributors

dependabot-preview[bot] avatar pyup-bot avatar tony avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.