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

Add option for global installation warning #11753

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sujaldev
Copy link

This PR implements a new (opt-in) option --global-install-warning to warn the user if they're installing without a virtual environment activated, this does not conflict with the existing option --require-virtualenv which gives an error when enabled and a virtualenv is not detected. If both --require-virtualenv and --global-install-warning are given then it will behave as if only --require-virtualenv was passed.

Example:

$ pip config set install.require-virtualenv true
Writing to /home/<user>/.config/pip/pip.conf

$ pip config set install.global-install-warning true
Writing to /home/<user>/.config/pip/pip.conf

$ pip install -r requirements.txt
ERROR: Could not find an activated virtualenv (required).

$ pip config unset install.require-virtualenv
Writing to /home/<user>/.config/pip/pip.conf

$ pip install -r requirements.txt
WARNING: Could not find an activated virtualenv.
Proceed (y/N)? 

fixes #11752.

@pfmoore
Copy link
Member

pfmoore commented Jan 27, 2023

I’m -1 on this. Just use —require-virtualenv for this. We don’t need 2 options that do extremely similar things.

@sujaldev
Copy link
Author

sujaldev commented Jan 27, 2023

In my opinion, the UX with --require-virtualenv is a bit frustrating. What if that is changed to what I'm proposing with --global-install-warning?

@notatallshaw
Copy link
Contributor

notatallshaw commented Jan 28, 2023

My two cents as a user of Pip is that I don't have an opinion on --global-install-warning vs. --require-virtualenv but I don't like the use of ask as part of pip install here, I'd rather pip just failed.

At a quick glance it seems Pip doesn't use ask unless it's to do with authentication or deleting files, otherwise pip tends to succeed or fail. Which means when pip is called in a subprocess (e.g. as part of CI scripts or in conda requirements) you can generally expect it to succeed or fail.

Currently you have to set the environmental variable PIP_NO_INPUT to throw an error instead, I think if ask is used in more places it should behave like other global settings and be able to be set as any of environmental variable, configuration, or command line flag. Or even change this to behave like conda and have flags to provide yes or no to every prompt.

@pfmoore
Copy link
Member

pfmoore commented Jan 28, 2023

I don't like the use of ask as part of pip install here, I'd rather pip just failed.

Thanks @notatallshaw, that's articulated my reservation far better than I managed. I agree, pip install should not prompt the user like this, it has the potential to break workflows that run pip install in non-interactive environments. And without the interactive prompt. there's basically no difference between --global-install-warning and --require-virtualenv except that one requires you to opt in and the other to opt out.

And we're looking at making --require-virtualenv the default behaviour sometime in the near future anyway, at which point --global-install-warning becomes pointless.

@sujaldev
Copy link
Author

I was thinking that the use of a prompt could be implemented inside --require-virtualenv itself to be an opt-in feature, which when not explicitly enabled, raise an error as it currently does otherwise a warning and a prompt. This approach will not break any existing scripts that run pip in a non-interactive environment, satisfy those who prefer an error and simultaneously those who prefer a prompt.

Personally, I'd love to have a prompt and a warning but seems like everyone prefers an error. Should I close this PR then?

@uranusjr
Copy link
Member

Maybe alternatively we could deprecate --require-virtualenv and turn it into something like --allow-global-site=always|ask|never. The always choice is the default, never is identical to --require-virtualenv, and ask would ask if there’s a terminal, or fall back to never otherwise.

But this could be an overkill, idk.

@github-actions github-actions bot added the needs rebase or merge PR has conflicts with current master label Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs rebase or merge PR has conflicts with current master
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Global Installation Warning
4 participants