[Python] Use dynamic optional dependencies pyproject.toml

Discussão em 'Python' iniciado por Stack, Março 15, 2025.

  1. Stack

    Stack Membro Participativo

    I want to create a pip package, which installs both module1 and module2 when doing a pip install ., but by doing a pip install .[module1] only installs dependencies from module1/module1_requirements.txt. I tried the following approach, but this will install also module2 dependencies for pip install .[module1] Is there a way to achieve this without using a separate setup.py or an all group?

    requires = ["setuptools", "setuptools-scm"]
    build-backend = "setuptools.build_meta"

    [project]
    requires-python = ">=3.9"
    name = "foobar"
    dynamic = ["dependencies", "optional-dependencies"]

    [tool.setuptools.dynamic]
    dependencies = { file = ["module1/module1_requirements.txt", "module2/module2_requirements.txt"] }
    optional-dependencies.module1 = { file = ["module1/module1_requirements.txt"] }
    optional-dependencies.module2 = { file = ["module2/module2_requirements.txt"] }

    Continue reading...

Compartilhe esta Página