Short project description
Table of Contents
This Python project is managed via Poetry, and leverages the pyproject.toml
configuration file, rather than the older setup.py
.
The pyproject.toml
configuration file can be and is also used to store 3rd party tools configurations, such as black, ruff, mypy etc.
In order to use poetry, you should install it first. If your OS package manager has
a python-poetry
package, you might also choose to install Poetry that way. Notice that if you do this, you should make sure that your OS
also ships all the necessary plugins you might want to use (most importantly, poetry-plugin-export
). As of the time of writing, Archlinux does.
Install the project, by using:
poetry install --with dev
This will install the necessary dependencies plus the dev dependencies, any binary shipped with the project, as well as create a dedicated virtual environment.
The virtual environment can be activated with:
source $(poetry env info -p)/bin/activate
Alternatively, you can also source the script activate.sh
in this repo:
source ./activate.sh
This has the advantage, over standard venvs management, that you don't need to remember the name of the environment for any project.
If you don't want the dev dependencies, simply install the project with poetry install
.
You can also install the project with pip
, since Poetry is PEP-517 compliant:
pip install .
# OR, using git+ssh
pip install git+ssh://[email protected]:strg-at/template-python.git
To add a dependency, simply run:
poetry add 3rd-party-package
To remove a dependency, run:
poetry remove 3rd-party-package
To add a dev dependency, run:
poetry add dev-dep-package --group dev
In this template, we also create one (or more) additional dependency group(s) to deal with IDE specific dependencies.
For instance, if you want to use the python-lsp-server, as well as installing
its plugins for mypy
etc., then you can use the lsp-dev
group.
poetry install --with dev --with lsp-dev
You can also generate a requirements.txt
with poetry. NOTICE that this is not mandatory at all, and should be done only for backward compatibility, IF necessary.
First, install the poetry-plugin-export
.
This can be done in several ways, depending on how you installed poetry.
If you installed poetry via your package manager, then you should install the plugin via your package manager. For instance, on Archlinux:
sudo pacman -S python-poetry-plugin-export
To generate the requirements, you can then run:
poetry export --without-hashes --format=requirements.txt > requirements.txt
Poetry has some nice shortcuts to manage the project version. You can see them by running
poetry version --help
For instance, bumping to the next minor version can be done with:
poetry version minor
This would be a project from, e.g., 1.2
to 1.3
. A major bump can be done with:
poetry version major
Poetry can do more than this, consult the documentation for more information.
Install pre-commit.
Pre-commit framework need to get initialized.
task pre-commit:init
Run coverage report.
sh ./coverage_report.sh
Name Stmts Miss Cover
---------------------------------------------------------------------------------------
template_python/template_python_package/template_python_module.py 6 0 100%
template_python/unittest/template_python_test.py 18 1 94%
---------------------------------------------------------------------------------------
TOTAL 24 1 96%
Run the following to fix linting issues using pre-commit.
task pre-commit:run
Based on pre-commit gitleaks dependencies Go language needs to be installed.
All changes require a PR and review. Create a new branch and reference a Jira ticket, f.e.
git switch -c feature/INPRO-1-configure-resource