This template should be used for every Python project in the lab. It uses:
uvfor dependency management.rufffor code formatting.pyrightfor type checking.- pre-commit hooks for automated validation.
We use uv for dependency management. It is just as
full-featured as poetry, but much faster. Follow the instructions below to
create a new project:
-
Update the name of the project in
pyproject.toml. -
Change the name of the folder
src/python-baseto match the project name. -
Run
uv syncfrom the root of the repo. This will create a virtual environment and install needed development dependencies. -
Add the dependencies you need (and run this same command every time you need a new package):
uv add polars lightgbm
-
Take a look at the
uv's Getting started guide.
First, install pre-commit:
uv add install pre-commitThen, install the pre-commit hooks:
uv run pre-commit installThis will create a .git/hooks/pre-commit file that will run the pre-commit
hooks every time you commit. Upon the first commit, the hooks will be installed.
Some hooks output error message that require a manual change (e.g., linting errors). Other hooks perform automated fixes. Either way, you need to re-run the commit command:
git commit -m "My message"Among the pre-commit hooks, you will find one that runs
ruff on every Python file. It is also warmly
recommended that you set up ruff in your IDE (e.g., Visual Studio Code, PyCharm).
We recommend the use of type hints
of your code. One of the pre-commit hooks is pyright,
which will perform type checking when hints are available. This reduces greatly the
risk of bugs and the maintainability of the code.