Hatch Requirements.txt Plugin
hatch-requirements-txt is a Hatchling plugin that enables Hatch-managed Python projects to declare their runtime dependencies directly within a 'requirements.txt' file. This allows projects to maintain a familiar dependency declaration style while leveraging Hatch for modern packaging. The current version is 0.4.1, with relatively infrequent but stable releases.
Warnings
- gotcha The `dynamic = ['dependencies']` entry in `[project]` is mandatory. Without it, Hatch will not attempt to dynamically source dependencies from the `requirements.txt` file, and your project will have no declared runtime dependencies.
- breaking In versions 0.4.0 and later, the `files` option in `[tool.hatch.metadata.hooks.requirements-txt]` must be a list of strings, even if you are specifying only a single file. Previous versions accepted a single string.
- deprecated Support for dynamically sourcing `name` and `version` from `requirements.txt` was removed in version 0.4.0. The plugin now strictly focuses on project dependencies.
- gotcha The `hatch-requirements-txt` plugin itself must be listed in `build-system.requires` in `pyproject.toml` so that Hatchling can find and load it during the build process.
Install
-
pip install hatch-requirements-txt
Quickstart
mkdir my_project cd my_project # Create pyproject.toml cat <<EOF > pyproject.toml [build-system] requires = ["hatchling>=1.8.0", "hatch-requirements-txt"] build-backend = "hatchling.build" [project] name = "my-hatch-app" version = "0.1.0" dynamic = ["dependencies"] [tool.hatch.metadata.hooks.requirements-txt] files = ["requirements.txt"] EOF # Create requirements.txt cat <<EOF > requirements.txt requests>=2.28.0 beautifulsoup4 EOF # Your project is now configured to use requirements.txt for dependencies. # To see it in action, you would typically run 'hatch build' (assuming 'hatch' CLI is installed).