Skip to content

Migrate from requirements.txt parsing #178

Closed as not planned
Closed as not planned
@astrojuanlu

Description

It's very typical to see a code block like this in setup.py:

with open("requirements.txt", encoding="utf-8") as f:
    # Make sure we strip all comments and options (e.g "--extra-index-url")
    # that arise from a modified pip.conf file that configure global options
    requires = []
    for line in f:
        req = line.split("#", 1)[0].strip()
        if req and not req.startswith("--"):
            requires.append(req)

setup(
    ...
    install_requires=requires,

However, as pointed out by the setuptools maintainers, requirements.txt files were always meant for pip, not for build backends (hence the stripping of comments and --<options>).

setuptools ships beta support for consuming them in pyproject.toml:

dynamic = ["dependencies"]

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

(see documentation)

But it breaks workflow tools that rely on adding deps statically to [project.dependencies], for example poetry, pdm, rye, uv.

Would you be open to adding an option that helps users migrate from having their deps in requirements.txt to having them in [project.dependencies]?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions