pypa / pip

The Python package installer
https://pip.pypa.io/
MIT License
9.53k stars 3.03k forks source link

Allow to set the list of optional dependencies that will be installed by default #9938

Open anki-code opened 3 years ago

anki-code commented 3 years ago

What's the problem this feature will solve?

The problem is that we can't set the dependencies that will be installed by default but will not be installed in case of choosing extras_require.

For example we have mypackage that could work with optional mydependency package. When we run pip install mypackage we want to install mydependency. But when we run pip install mypackage[minimal] we want to install only mypackage.

Current logic of install_requires and extras_require can't do this.

In real world this behavior is required at least by xonsh shell project. When we run pip install xonsh we want to give the best experience to the user by installing all packages and extensions. When we run pip install xonsh[min] we want to install minimal pack of dependencies (this useful for docker containers, testing environments and scripting on xonsh).

Describe the solution you'd like

We can allow to set the special name for the default extra dependencies in the extras_require:

import setuptools
setuptools.setup(
    name="mypackage",
    version="0.0.1",
    install_requires=['my-required-package'],
    extras_require={
        'DEFAULT': ['my-package1', 'my-package2'],
        'min': ['my-package3']
    }
)

In this case we will have this behavior:

pip install mypackage
# Installation of mypackage, my-required-package, my-package1, my-package2

pip install 'mypackage[min]'
# Installation of mypackage, my-required-package, my-package3

pip install 'mypackage[DEFAULT,min]'
# Installation of mypackage, my-required-package, my-package1, my-package2, my-package3

Alternative Solutions

I tried to set empty name to extras_require i.e. extras_require={'':['my-package1']} but got an error:

pip install mypackage
# ERROR: pip's dependency resolver does not currently take into account all the packages 
# that are installed. This behaviour is the source of the following dependency conflicts.
# mypackage 0.0.1 requires my-package1, which is not installed.

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

pfmoore commented 3 years ago

This has already been raised here: https://discuss.python.org/t/adding-a-default-extra-require-environment/4898. It would require a new standard, rather than being "just" a pip feature.