Purpose: Notes on good ideas for organizing and developing a Python project.
Use a src
-layout
package layout.
Use venv
for virtual environment.
conda
can be used but are best for scientific
computing.
Install the package in development mode / editable mode. This enables us to edit the package on the fly without the need to reinstall it.
Use the autoreload
magic command when making prototypes in a notebook. And use
Cython
magic commands when prototyping Cython code.
Use pytest
and put the tests in a tests/
folder in the same directory.
Often used tools for testing in Python are
pytest
(most common and the best) and
unittest
.
Use sphinx
for documentation.
mkdocs
seems like the new kid on the block but
sphinx
is older and more used.
Write doctests when writing documentation. Doctest can be run with pytest.
Use pyright
for type checking.
Often used are flake8
or for automatic code
formatting people often use black
.
pre-commit is often used
to run a series of checks before making commits to git e.g.
black
code formatting, pyright
,
isort
etc.
The logging
module is a nice debugging tool in
Python, use it.
cookiecutter can be used to create a template Python project.
Use PEP 8. And think about the public and non-public API. Default to non-public attributes, API etc.
Use Github flow. See this discussion.
Use Githubs workflows for CI/CD pipelines.
Use the pypi package index.
You can create your own package index on premise
(conda
is pretty easy). Other solutions for an on
premise package index exists like fury.
Use semantic versioning e.g.
MAJOR.MINOR.PATCH and git tag
each version and push
to the remote.
versioneer
seems like a cool project to automate parts of the versioning
process.
Feel free to comment here below. A Github account is required.