Package management¶
Prerequisite¶
Install uv on your machine.
Project management tool, especially dependencies, build distributions etc. See the git repo
and the docs.
The dependencies (the external package that your code uses) are installed in a virtual environnement (in the .venv folder).
The role a virtual environment is to isolate every dependency of a given project because dependencies can differ between projects.
Installation¶
if uv not found, it might be missing from the path, on linux:
$ export PATH="$HOME/.local/bin:$PATH"
Typical structure¶
.
├── docs
├── .git
├── .gitignore
├── pyproject.toml
├── .python-version
├── README.md
├── src
│ └── package
│ ├── __init__.py
│ └── module.py
├── tests
├── uv.lock
├── .venv
└── .vscode
Other packages can live in a folder under src.
Basic usage¶
Initialize a project and open the folder (check the pyproject.toml), with PACKAGE and PROJECT being
restpectively the package name and the project name.
$ uv init PROJECT --name PACKAGE
Install the latest python:
$ uv python install
To open a python console:
$ uv run python
Add a dependency for development
$ uv add --dev pytest
Add a dependency (check the pyproject.toml)
$ uv add FOO
Remove a dependency (check the pyproject.toml)
$ uv remove FOO
Run a python module with PATH being the path to sources:
$ uv run PATH/FILE.py
Run tests (the tests will be covered in more details during a future session)
$ uv run pytest
Basic usage¶
Demo
# init a project, add a module
# add / remove dependecies
# run a python file and a test