Registry / devops / hatch-requirements-txt

hatch-requirements-txt

JSON →
library0.4.1pypypiunverified

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.

pip install hatch-requirements-txt
INSTALL
IMPORT
SIG · HATCH-REQUIREMENTS
H
hatch-requirements-txt
devopspythonv0.4.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

To use `hatch-requirements-txt`, install the plugin and configure your `pyproject.toml` to declare 'dependencies' as dynamic. Then, create a `requirements.txt` file in your project root with your desired runtime dependencies. The Hatchling build backend will automatically parse this file when building your package. After setting up these files, you can use the `hatch` CLI (e.g., `hatch build`) to see the plugin in action.

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).
Debug
Known issues
gotchaThe `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.
fix
Ensure `dynamic = ['dependencies']` is present in your `pyproject.toml` under the `[project]` table.
affects: All versions
breakingIn 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.
fix
Change `files = 'requirements.txt'` to `files = ['requirements.txt']`.
affects: >=0.4.0
deprecatedSupport for dynamically sourcing `name` and `version` from `requirements.txt` was removed in version 0.4.0. The plugin now strictly focuses on project dependencies.
fix
Ensure your project's `name` and `version` are explicitly defined in `pyproject.toml` or sourced from other appropriate Hatch dynamic metadata hooks, not via `hatch-requirements-txt`.
affects: >=0.4.0
gotchaThe `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.
fix
Add `"hatch-requirements-txt"` to the `requires` list under `[build-system]`.
affects: All versions
Errors
Common errors & fixes
hatch requirements.txt not working
The `pyproject.toml` file is likely missing the necessary configuration to inform Hatch to use the `hatch-requirements-txt` plugin or to recognize 'dependencies' as dynamic.
fix
Ensure your `pyproject.toml` includes `hatch-requirements-txt` in `build-system.requires`, adds `"dependencies"` to `project.dynamic`, and defines the `[tool.hatch.requirements-txt]` table. For example:
```toml
[build-system]
requires = ["hatchling", "hatch-requirements-txt"]
build-backend = "hatchling.build"

[project]
name = "your-project"
version = "0.1.0"
dynamic = ["dependencies"]

[tool.hatch.requirements-txt]
files = ["requirements.txt"]
```
hatch-requirements-txt unsupported format '-e'
The `requirements.txt` file contains an editable install (`-e` option), which is explicitly not supported by `hatch-requirements-txt`.
fix
Remove editable installs (`-e`) from your `requirements.txt` file. For local or development dependencies, consider using Hatch's environment-specific dependencies or other mechanisms outside of the main `requirements.txt` parsed by this plugin.
hatch-requirements-txt references to other requirements or constraints files
Your `requirements.txt` file includes references to other requirement files (`-r`) or constraint files (`-c`), which `hatch-requirements-txt` does not support.
fix
Consolidate all direct dependencies into a single `requirements.txt` file that `hatch-requirements-txt` processes, or manage interconnected dependency files using a different approach that doesn't rely on `-r` or `-c` within the plugin's scope.
pkg_resources.RequirementParseError: Invalid requirement
The `requirements.txt` file contains a dependency specification that the underlying parsing library (like `setuptools` which `hatch-requirements-txt` relies on) cannot interpret, often due to non-standard syntax, local paths, or complex URL formats.
fix
Ensure all entries in `requirements.txt` strictly adhere to PEP 508 requirement specifier syntax. Avoid local filesystem paths or complex URL forms that are not compliant, or verify correct quoting/escaping for URLs like `git+https://` if they are intended to be PEP 508 compliant.
Upgrade
Version history
0.4.1latest on PyPI · released Jan 24, 2024
Audit
Dependencies
hatchlingrequiredRequired build backend for Hatch, the plugin integrates with it.
hatchrequiredThe CLI tool that uses hatchling and this plugin during project builds.
Agent activity
8 hits · last 30 days
node
6
Amazon
1
Resources
hatch-requirements-txt — pip install hatch-requirements-txt · libregistry