This is a simple template for a python package development repository. The project
defines setup.py
and pyproject.toml
with all the standard configuration one
might want for a python package development, such as unit testing with pytest
(including docstring and documentation testing and coverage), code formatting by
black
and testing on a matrix of python versions and dependency versions powered
by tox
.
The package source code is structured in the src
directory, which means that
the package needs to be pip installed
to run tests and development, which appears
to be an agreed upon best practice for package development.
A full CI/CD pipeline is implemented via GitHub Actions. On any push to master
,
GitHub actions:
- Run all the tests with
pytest
andtox
on a matrix of supported python versions and dependency versions. - Check if the project code is
black
-formatted.
On any GitHub release, actions:
- Publish the package to PyPI.
The pkg-template-mh
package can be installed either from PyPI
python3 -m pip install pkg-template-mh
or from the GitHub page
python3 -m pip install git+https://github.com/hanicinecm/template-python-package.git
It goes without saying that any development should be done in a clean virtual
environment.
After cloning or forking the project from its GitHub page, pkg-template-mh
can be
installed into the virtual environment in the editable mode by running
pip install -e .[dev]
The [dev]
extra installs (apart from the package dependencies) also several
development-related packages, such as pytest
, black
, or tox
.
The tests can then be executed by running (from the project root directory)
pytest --cov
The project does not have the requirements.txt
file by design, as all the package
dependencies are rather handled by the setup.py
.
The package therefore needs to be installed locally to run the tests, which grants the
testing process another layer of usefulness.
Docstrings in the project adhere to the Google Python Style Guide.
The project code is formatted by black
.
Always make sure to format your code before submitting a pull request, by running
black
on all your python files.
>>> print("hello, world!")
hello, world!
>>> from pkg_template.module import get_dataframe
>>> get_dataframe((2, 3))
a b c
0 0 1 2
1 3 4 5