Template for Python code using poetry and pre-commit.
.
├── folder # sample folder
│ └── file # sample file
├── .flake8 # `flake8` Python style enforcement config file
├── .gitignore # ignore files that cannot be committed to Git
├── .pre-commit-config.yaml # `pre-commit` hook config file
├── poetry.lock # lock versions of dependencies managed by poetry
├── pyproject.toml # build system dependencies
└── README.md # this file
poetry
is a Python packaging and dependency management tool. If you don't already have poetry
:
pip install poetry
Then install dependencies via poetry
:
poetry install
(Note: The remaining commands assume you are in a poetry shell. If you aren't, follow the instructions in the section Activating the virtual environment.)
Follow the steps below to set the interpreter for the project in VSCode. This enables the IDE to read Python scripts and Jupyter notebooks.
(Note: This is a one-time process and need not be repeated afterwards.)
Create a poetry shell in the project directory:
poetry shell
It should print the path of the poetry
shell in the format below (I use Python 3.8.10 on Windows 11):
Spawning shell within C:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\{{path depending on project name and python version}}
Restart VSCode and open a Jupyter notebook. Click the interpreter.
Choose the path generated above, and the configuration is done.
Exit/deactivate (if needed):
exit
After setting up poetry
, install the pre-commit
hook:
pre-commit install
You can optionally run the pre-commit hook manually:
pre-commit run --all-files
This project uses: