Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform Requires-Python check before downloading dependencies #9925

Closed
tekumara opened this issue Apr 30, 2021 · 3 comments · Fixed by #9994
Closed

Perform Requires-Python check before downloading dependencies #9925

tekumara opened this issue Apr 30, 2021 · 3 comments · Fixed by #9994
Milestone

Comments

@tekumara
Copy link
Contributor

What's the problem this feature will solve?

When installing a package that requires a specific python version its dependencies are installed first, which

  1. downloads a bunch of dependencies unnecessarily
  2. can result in a confusing message when those dependencies don't have a distribution

eg:

myapi has python_requires=">=3.7" and depends on mylib. mylib has only been built for python 3.6.

pip install myapi with the Python 3.6 interpreter will download all dependencies and error with:

pip._internal.exceptions.DistributionNotFound: No matching distribution found for mylib==1.2.3

Describe the solution you'd like

pip install myapi with the Python 3.6 interpreter won't download dependencies and will error with the more helpful:

ERROR: Package 'myapi' requires a different Python: 3.6.10 not in '>=3.7'

Alternative Solutions

Additional context

@uranusjr
Copy link
Member

Are you using PyPI.org? This is already done for all packages from PyPI.org, but an alternative index implementation may not provide enough information to make this possible.

@uranusjr uranusjr added the S: awaiting response Waiting for a response/more information label Apr 30, 2021
@tekumara
Copy link
Contributor Author

tekumara commented May 1, 2021

Thanks @uranusjr for looking into this. Yes, this happens when using pypi.org. The undesired behaviour seems to have been introduced in pip 20.3.4.

Example

setup.py

from setuptools import find_packages, setup

setup(
    name="myapp",
    version="0.0.0",
    python_requires=">=3.7",
    install_requires=["black==20.8b1"]
)
❯ python --version
Python 3.6.10

❯ python -m venv --clear .venv
❯ . .venv/bin/activate

pip 20.3.3 (and earlier) will check the package's python requires before downloading dependencies (yay!):

❯ pip install pip==20.3.3
...
❯ pip install -e .
Obtaining file:///private/tmp/repo-name
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
ERROR: Package 'myapp' requires a different Python: 3.6.10 not in '>=3.7'
WARNING: You are using pip version 20.3.3; however, version 21.1.1 is available.
You should consider upgrading via the '/private/tmp/repo-name/.venv/bin/python -m pip install --upgrade pip' command.

pip 20.3.4 will download dependencies first and then check the package's python requires:

❯ pip install pip==20.3.4
...
❯ pip install -e .
Obtaining file:///private/tmp/repo-name
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting black==20.8b1
  Using cached black-20.8b1.tar.gz (1.1 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
ERROR: Package 'myapp' requires a different Python: 3.6.10 not in '>=3.7'
WARNING: You are using pip version 20.3.4; however, version 21.1.1 is available.
You should consider upgrading via the '/private/tmp/repo-name/.venv/bin/python -m pip install --upgrade pip' command.

Same behavior in pip 21.1.1

❯ pip install pip==21.1.1
...
❯ pip install -e .       
Obtaining file:///private/tmp/repo-name
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting black==20.8b1
  Using cached black-20.8b1.tar.gz (1.1 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
ERROR: Package 'myapp' requires a different Python: 3.6.10 not in '>=3.7'

@no-response no-response bot removed the S: awaiting response Waiting for a response/more information label May 1, 2021
@uranusjr
Copy link
Member

uranusjr commented May 1, 2021

Ah OK, you meant checking Requires-Python of a package before downloading the dependencies of that package, not dependnecies in general. That makes sense, thanks for the additional context. I think that’s a reasonable optimisation.

@uranusjr uranusjr added this to the 21.2 milestone May 1, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants