Skip to content

Utility to create a basic Python project structure with tests, CI etc.

License

Notifications You must be signed in to change notification settings

instituteofcancerresearch/python-cookiecutter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cookiecutter-python

A tool to automatically create a Python project structure ready to release via GitHub and PyPI. It will also set up:

To set up:

First install cookiecutter:

pip install cookiecutter

Then run:

cookiecutter https://github.com/adamltyson/python-cookiecutter

Then you will be asked a series of questions about how you want to set up your project

For each one, type your answer, enter a single number (or just hit return) to choose from a default option.

  • full_name [Python developer]: - e.g. Adam Tyson
  • email [yourname@example.com]: - e.g. cookiecutter@adamltyson.com
  • github_username_or_organization [githubuser]: - e.g. adamltyson
  • package_name [python-package]: - e.g. my-awesome-software
  • Select github_repository_url: - Default will be e.g. https://github.com/adamltyson/my-awesome-software, but you can also provide this later.
  • module_name [my_awesome_software]: - The default will be the same as package_name but with hyphens converted to underscores.
  • short_description [A simple Python package] - Enter a simple, one-line description of your Python package.
  • Select license: - choose from:
    • 1 - BSD-3
    • 2 - MIT
    • 3 - Mozilla Public License 2.0
    • 4 - Apache Software License 2.0
    • 5 - GNU LGPL v3.0
    • 6 - GNU GPL v3.0

To use:

Installation For a local, editable install, in the project directory, run:

pip install -e .

For a local, editable install with all the development tools (e.g. testing, formatting etc.) run:

pip install -e .[dev]

Pre-commit hooks Running pre-commit install will run set up pre-commit hooks to ensure the code is formatted correctly. Currently these are:

  • black for code structure formatting (maximum line length set to 79)
  • flake8 to enforce PEP8

These will prevent code being committed if any of these hooks fail. To run them individually:

black ./
flake8

Automated versioning

bump2version is used to enforce a consistent style for version numbers, and create git tags as appropriate.

.bumpversion.cfg defines in which files the version will be updated (setup.cfg, <MODULE_NAME>/__init__.py) and how.

Running bump2version will update version numbers throughout the code and, commit the changes to git and tag the commit. The current version is 0.0.1 and there are five version types set up:

  • bump2version patch, e.g. bump from 0.0.1 to a release candidate 0.0.2rc0
  • bump2version minor, e.g. bump from 0.0.1 to a release candidate 0.1.0rc0
  • bump2version major, e.g. bump from 0.0.1 to a release candidate 1.0.0rc0
  • bump2version rc, e.g. bump from 0.1.0rc0 to create a new release candidate 0.1.0rc1
  • bump2version release, e.g. bump from 0.1.0rc0 to create a new release 0.1.0

To ensure the tags are pushed to GitHub:

git push --follow-tags

Test structure

A pytest test suite can be run with pytest. A template structure for this is in tests.

GitHub actions workflow A GitHub actions workflow (.github/workflows/test_and_deploy.yml) has been set up to run (on each commit/PR):

  • Linting checks (black, flake8, mypy).
  • Pytest (only if linting checks pass)
  • Release to PyPI (only if tests pass). Requires TWINE_API_KEY from PyPI to be set in repository secrets.

About

Utility to create a basic Python project structure with tests, CI etc.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%