Skip to main content

Opinionated Python code quality baseline plugin for Pants build system

Project description

jaymd96-pants-baseline

An opinionated Python code quality baseline plugin for the Pants build system.

Overview

This plugin integrates modern, high-performance tools from the Astral ecosystem to enforce consistent code quality standards across Python projects:

Tool Purpose Performance
Ruff Linting & Formatting 100-1000x faster than Flake8/Black
ty Type Checking 10-60x faster than MyPy
uv Dependency Security Audit 10-100x faster than pip
pytest Testing with Coverage Industry standard

Installation

Add the plugin to your pants.toml:

[GLOBAL]
backend_packages = [
    "pants.backend.python",
    "pants_baseline",
]

plugins = [
    "jaymd96-pants-baseline==0.1.0",
]

Quick Start

1. Define a baseline project

Create a BUILD file in your project root:

baseline_python_project(
    name="my_project",
    sources=["src/**/*.py"],
    test_sources=["tests/**/*.py"],
    python_version="3.13",
    line_length=120,
    strict=True,
    coverage_threshold=80,
)

2. Run quality checks

# Lint with Ruff
pants baseline-lint ::

# Format with Ruff
pants baseline-fmt ::

# Type check with ty
pants baseline-typecheck ::

# Run tests with coverage
pants baseline-test ::

# Security audit with uv
pants baseline-audit ::

Configuration

Global Configuration (pants.toml)

[python-baseline]
# Enable/disable all baseline checks
enabled = true

# Target Python version
python_version = "3.13"

# Maximum line length
line_length = 120

# Source and test directories
src_roots = ["src"]
test_roots = ["tests"]

# Minimum coverage threshold
coverage_threshold = 80

# Enable strict mode for all tools
strict_mode = true

# Patterns to exclude
exclude_patterns = [
    ".venv",
    "__pycache__",
    "migrations",
]

Ruff Configuration

[ruff]
version = "0.2.0"

# Lint rules to enable
select = [
    "E",      # pycodestyle errors
    "W",      # pycodestyle warnings
    "F",      # pyflakes
    "I",      # isort
    "N",      # pep8-naming
    "UP",     # pyupgrade
    "B",      # flake8-bugbear
    "C4",     # flake8-comprehensions
    "SIM",    # flake8-simplify
    "RUF",    # Ruff-specific
]

# Rules to ignore
ignore = ["E501"]

# Formatting options
quote_style = "double"
indent_style = "space"

# Auto-fix options
fix = true
unsafe_fixes = false

ty Configuration

[ty]
version = "0.1.0"

# Enable strict type checking
strict = true

# Reporting options
report_missing_imports = true
report_unused_imports = true
report_unused_variables = true

# Include/exclude paths
include = ["src", "tests"]
exclude = [".venv", "dist"]

# Output format (text, json, github)
output_format = "text"

uv Configuration

[uv]
version = "0.5.0"

# Security auditing
audit_enabled = true
audit_ignore_vulns = []
audit_fail_on_warning = false

# Lock file
lock_file = "uv.lock"
require_lock = true

# Output format
output_format = "text"

Target Fields

The baseline_python_project target supports the following fields:

Field Type Default Description
sources list[str] ["**/*.py"] Python source file patterns
test_sources list[str] ["tests/**/*.py"] Test file patterns
python_version str "3.13" Target Python version
line_length int 120 Maximum line length
strict bool True Enable strict mode
coverage_threshold int 80 Minimum coverage %
skip_lint bool False Skip Ruff linting
skip_fmt bool False Skip Ruff formatting
skip_typecheck bool False Skip ty type checking
skip_test bool False Skip pytest
skip_audit bool False Skip uv security audit

Goals

baseline-lint

Run Ruff linting on Python files.

pants baseline-lint src/::

baseline-fmt

Format Python files with Ruff.

pants baseline-fmt src/::

# Check formatting without modifying files
pants baseline-fmt --check src/::

baseline-typecheck

Run ty type checking.

pants baseline-typecheck src/::

baseline-test

Run pytest with coverage.

pants baseline-test tests/::

# Run specific test markers
pants baseline-test --pytest-args="-m unit" tests/::

baseline-audit

Run uv security audit on dependencies.

pants baseline-audit ::

# Ignore specific vulnerabilities
pants --uv-audit-ignore-vulns="['GHSA-xxxx']" baseline-audit ::

Example Project Structure

my-project/
├── BUILD
├── pants.toml
├── pyproject.toml
├── uv.lock
├── src/
│   └── my_package/
│       ├── BUILD
│       ├── __init__.py
│       └── main.py
└── tests/
    ├── BUILD
    ├── conftest.py
    └── test_main.py

Root BUILD file

baseline_python_project(
    name="my_project",
    sources=["src/**/*.py"],
    test_sources=["tests/**/*.py"],
)

pants.toml

[GLOBAL]
pants_version = "2.30.1"
backend_packages = [
    "pants.backend.python",
    "pants_baseline",
]
plugins = ["jaymd96-pants-baseline==0.1.0"]

[python]
interpreter_constraints = ["CPython>=3.13,<4"]

[python-baseline]
python_version = "3.13"
line_length = 120
coverage_threshold = 80

[ruff]
select = ["E", "F", "I", "B", "UP", "RUF"]

[ty]
strict = true

Why This Stack?

Performance Comparison

Task Traditional Stack Baseline Stack Speedup
Lint (50K LOC) 20s (Flake8) 0.4s (Ruff) 50x
Format (50K LOC) 8s (Black) 0.3s (Ruff) 26x
Type Check 45s (MyPy) 4.7ms (ty) 9500x
Pre-commit 18s 0.3s 60x

Tool Consolidation

Traditional Baseline
Black Ruff format
isort Ruff (I rules)
Flake8 + plugins Ruff lint
MyPy/Pyright ty
pip-audit uv audit

Development

Setup

cd python-baseline
hatch env create

Run tests

hatch run test
hatch run test-cov

Lint and format

hatch run lint
hatch run fmt

License

Apache License 2.0

Contributing

Contributions are welcome! Please read our contributing guidelines before submitting a PR.

Credits

Built with tools from:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jaymd96_pants_baseline-0.1.6.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jaymd96_pants_baseline-0.1.6-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

Details for the file jaymd96_pants_baseline-0.1.6.tar.gz.

File metadata

  • Download URL: jaymd96_pants_baseline-0.1.6.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.3 cpython/3.13.0 HTTPX/0.28.1

File hashes

Hashes for jaymd96_pants_baseline-0.1.6.tar.gz
Algorithm Hash digest
SHA256 132cb717ba04b05c30160fefd6e82123241e7910179f9c9ec5fc8decec225138
MD5 2f7ddf382e487727dea1b3ef7d29db45
BLAKE2b-256 6d889422b7583ee371f564da1c37faaf77a6883cd8f32ae28d5bdbfe001a9ecc

See more details on using hashes here.

File details

Details for the file jaymd96_pants_baseline-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for jaymd96_pants_baseline-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 cbe6bbfcfd1773f435ae26b2fe64515bb6a03f907c4109c30ef0332cbe40e829
MD5 4b352beab0c9c0b59f9dbf8c74f1af9f
BLAKE2b-256 ece920cb05e9de1c8ef3b7fa4dec122bd05f3ffcfb423f18b6679a984c366a07

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page