4. pyproject.toml Configuration
4.1 Overview
The pyproject.toml file serves as the central configuration hub for the project,
consolidating metadata, dependency management, and tool settings in a single,
standardized location. It follows the PEP 621
specification, which defines a uniform format for Python project metadata and
facilitates interoperability between tools. By leveraging pyproject.toml, the project
achieves modular dependency management, consistent tool behavior, and simplified setup
for both development and production environments.
4.2 Build System: [build-system] Section
Defines the build backend used for packaging:
1 2 3 | |
This configuration uses uv_build as the build backend, enabling fast and reliable
package building.
4.3 Project Metadata: [project] Section
The [project] section defines fundamental information about the project:
1 2 3 4 5 6 7 8 9 | |
These fields ensure that packaging tools, dependency managers, and documentation
generators can automatically retrieve key project information. The keywords field
improves discoverability on PyPI.
4.4 UV Configuration: [tool.uv] Section
Configures the UV package manager behavior:
1 2 3 4 5 6 7 8 9 | |
default-groups = "all": Installs all dependency groups by default.cache-keys: Defines cache invalidation triggers based on file changes and git commits.environments: Specifies supported platforms (Linux).required-environments: Restricts to Linux x86_64 architecture.
4.4.1 UV Build Backend: [tool.uv.build-backend] Section
1 2 3 | |
Configures the module name and root directory for the build backend.
4.5 Dependency Management: [dependency-groups] Section
Dependencies are organized into logical groups, allowing selective installation based on project requirements. This modular approach supports both development and production workflows.
4.5.1 pipeline Group: Development Tools
The pipeline group includes tools essential for code quality, testing, security, and
automation:
bandit: Security analysis tool for detecting common vulnerabilities.complexipy: Measures cyclomatic complexity to identify potentially unmaintainable code.mypy: Static type checker to detect type inconsistencies.pytest: Framework for running unit tests.ruff: A high-performance linter and automatic formatter.isort: Sorts imports according to standard conventions.deadcode: Detects unused or unreachable code.pre-commit: Manages Git pre-commit hooks for automated checks.
4.5.2 documentation Group: Documentation Tools
The documentation group contains tools for building and maintaining project
documentation:
mkdocsandmkdocs-material: Static site generator and material design theme.mkdocstrings[python]: Generates API documentation directly from Python docstrings.mkdocs-git-revision-date-localized-plugin: Displays last update dates for pages.mkdocs-git-authors-plugin: Shows contributors for each page.mkdocs-enumerate-headings-plugin: Automatically numbers headings.mkdocs-awesome-nav: Enhances navigation capabilities.mike: Provides versioned documentation management.
4.6 Tool-Specific Configuration
4.6.1 Ruff: [tool.ruff]
The Ruff linter is configured to enforce code style, detect errors, and simplify code:
1 2 3 4 | |
line-length = 88: Maximum line length following Black's convention.indent-width = 4: Standard Python indentation.extend-exclude: Additional patterns to exclude (Jupyter notebooks).
4.6.1.1 Ruff Lint Rules: [tool.ruff.lint]
1 2 3 | |
E: Enforces PEP 8 style guidelines.F: Detects Pyflakes errors such as unused imports.UP: Applies modern Python syntax checks and upgrades.B: Detects common programming bugs.SIM: Suggests code simplifications to improve readability.ignore = ["E203"]: Ignores whitespace before ':' (conflicts with Black).
4.6.1.2 Ruff Docstring Style: [tool.ruff.lint.pydocstyle]
1 2 | |
Enforces Google-style docstring conventions.
4.6.1.3 Ruff Formatter: [tool.ruff.format]
1 2 3 4 5 6 | |
Configures automatic code formatting with double quotes, space indentation, and formats code blocks within docstrings.
4.6.2 Mypy: [tool.mypy]
Mypy performs static type checking, ensuring type safety and consistency:
1 2 3 4 5 | |
check_untyped_defs = true: Validates functions even if type annotations are missing.ignore_missing_imports = true: Avoids errors for third-party modules without type stubs.exclude: Directories to skip during type checking.cache_dir = "/dev/null": Disables caching to avoid stale cache issues.
4.6.3 isort: [tool.isort]
isort enforces a standardized import order, improving code readability and maintainability:
1 2 3 4 5 6 7 8 9 10 11 12 | |
Imports are grouped as follows:
- FUTURE: Future imports (
from __future__ import ...). - STDLIB: Python standard library modules.
- THIRDPARTY: External dependencies installed via package managers.
- FIRSTPARTY: Modules developed within the current project.
- LOCALFOLDER: Relative imports for local submodules or packages.
The configuration uses Black-compatible formatting with custom section headings for better organization.
4.6.4 deadcode: [tool.deadcode]
Detects unused code in the project:
1 2 | |
Excludes virtual environments and test directories from dead code analysis.