Hatchling plugin to read project dependencies from requirements.txt
Tests | |
---|---|
PyPI | |
Anaconda | |
Activity | |
QA | |
Other |
In your pyproject.toml
make the following changes:
- Append
hatch-requirements-txt
tobuild-system.requires
. - Append
"dependencies"
toproject.dynamic
. - Add the following table:
[tool.hatch.metadata.hooks.requirements_txt]
files = ["requirements.txt"]
The resulting pyproject.toml
should look something like:
[build-system]
requires = ["hatchling", "hatch-requirements-txt"]
build-backend = "hatchling.build"
[project]
name = "my-project"
version = "1.0.0"
dynamic = ["dependencies"]
[tool.hatch.metadata.hooks.requirements_txt]
files = ["requirements.txt"]
You can also define groups of optional dependencies
(also known as "features") by appending optional-dependencies
to project.dynamic
and adding a table like:
[tool.hatch.metadata.hooks.requirements_txt.optional-dependencies]
crypto = ["requirements-crypto.txt"]
fastjson = ["requirements-fastjson.txt"]
cli = ["requirements-cli.txt"]
hatch-requirements-txt
only supports a subset of the requirements.txt
format supported by pip
.
The following are supported:
- requirement specifiers, per PEP 508
- Comments, prefixed with a
#
. --<option>
options, both on their own line and after a requirement specifier. Note however that the options themselves are ignored.
The following are unsupported within requirements.txt
files:
- Editable install commands with the
-e
option, - References to other requirements or constraints files with the
-r
or-c
options. - References to paths on the local filesystem, or URLs.
TL;DR
For best compatibility, ensure all lines in your requirements.txt
files
are valid PEP 508 requirements, or comments starting with a #
.