[Python] How to conditionally install modules using pip with pyproject.toml?

Discussão em 'Python' iniciado por Stack, Novembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to set different user-versions inside the same directory, so when using pip install . only the basic version module should be installed, namely only installing foo_tool. When using pip install .[extension] an additional module should be installed, foo_tool_extension.

    My Problem: When running pip install . I want only the foo_tool module to be installed. When running pip install .[extension] I want the additional foo_tool_extension module to be installed. However, depending on my pyproject.toml configuration:

    • Both foo_tool and foo_tool_extension get installed, regardless of whether I specify the [extension] option.
    • Only the dist-info file is installed, but neither of the modules (foo_tool or foo_tool_extension) are installed.

    c:\users\thetelefone\anaconda3\envs\test_env\lib\site-packages\foo_tool-0.6.dist-info\*
    c:\users\thetelefone\anaconda3\envs\test_env\lib\site-packages\foo_tool\*
    c:\users\thetelefone\anaconda3\envs\test_env\lib\site-packages\foo_tool_extension\*


    or only

    c:\users\thetelefone\anaconda3\envs\test_env\lib\site-packages\foo_tool-0.6.dist-info\*


    with both modules missing.

    My structure has the following layout:

    /foo_project
    ├── src
    │ ├── foo_tool
    │ │ ├── __init__.py
    │ │ ├── foo_problem.py
    │ │ ├── foo_plotting.py
    │ ├── foo_tool_extension
    │ │ ├── __init__.py
    │ │ ├── foo_problem_extension.py
    ├── tests
    │ ├── ...
    ├── README.md
    ├── pyproject.toml


    Both __init__.py files are empty. Currently my pyproject.toml looks like the following. I tried several different options, but always resulting in the behavior above.

    [project]
    name = "foo_tool"
    version = "0.6"
    authors = [{name = "thetelefonecopmpany"}]
    description = "Foo-Tool for fools."
    requires-python = ">3.6"
    dependencies = [
    "matplotlib",
    "pandas",
    "numpy",
    "openpyxl"
    ]

    [build-system]
    requires = ["setuptools>=61.0"]
    build-backend = "setuptools.build_meta"

    [tool.setuptools.packages.find]
    where = ["src"]
    exclude = ["foo_tool_extension"]

    [project.optional-dependencies]
    extension = [
    "scipy>=1.7.0",
    "foo_tool_extension @ file://src/foo_tool_extension"
    ]



    How can I configure my pyproject.toml file to achieve this behavior?
    Please also help me to improve this question. Thanks in advance!

    Continue reading...

Compartilhe esta Página