Migrate Python guidelines from Poetry to uv

This commit is contained in:
2026-10-13 17:58:03 +02:00
parent 355a63fc43
commit 4689cd45bc
7 changed files with 75 additions and 47 deletions
+28 -24
View File
@@ -1,6 +1,6 @@
# Python Library Development Guidelines
**Document Version:** v4
**Document Version:** v5
> **Note on Versioning:**
> - This document version is independent — reused across projects
@@ -140,27 +140,30 @@ Define specific exception types in `src/<package>/exceptions.py`. Use a fail-fas
Run before every commit:
```bash
poetry run ruff check
poetry run mypy
poetry run pytest
uv run ruff check
uv run mypy
uv run pytest
```
---
## 11. Poetry
## 11. uv
```bash
poetry install # Install all dependencies
poetry add <pkg> # Add runtime dependency
poetry add --group dev <pkg> # Add dev dependency
poetry remove <pkg> # Remove dependency
poetry run <cmd> # Run command in virtualenv
poetry build # Build sdist and wheel into dist/
poetry publish # Publish to PyPI
uv sync # Install all dependencies
uv add <pkg> # Add runtime dependency
uv add --dev <pkg> # Add dev dependency
uv remove <pkg> # Remove dependency
uv run <cmd> # Run command in virtualenv
uv build # Build sdist and wheel into dist/
uv publish # Publish to PyPI
uv python install <version> # Install a uv-managed Python
```
Never edit `pyproject.toml` directly to add or remove dependencies.
The interpreter is a uv-managed Python — no pyenv, no system Python.
### pyproject.toml configuration for a library
```toml
@@ -171,19 +174,20 @@ description = "Short description"
requires-python = ">=3.x"
dependencies = []
[tool.poetry]
packages = [{include = "your_library", from = "src"}]
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"
requires = ["uv_build>=0.13.0,<0.14.0"]
build-backend = "uv_build"
```
Do **not** add `[tool.poetry.scripts]` — libraries have no entry points.
`uv_build` finds the package at `src/<name>/` on its own, with the dashes in the project name turned
into underscores — no package list is needed. Keep the upper bound on `uv_build`; `uv init --lib`
writes the range that matches the installed uv.
### poetry.lock
Do **not** add `[project.scripts]` — libraries have no entry points.
Do **not** commit `poetry.lock` for libraries. It is only committed for applications. Add `poetry.lock` to `.gitignore`.
### uv.lock
Do **not** commit `uv.lock` for libraries. It is only committed for applications. Add `uv.lock` to `.gitignore`.
---
@@ -198,7 +202,7 @@ project/
│ └── ... # Internal modules
├── tests/ # Tests
├── docs/ # Detailed documentation
├── .venv/ # Virtual environment (managed by Poetry)
├── .venv/ # Virtual environment (managed by uv)
└── pyproject.toml # Project config and dependencies
```
@@ -218,11 +222,11 @@ project/
## 14. Distribution
Build and publish with Poetry:
Build and publish with uv:
```bash
poetry build # Creates dist/*.tar.gz and dist/*.whl
poetry publish # Publishes to PyPI (requires credentials)
uv build # Creates dist/*.tar.gz and dist/*.whl
uv publish # Publishes to PyPI (requires credentials)
```
`dist/` is **not committed** to the repository — add it to `.gitignore`.