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

Support pip's --user option in mypy's --install-types #16606

Closed
wants to merge 6 commits into from

Conversation

lsfischer
Copy link

@lsfischer lsfischer commented Dec 2, 2023

Fixes: #16339

This PR adds support for a new command line argument --user. This command line argument is intended to be used together with --install-types throwing an error otherwise.
When used with --install-types, this new option will pass the --user flag to pip install so that the missing library stubs are installed to the user's local python package install location.

Example

$ mypy --install-types --non-interactive --user -c "import lxml"
Installing missing stub packages:
/home/lsfischer/anaconda3/envs/mypy/bin/python -m pip install --user lxml-stubs

Collecting lxml-stubs
  Downloading lxml_stubs-0.4.0-py3-none-any.whl (13 kB)
Installing collected packages: lxml-stubs
Successfully installed lxml-stubs-0.4.0

This comment has been minimized.

@@ -1561,7 +1572,8 @@ def install_types(
print()
print("Installing missing stub packages:")
assert options.python_executable, "Python executable required to install types"
cmd = [options.python_executable, "-m", "pip", "install"] + packages
pip_options = ["--user"] if options.user else []
Copy link
Author

Choose a reason for hiding this comment

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

If more pip options are supported in the future, this could go into a proper derive_pip_options function or similar

Copy link
Contributor

github-actions bot commented Dec 4, 2023

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@lsfischer
Copy link
Author

Pinging maybe @AlexWaygood, I would love to get your feedback on this topic.
I feel this would be good alternative to people without a venv

@gtedesco-r7
Copy link

For anyone else searching for this export PIP_USER=true or setting a pip.conf can achieve the same thing for now.

@hauntsaninja
Copy link
Collaborator

Thanks for the PR! I'm not planning on merging this. I don't want --install-types to replicate pip's user interface. As it is it has some usability issues, e.g. it effectively means you have to run mypy twice. It sounds like there are reasonable workarounds mentioned by gtedesco-r7

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.

Support pip's --user option when using --install-types
3 participants