Skip to content

Add pip to install_requires #13739

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

Merged
merged 1 commit into from
Sep 30, 2022
Merged

Conversation

dvzrv
Copy link
Contributor

@dvzrv dvzrv commented Sep 26, 2022

setup.py:
Change setup() call to include pip in the list of dependencies passed to install_requires.
Pip is required for the mypy --install-types feature. Without specifically adding it, minimal environments (e.g. venvs) will not have pip installed and therefore have no way of installing required types (e.g. for tests).

Fixes #13580

@github-actions

This comment has been minimized.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rarely see envs without pip but with mypy installed.
I don't really know how one can even do that: by running python mypy/setup.py install locally?

@dvzrv
Copy link
Contributor Author

dvzrv commented Sep 27, 2022

I rarely see envs without pip but with mypy installed.

That might be, but relying on transitive dependencies of some other package to pull in pip is less than ideal (basically broken).

I don't really know how one can even do that: by running python mypy/setup.py install locally?

This can happen if one does not specifically add it to the project's requirements. Tools such as PDM and also poetry will not install pip to your venv, if it is technically not required. If mypy does not pull in pip specifically and no other dependency does, a build container in CI only installing e.g. pdm and then bootstrapping the project requirements will not have pip.

@sobolevn
Copy link
Member

Tools such as PDM and also poetry will not install pip to your venv

poetry part is 100% not correct. It installs pip:

~/Desktop                                                                            
» mkdir test && cd test

~/Desktop/test                                                                       
» poetry --version && poetry init
Poetry (version 1.2.1)

This command will guide you through creating your pyproject.toml config.

Package name [test]:  
Version [0.1.0]:  
Description []:  
Author [sobolevn <mail@sobolevn.me>, n to skip]:  
License []:  
Compatible Python versions [^3.10]:  

Would you like to define your main dependencies interactively? (yes/no) [yes] no
Would you like to define your development dependencies interactively? (yes/no) [yes] no
Generated file

[tool.poetry]
name = "test"
version = "0.1.0"
description = ""
authors = ["sobolevn <mail@sobolevn.me>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


Do you confirm generation? (yes/no) [yes] 

~/Desktop/test                                                                       
» poetry install
Creating virtualenv test in /Users/sobolev/Desktop/test/.venv
Updating dependencies
Resolving dependencies... (0.1s)

Writing lock file

~/Desktop/test                                                                       
» poetry run which pip
/Users/sobolev/Desktop/test/.venv/bin/pip

@dvzrv
Copy link
Contributor Author

dvzrv commented Sep 27, 2022

Tools such as PDM and also poetry will not install pip to your venv

poetry part is 100% not correct. It installs pip:

Yeah, my bad (didn't check up on poetry again before writing my reply). I guess this only extents to PDM then (it does not install pip into the venv, but would instead rely on the system-wide installed pip if it is available) and poetry somehow installs some magic packages into the venv. 🤔
Given that pip is not a runtime requirement of any of the installed packages, that is basically just some implementation detail of poetry doing something in its own undocumented way.

Either way, a dependency on pip is a requirement if it is needed. Not all environments install their python packages using pip (e.g. all downstream distributions use system package management for that). So currently I don't have pip installed and have a fully functioning Python environment.

@dvzrv dvzrv force-pushed the add_pip_to_requirements branch from 83fa6ea to 8deffa5 Compare September 27, 2022 11:58
@github-actions

This comment has been minimized.

setup.py:
Change `setup()` call to include pip in the list of extra dependencies
passed to `extra_requires`.
Pip is required for the `mypy --install-types` feature. Without
specifically adding it, minimal environments (e.g. venvs created using
PDM) will not have pip installed and therefore have no way of installing
required types (e.g. for tests).
@dvzrv dvzrv force-pushed the add_pip_to_requirements branch from 8deffa5 to 9ba4f1f Compare September 28, 2022 13:46
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@dvzrv dvzrv requested review from sobolevn and hauntsaninja and removed request for sobolevn and hauntsaninja September 30, 2022 19:33
@hauntsaninja hauntsaninja merged commit 24aab8e into python:master Sep 30, 2022
@yermulnik
Copy link

yermulnik commented Oct 17, 2022

I'm not quite sure and hence am seeking for assistance: recently I found that MyPy cannot install pip dependencies in GitHub action: https://github.com/github/super-linter/issues/3450
Initially I was under impression that this was a super-linter issue since I use mypy via this linter automation, though then I found this change and now I'm wondering whether this should/might be fixed via https://github.com/python/mypy or maybe the issue lays deeper, e.g. in Actions runner (actions/runner#652)?
Thanks for any clue.

@dvzrv
Copy link
Contributor Author

dvzrv commented Nov 23, 2022

@yermulnik I don't believe this is related. pip has been added as an optional dependency only, installable by keyword (i.e. mypy[install-types]). Your problem in https://github.com/github/super-linter/issues/3450 looks like a directory permission issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mypy uses pip for --install-types but does not list pip in requirements
4 participants