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
+2 -2
View File
@@ -23,6 +23,6 @@ build/
# dist/
# --- Lock file ---
# Applications commit poetry.lock — leave the line below commented out.
# Applications commit uv.lock — leave the line below commented out.
# Libraries do not commit it — uncomment it there.
# poetry.lock
# uv.lock
+18 -15
View File
@@ -1,6 +1,6 @@
# Python Development Guidelines
**Document Version:** v11
**Document Version:** v12
> **Note on Versioning:**
> - This document version is independent — reused across projects
@@ -129,28 +129,31 @@ Define specific exception types. Use a fail-fast approach — surface errors ear
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
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 python install <version> # Install a uv-managed Python
```
Never edit `pyproject.toml` directly to add or remove dependencies.
### poetry.lock
The interpreter is a uv-managed Python — no pyenv, no system Python.
`poetry.lock` **is committed** for applications — it pins the exact dependency graph and keeps builds reproducible.
### uv.lock
`uv.lock` **is committed** for applications — it pins the exact dependency graph and keeps builds reproducible.
---
@@ -162,7 +165,7 @@ project/
├── src/ # All application modules
├── tests/ # Tests
├── docs/ # Detailed documentation
├── .venv/ # Virtual environment (managed by Poetry)
├── .venv/ # Virtual environment (managed by uv)
└── pyproject.toml # Project config and dependencies
```
@@ -193,8 +196,8 @@ When a project is distributed as a standalone executable (no Python required on
Build commands:
```bash
poetry run python prebuild.py
poetry run pyinstaller ToolName.spec
uv run python prebuild.py
uv run pyinstaller ToolName.spec
```
> This section applies only to projects that produce standalone executables. Skip for libraries or web services.
+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`.
+2 -2
View File
@@ -14,7 +14,7 @@ template/
├── <tool_name>.py # Entry point — named by purpose or tool name
├── <tool_name>.spec # PyInstaller spec (only for projects shipping an .exe)
├── prebuild.py # Pre-build script: venv check, version print, console= rewrite
├── pyproject.toml # Poetry config (ruff, mypy, pytest)
├── pyproject.toml # Project config (ruff, mypy, pytest)
├── docs/
│ └── .gitkeep # Detailed documentation lives here, never in the root
├── src/
@@ -36,7 +36,7 @@ copies themselves **are committed** with the project and are never edited in pla
- **DEBUG mode** via `ENV_DEBUG=true` in `.env` (adds "DEV" suffix to version: v1.2.3DEV)
- **Build configuration** via `ENV_BUILD_CONSOLE` and `ENV_BUILD_SPEC` in `.env`, applied by `prebuild.py`
- **loguru** for logging (never print for debugging)
- **Poetry** for dependency management, `poetry.lock` committed
- **uv** for dependency management and Python versions, `uv.lock` committed
- **pytest** for testing (no unittest)
- **ruff + mypy** for linting and type checking (120-character lines)