Important: For regular projects that have already been initialized, these instructions don't apply.
Template setup instructions:
- Update the python version if necessary:
- Update
.python-version
to set your project's python version. - Update "target-version" in
pyproject.toml
. This field is used by tools likeruff
(a linter) to determine what language features to support. Set this to match.python-version
or set it to a lower value for greater backwards compatibility. - Update
tool.poetry.dependencies.python
variable inpyproject.toml
- Update
[.pre-commit-config.yaml](.pre-commit-config.yaml)
"language_version" variable - Update your /.github/workflows
matrix.python-version
arrays
- Update
- Update project variables
pyproject.toml
:- Set project
name
variable - Set project
description
variable - Set project
version
variable - Set project
authors
variable
- Set project
- Change folder "package_name" to match your project name
- Update README title
- Follow the instructions in the Setup section
- Remove this section from README
Manage python version with pyenv. Just install pyenv and make sure you have the correct python version installed before setting up your virtual env below:
pyenv install $(cat .python-version)
Make sure you have poetry installed:
- Poetry can be installed via pipx
- Install poetry with:
pipx install poetry
Set the poetry config with:
poetry config virtualenvs.prefer-active-python true
poetry config virtualenvs.in-project true
The prefer-active-python
setting tells poetry to use the version of python currently active in the shell. This will ensure that your pyenv
python version is respected by poetry.
The virtualenvs.in-project
setting tells poetry to save your virtual env within your project instead of in a global cache.
Setup your venv and install requirements:
poetry shell
poetry install
poetry upgrade
Install git hooks:
pre-commit install
To run unit tests:
pytest
Use poetry to manage your virtual env
Activate your venv with:
poetry shell
Deactivate your venv with:
exit
To check linting rules:
ruff check .
To automatically fix linting issues where possible:
ruff check --fix .
black .
Add dependencies:
poetry add <dep1> <dep2>
Add a dev dependency:
poetry add --group=dev <dep>
Add a test dependency:
poetry add --group=test <dep>
Update a dependency:
poetry upgrade <dep>
Update all dependencies:
poetry upgrade