Start a new python project running
pip install cookiecutter
cookiecutter gh:joamatab/cookiecutter-pypackage-minimal
It will ask you some questions to fill the template
If you want to run a branch or a different version
cookiecutter gh:joamatab/cookiecutter-pypackage-minimal --checkout branch_name
In this cookiecutter 🍪 template we combine state-of-the-art libraries and best development practices for Python.
The Makefile provides you with an easy way to:
- install: the package
- test: run tests
- cov: get test coverage
- mypy: check types
- ruff: fixer
Precommit hooks enforces that the code that you commit follows some standards:
You can comment them in .pre-commit-config.yaml
- Standard
- check-yaml
- end-of-file-fixer
- trailing-whitespace
- Black: format your code
- nbstripout: strips jupyter notebooks output, so they can be version controlled
- reorder-python-imports: sorts imports
- ruff
See .github/workflows
test_code.yml
: runs tests for code and docs. Usespip install
test_code_conda.yml
: runs tests. Usesconda
. Choose this one if some dependencies are only on conda. Otherwise delete this one.- release.yml: publishes to PyPI any new releases, need to add Pypi token to your Github account
- pages.yml: builds docs.
- README uses markdown format
- MIT license by default
This template provides you the classic MIT licence: it lets people do almost anything they want with your project, including to make and distribute closed source versions.
If you choose another license, you also need to update the
{{ package_name }}/setup.py
file: adjust theclassifiers
andlicense
fields accordingly.
- Uses pytest as the default test runner
This can be changed easily, though pytest is a easier, more powerful test library and runner than the standard library's unittest.
The
tests
directory should not be a Python package unless you want to define some fixtures. But the best practices are to use PyTest fixtures which provides a better solution. Therefore, thetests
directory has no__init__.py
file.
you can mix and match markdown and RST syntax in the index for your docs.
I prefer markdown but I also embed RST commands as
.. autofunction:: module.function_name
To build the docs you need to have the package itself installed, you can do this by:
cd path_to_your_repo
make install
cd docs
Alternatively, you can install the dependencies of the package as:
cd path_to_your_repo
make python-deps
cd docs
make html