$ show heroku/heroku-buildpack-python
This is the official Heroku buildpack for Python applications. It implements the standard buildpack lifecycle (detect, compile, release, report) to install a Python runtime and manage dependencies using pip, pipenv, poetry, or uv. It handles Django collectstatic, NLTK corpora downloads, user-supplied hooks (pre/post compile), and Heroku CI. The codebase is a collection of modular shell scripts with a consistent library pattern, extensive integration tests via Hatchet/RSpec, and support for multiple Heroku stacks. It is actively maintained, with Dependabot for dependency updates and CI workflows for every commit. The architecture is straightforward: each lifecycle phase is a standalone script that sources reusable libraries from lib/. While the core logic is specific to Heroku's platform, the library functions (e.g., caching, version resolution, build data reporting) demonstrate good shell scripting practices and could be adapted for other build systems.
The LLM identified 3 files worth highlighting for reuse:
Provides a key-value store for build metadata (e.g., failure detail, Python version origin, package manager) that is serialized to a JSON file and later emitted by bin/report. Implements a simple, shell-compatible data dictionary with set_string, get_string, set_duration, and print_bin_report_json. This pattern is reusable in any shell-based CI/CD pipeline that needs to collect and report structured build metrics without external dependencies.
Manages the build cache directory structure, stores stack and requirements metadata, and supports legacy cache formats for backward compatibility. Functions like cache::load, cache::store, cache::clear handle idempotent cache key generation based on stack, Python version, package manager version, and lockfile hash. The pattern of storing metadata alongside cached artifacts and gracefully handling format migrations is broadly applicable to any build or CI system that uses caching.
Resolves the Python version from multiple sources (.python-version, runtime.txt, Pipfile.lock, pyproject.toml) with strict validation, misspelling detection, and EOL warnings. Uses a function-based approach (python_version::resolve, python_version::validate) that is easily testable and can be extracted into any shell-based tool that needs to parse and validate version constraints from file inputs.