Use this template to bootstrap new Python projects fast and unified.
This tools are language agnostic and don’t belong to a single project. Install them locally for your user or globally for your system.
-
GNU Make for workflow automation
-
pre-commit for Git hooks
-
Nitpick for project configuration management
-
pyenv for Python version management
Note
|
I recommend pipx for Python application management, but it is not required for this template. |
To create a new project, install and run Cookiecutter
$ cookiecutter https://github.com/andreaslongo/cc-python.git
Or install and use pipx (recommended)
$ pipx run cookiecutter https://github.com/andreaslongo/cc-python.git
Note
|
Make sure you are working in a Python virtual environment for the following steps. |
Compile the project dependencies
cd python-project
make compile-dependencies
Initialize the project for development
make init
Note
|
You may have to refresh your shell environment before the next step. |
Run the test suite
make test
python-project/
| requirements-dev.in
| requirements-dev.txt
| requirements.in
| requirements.txt
-
.in
files contain the actual dependencies. Add your dependencies to this files manually. -
.txt
files are pinned and hashed results ofpip-compile
. Use this files to install your dependencies.
Depending on the environment, the dependencies of Python packages may vary.
An environment is (simplified): Operating system + Python version (3.8, 3.9, …) + Python interpreter (CPython, PyPy, …)
If your project supports multiple environments, run pip-compile
on each environment to generate different .txt
files, valid for each environment.
You can use the same .in
files for all environments.
Do not use the same .txt
files for different environments, even if the generated output is the same.
Any change or update to dependencies or their sub-dependencies might introduce new environment dependent dependencies.
An example {environment}-requirements.txt
format:
python-project/
| requirements-dev.in
| requirements-dev.txt
| requirements.in
| linux-py3.6-requirements.txt
| macos-py3.7-requirements.txt
| win32-py3.8-requirements.txt
See also: Cross-environment usage of pip-compile