This template includes multiple config files for project metadata, tooling, and CI.
Central project config: metadata, dependencies, and tool settings.
[project]
name = "project-name"
version = "1.0.0"
description = "Project description"
requires-python = ">=3.10,<3.14"
dependencies = [
"package1>=1.0.0",
"package2>=2.0.0",
]
[project.optional-dependencies]
dev = ["pytest>=7.0.0", "black>=23.0.0"]
docs = ["mkdocs>=1.4.0"][tool.poetry]
name = "project-name"
version = "1.0.0"
description = "Project description"
[tool.poetry.dependencies]
python = ">=3.10,<3.14"
package1 = ">=1.0.0"
[tool.poetry.group.dev.dependencies]
pytest = ">=7.0.0"# Black
[tool.black]
line-length = 88
target-version = ['py310', 'py311', 'py312', 'py313']
# Ruff
[tool.ruff]
line-length = 88
target-version = "py310"
select = ["E", "F", "I", "N", "W", "B", "C4", "UP"]
# MyPy
[tool.mypy]
python_version = "3.10"
warn_return_any = true
warn_unused_configs = true
# Interrogate
[tool.interrogate]
fail-under = 80
ignore-init-module = true
# Flake8
[tool.flake8]
max-line-length = 88
max-complexity = 10Multi-version test matrix.
[tox]
envlist = py310, py311, py312, py313
isolated_build = true
[testenv]
whitelist_externals = uv
commands_pre = uv sync --dev
commands = uv run pytest
commands =
uv run pytest --cov=src --cov-report=html
uv run pytest --cov=src --cov-report=term
[testenv:docs]
commands = uv run mkdocs buildGit hooks for automated checks.
repos:
- repo: https://github.com/psf/black
rev: '24.1.0'
hooks:
- id: black
- id: black-jupyter
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.0
hooks:
- id: ruff
- id: ruff-format
- repo: https://github.com/kynan/nbstripout
rev: 0.8.1
hooks:
- id: nbstripout
args: ['--keep-output']
- repo: https://github.com/econchick/interrogate
rev: 1.7.0
hooks:
- id: interrogate
args: [--verbose, --fail-under=80]Command shortcuts.
# Install deps and init
setup:
@uv sync --all-extras
@make configure-project
# Run tests
test:
uv run pytest
# Reports
report:
uv run allure serve tmp/allure_results
# Configure project
configure-project:
@uv run python scripts/configure_project.pyCustom commands example:
format:
@black src/ tests/
@isort src/ tests/
typecheck:
@mypy src/
clean:
@rm -rf build/ dist/ *.egg-info
@find . -type d -name __pycache__ -exec rm -rf {} +
@find . -type f -name "*.pyc" -delete
docs:
@uv run mkdocs buildGitHub Actions configuration.
Automated release flow:
- Create release PR
- Publish to PyPI
- Create GitHub release
PyPI secret: PYPI_TOKEN.
Application config (e.g., Hydra).
database:
host: localhost
port: 5432
name: myapp
api:
host: 0.0.0.0
port: 8000
debug: false
logging:
level: INFO
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"Dataset-specific configs:
mac.yamlwin.yaml
Use a .env file (do not commit):
# .env
DATABASE_URL=postgresql://user:pass@localhost/db
API_KEY=your-api-key
DEBUG=TrueLoad in code:
import os
from dotenv import load_dotenv
load_dotenv()
DATABASE_URL = os.getenv("DATABASE_URL"){
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.formatting.provider": "black",
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.mypyEnabled": true,
"python.testing.pytestEnabled": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}- Set interpreter to project venv
- Enable Black formatting
- Configure pytest
- Enable flake8 and mypy
- CLI args
- Environment variables
.env- Config files (
config.yaml) - Defaults
[tool.black]
line-length = 100
[tool.ruff]
line-length = 100[project]
requires-python = ">=3.11,<3.14"
[tool.poetry.dependencies]
python = ">=3.11,<3.14"[tool.interrogate]
fail-under = 90[tool.your-tool]
setting1 = "value1"
setting2 = "value2"- Version-control all configs
- Keep secrets in env vars
- Document config changes
- Keep team configs consistent
- Lint configs where possible
Edit pyproject.toml, then:
uv lock
poetry lock[tool.black]
exclude = '''
/(
\.git
| \.venv
| build
| dist
)/
'''pyenv install 3.12.0
pyenv local 3.12.0- See Quick Start
- Read Tooling
- Review Development Guide