A cookiecutter template for a Python 3 package, with a special focus on scientific computing.
The Wiki describes the best practices realized by this template in detail.
src
directory. See https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-structure for the reasoning behind this.isort
tox
for convenience on Unix. Run make help
inside the generated project for details.make release
First, make sure to have cookiecutter
installed:
pip install cookiecutter
Then, create a new project with
cookiecutter gh:goerz/cookiecutter-pypackage
Follow the prompts. You can also pass values for variables on the command line, e.g.
cookiecutter gh:goerz/cookiecutter-pypackage --no-input interactive_postsetup=no project_name="My Project"
full_name
: Full author name, will show up in README, in the module, and on PyPIemail
Author email addressgithub_username
Username (or organization name) on githubproject_name
: The name of the package on PyPI, also the name of the folder that will be generatedproject_slug
: The name of the repository as it appears in Github URLsproject_short_description
: (Short) description to appear as the doc-string of the module, in the documentation of the console script, in the README, and on PyPIversion
: Initial version of the packagecreate_author_file
: Whether to create AUTHORS.rstopen_source_license
: The license under which the code will be available .use_isort
: Whether to require that all imports are sorted according to the isort
utilityuse_black
: Whether the black code formatter should be used to enforce code styles. This enables make black
, make black-check
, and the underlying tox environments, as well as automatic checking of the code style on Travis.use_pre_commit
: Whether to use pre-commit to manage git pre-commit hooks. A local hook for checking for trailing whitespace and DEBUG lines is always included, as well as third-party hooks for isort
and black
if use_isort
and use_black
are True.linelength
: The allowed line length of code lines (for black
formatting). PEP 8 requires 79 characters. This is not a hard limit; code may extend beyond the linelength
if this increases readability.allow_single_quote_strings
: Whether strings are allowed to be enclosed in single quotes, cf. -S
option of black
.on_pypi
: Whether the package will be uploaded to the Python Package Indextravisci
: Whether Travis will be used as a Continuous Integration testing servicetravis_texlive
: Whether texlive should be installed on Travis. This may be required for building the documentation. Required for downloadable PDF documentation through Doctr.appveyor
: Whether AppVeyor will be used as a Continuous Integration testing service for Windowsappveyor_username
: Username on AppVeyorcoverage
: Which service to use for keeping track of code coveragesphinx_docs
: Whether the package will use Sphinx to generate its documentationuse_notebooks
: Whether Jupyter notebooks will be included in the Sphinx documentation, and validated through pytest
.better_apidoc
: Whether to use https://github.com/goerz/better-apidoc for generating the package API for Sphinx.docshosting
: Which service to use for hosting the Sphinx-generated documentation. The following choices are available:
doctr_artifact_hosting
: If docshosting
is "Doctr", which provider to use for binary documentation artifacts (e.g. zipped-html/epub/pdf versions of the documentation linked in the "Download" menu. The following choices are available:
support_py35
: Does the package support Python 3.5?support_py36
: Does the package support Python 3.6?support_py37
: Does the package support Python 3.7?support_py38
: Does the package support Python 3.8?support_py39
: Does the package support Python 3.9?main_python
: The version of Python to use for development tasks like building the documentationuse_git_flow
: Whether the project uses the git-flow branching modelinteractive_postsetup
: Whether to run the interactive post-setup script, which will e.g. set up git for the projectAfter you generate a new project from the cookiecutter template, you should do the following:
Declare dependencies in setup.py
, both for installation and development (testing). There are no additional pip requirement files (These are for app deployment, not for packages!).
If you didn't do so during project creation, initialize git and push the project to Github
Activate ReadTheDocs or Doctr. For ReadTheDocs, log in to https://readthedocs.org/dashboard/, and click the "Import a Project" button. You shouldn't have to do any configuration, as everything is set up through the .readthedocs.yml
file. For Doctr, if you did not already do so during the interactive post-setup script, run tox -e run-cmd -- doctr configure --no-upload-key --no-authenticate --key-path docs/doctr_deploy_key
and set the Doctr deploy key in the Github settings according to the instructions printed by doctr configure
. Update your .travis.yml
file with the encrypted deploy key, and with any deploy keys required for uploading documentation artifacts (doctr_artifact_hosting
).
If using better-apidoc, review the custom RTD templates in docs/_templates
.
If you are using the git-flow branching model, you must configure this on Github. Go to the "Settings" for the project, then "Branches", and switch the "Default branch" from "master", to "develop". You may consider protecting the master branch.
Activate Travis CI. The easiest way to do this is to click on the build|unknown
badge in the README on Github
Activate AppVeyor. The easiest way to do this is to click on the appveyor|no id
badge in the README on Github. You must update the badge svg in README.rst
and docs/index.rst
.
Activate Coveralls or Codecov. For Coveralls, log in to https://coveralls.io, and click on "Add Repo". Not that coverage data is only uploaded if all tests pass successfully!
Review the classifiers in setup.py
. The full list of PyPI classifiers can be found here.
If you are using pre-commit, review the .pre-commit-config.yaml
file, especially for whether you will want to use more recent rev
s for third-party hooks.
If the package should be registered on PyPI, upload it. You can do this with make release
.
Make sure to tag releases on Github (using a leading v
in the tag name, e.g. v0.1.0
)
Activate branch protection for the master
branch (and develop
branch, if using the git flow branching model), to prohibit history rewriting for these branches.