A minimal, production-grade Python infrastructure template utilizing the src/ layout and PEP 621 configurations. This repository serves as a robust foundation for building scalable, maintainable Python applications and libraries without unnecessary bloat.
- Standardized Project Structure: Enforces the
src/layout to isolate package code, ensuring testing is performed against the installed package rather than source files. - Modern Packaging: Uses
pyproject.toml(PEP 621) with thehatchlingbuild backend for dependency parsing, metadata, and tool configuration. - Comprehensive Tooling: Integrated support for formatting, linting, and testing via
ruff,pytest,pytest-cov, andpre-commit. - Automated CI Pipeline: Matrix testing defined in GitHub Actions ensuring compatibility across multiple Python versions.
- Production-Ready Dockerization: Minimal image footprint utilizing
python:3.11-slim, non-root execution, and optimized caching. - Developer Workflows: Centralized orchestration using
makecommands.
A Makefile is provided to orchestrate environment initialization and installation.
Ensure a Python virtual environment is active, then execute:
make installThis command installs the package in editable mode (pip install -e ".[dev]") alongside all development dependencies, and configures pre-commit hooks.
The project incorporates several tools to enforce code quality and consistency. Tool configurations are centralized within pyproject.toml.
- Formatting & Linting: Handled exclusively by
ruff, providing rapid static analysis and automatic code formatting. - Pre-commit Hooks: Configured via
.pre-commit-config.yamlto runruffand enforce codebase integrity prior to commits. - Testing:
pytestis configured to run tests located in thetests/directory. Coverage reports are generated usingpytest-cov, with enforcement rules specified in the project configuration.
The following targets are available for developer workflows:
make install: Installs dependencies and sets up pre-commit hooks.make test: Executes the test suite with coverage reporting.make lint: Runs static analysis checks viaruff.make format: Automatically resolves formatting and fixable linting violations.make clean: Removes caches, compiled bytecode, and test artifacts.
The repository leverages GitHub Actions (.github/workflows/ci.yml) to enforce CI requirements on pull requests and pushes to the main branch.
The test strategy includes a matrix execution spanning Python 3.9, 3.10, 3.11, and 3.12. The pipeline verifies proper editable installation, asserts code compliance via ruff, and mandates successful execution of the test suite via pytest.
A production-ready Dockerfile is included, implementing security and size optimizations such as environment variable tuning, caching bypasses, and continuous non-root execution contexts (appuser).
Build the image:
docker build -t python-infra-lab .Run the container locally:
docker run --rm -it python-infra-lab