| Concern | Tool | Version Strategy |
|---|---|---|
| Linter | ruff | Latest in container |
| Formatter | ruff format | Latest in container |
| Security | bandit | Latest in container |
| Security | semgrep | Latest in container |
| Tests | pytest | Latest in container |
| Type Check | mypy | Latest in container |
Config file: ruff.toml or pyproject.toml under [tool.ruff].
Recommended ruff.toml:
line-length = 120
target-version = "py311"
[lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"B", # flake8-bugbear
"S", # flake8-bandit (subset)
"C4", # flake8-comprehensions
"SIM", # flake8-simplify
]
[format]
quote-style = "double"
indent-style = "space"ruff replaces flake8, isort, pyupgrade, and black. Do not install those tools separately.
Config in pyproject.toml:
[tool.bandit]
exclude_dirs = ["tests"]
skips = []No project-level config file required. Uses --config auto to pull community rulesets.
Config in pyproject.toml:
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-v --tb=short"Config in pyproject.toml:
[tool.mypy]
python_version = "3.11"
strict = true
warn_return_any = true
warn_unused_configs = true| Target | Command | Description |
|---|---|---|
_lint |
ruff check . |
Lint all Python files |
_lint |
mypy . |
Static type checking |
_format |
ruff format --check . |
Check formatting (no changes) |
_format (fix) |
ruff format . |
Apply formatting fixes |
_security |
bandit -r . |
Security-focused static analysis |
_security |
semgrep --config auto . |
Pattern-based security scanning |
_test |
pytest |
Run test suite |
See DEVELOPMENT.md for the full Makefile contract and two-layer delegation pattern.
These run on every commit via pre-commit:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "" # container manages version
hooks:
- id: ruff
args: [--fix]
- id: ruff-formatThese run via make security and make test in CI pipelines. They are not configured as pre-commit hooks due to execution time:
bandit -r .-- security scanningsemgrep --config auto .-- pattern-based scanningpytest-- full test suitemypy .-- type checking (when project is large)
- ruff is the single tool for both linting and formatting. Do not use flake8, isort, black, or autopep8.
mypyruns as part ofmake lint, not as a separate target.banditandsemgreprun as part ofmake security. They are complementary: bandit catches Python-specific issues, semgrep applies broader security patterns.- All tools are pre-installed in the dev-toolchain container. Do not install them on the host.
- Python CLIs in DevRail repos use Click for argument parsing (see DEVELOPMENT.md Shell Script Conventions).
- For cross-cutting practices (DRY, idempotency, error handling, testing, naming) and git workflow (branching, code review, conventional commits), see Coding Practices and Git Workflow.