Home > Software design >  How to reference a requirements.txt from a pyproject.toml?
How to reference a requirements.txt from a pyproject.toml?

Time:09-05

I'm trying to migrate some legacy setup.py-based builds towards modern pyproject.toml-based builds.

At the same time I want to keep well established workflows based on pip-compile, i.e., a requirements.in that gets compiled to a requirements.txt (for end-user / non-library projects of course). This has important benefits as a result of the full transparency:

  • 100% reproducible installs due to pinning the full transitive closure of dependencies.
  • better understanding of dependency conflicts in the transitive closure of dependencies.

For this reason I don't want to maintain the dependencies directly inside the pyproject.toml via a dependencies = [] list, but rather externally in the pip-compiled managed requirements.txt.

This makes me wonder: Is there a way to reference a requirements.txt from a pyproject.toml, without having to fallback to legacy setup.py-based techniques?

CodePudding user response:

Use dynamic metadata:

[project]
dynamic = ["dependencies"]
[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
  • Related