Skip to content
TheChatArchiveThe Chat Archive
DeepSeekdeepseek-v3-0324· DeepSeekHugging Face LMArena Human Preference 140K

In pyproject.toml, I can define extra_requires via [project.optional-dependencies].…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with o3-2025-04-16’s answer.
  1. User

    In pyproject.toml, I can define extra_requires via [project.optional-dependencies]. Suppose I define two such extras extraa = ["package1", "package2"] and extrab = ["package1", "package3"]. Is there a convenient way to create an "all" extras that would include both of there without repeating the list of packages?

  2. DeepSeek Assistant

    Yes! In pyproject.toml, you can define an "all" extra that includes the packages from other extras without repeating them by referencing the other extras. Here's how you can do it:

    [project.optional-dependencies]
    extraa = ["package1", "package2"]
    extrab = ["package1", "package3"]
    all = ["package1", "package2", "package3"]  # Manually combined (not ideal)
    

    However, to avoid repeating packages, you can use extra references (supported by modern build backends like setuptools and poetry). Here's the cleaner way:

    [project.optional-dependencies]
    extraa = ["package1", "package2"]
    extrab = ["package1", "package3"]
    all = ["package1", "package2", "package3"]  # Still manual, but see below
    

    Better Approach (Dynamic "all" Extra)

    If you want the "all" extra to automatically include all other extras, you can do this:

    [project.optional-dependencies]
    extraa = ["package1", "package2"]
    extrab = ["package1", "package3"]
    all = ["extraa", "extrab"]  # References other extras (supported in some backends)
    

    But beware: Not all build backends support referencing extras directly like this. Here's what works where:

    1. Poetry: Fully supports this syntax (extras can reference other extras).

      [tool.poetry.extras]
      extraa = ["package1", "package2"]
      extrab = ["package1", "package3"]
      all = ["extraa", "extrab"]  # Works in Poetry
      
    2. Setuptools: As of 2023, setuptools does not support referencing extras directly in pyproject.toml. You'd need to either:

      • Manually combine the lists (as in the first example), or
      • Use a dynamic approach (e.g., with setup.py or a script to generate the list).

    Workaround for Setuptools

    If you're using setuptools, you can define the "all" extra programmatically in setup.py:

    from setuptools import setup
    
    extras = {
        "extraa": ["package1", "package2"],
        "extrab": ["package1", "package3"],
    }
    extras["all"] = list(set(pkg for extra in extras.values() for pkg in extra))
    
    setup(
        ...,
        extras_require=extras,
    )
    

    Best Practice

    • If using Poetry, use all = ["extraa", "extrab"].
    • If using Setuptools, either manually combine or use a script to avoid duplication.
    • Always test with pip install -e .[all] to verify the extras work as expected.

    This keeps your pyproject.toml clean and maintainable.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.