-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Make --require-virtualenv
output more info
#2401
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
Conversation
Note that if folks have some kind of process that relies on being able to force_use_system_python = true |
@@ -104,6 +114,9 @@ def parse_args(self, args): | |||
# factored out for testability | |||
return self.parser.parse_args(args) | |||
|
|||
def running_outside_virtualenv(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is_in_virtualenv
would be a nicer name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alex, is_in_virtualenv
would require negative logic in the if
statement below, which is not ideal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's too bad. If we had it as .in_virtualenv()
then it would look like:
if not self.in_virtualenv():
...
I actually don't like function that's have negative logic because if I want to reverse the logic, then I have to read a double-negative logic and my brain starts to melt. I'd rather read positive logic and then just add a not
to negate it.
Hmmm, there appears to already be some code to do something like this, but I can't figure out how to use it:
|
Ah. Here it is:
That said since I've never heard of any user seeing this message and I didn't know about it myself until just now, I would say that perhaps we need something a bit stronger... |
I like the general idea. The message could be tweaked to be less verbose somehow. Instead of exiting the |
@aconrad: I'll probably redo this to be a smaller change to the already existing I do feel like perhaps that needs to be on my default and maybe needs to display a bit more info, because folks who aren't steeped in Python packaging may not be able to make sense of |
I also like the idea, but maybe the warning should not appear when performing:
which should (hopefully) be the default soon(?). Cf #1668 |
@msabramo yeah, it would be better if you could leverage the implementation I think another option that could be enabled by default is |
@@ -38,6 +39,7 @@ class Command(object): | |||
name = None | |||
usage = None | |||
hidden = False | |||
warn_outside_virtualenv = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warn_outside_virtualenv
could be renamed to warn_no_virtualenv
(shorter) and work well with the --warn-no-virtualenv
option I suggested in my comment #2401 (comment).
I was thinking we could simply invert |
I'm just worried that existing scripts would break as your suggestion would be backwards incompatible -- it would abort the install by default, correct? But hey, we could make it a major version bump too (that being said, it didn't prevent pip 6 from being a nightmare with regards to PEP440). |
With your suggestion:
|
I must say that I like it, I just don't know if it's acceptable for legacy scripts. |
I'm pretty down on the idea of mandating virtual environments by default. It feels like the wrong solution to the problem of users installing things into their system. I think switching the default to |
I agree with @dstufft, mandating virtual environments is a bad move. For a start, it sort of breaks the whole point of ensurepip (which is that Python ships with pip - what use is that if you can't then use pip?) In particular, on Windows people are expected to use pip to install packages in their main Python (it's not a "system" Python, there's no such thing in Windows terms). I thought there was another PR around that addressed this issue by actually checking if you were using sudo (checking euid vs uid?) That seems much less prone to disallowing valid use cases, IMO. |
Interesting. I actually started with the idea of checking for |
I didn't know that |
9ae09c9
to
5bdb2e0
Compare
--require-virtualenv
output more info
I just simplified this greatly to take advantage of the existing
Note that |
I think this also addresses @pfmoore's comment about Windows, because it's not the default behavior. Presumably, one wouldn't enable this option on a Windows system. |
Sounds like @msabramo so right now with the state of the PR, if I do So if |
@aconrad: Now that I've updated it, |
@msabramo oh I see, this code is under So now that I look at it with a fresh eye, this feels like
The point of |
Travis fail looks like a network blip. Restart please? |
@aconrad Yeah I wouldn't expect a user to use both options on the command-line. The more likely use case is that a user would specify Funny how this PR started out as being something that made pip more restrictive and now it's less restrictive (though that just means the discussion was valuable to steer it in a different direction). |
Oh and |
5bdb2e0
to
83e9228
Compare
83e9228
to
2b1c10c
Compare
2b1c10c
to
ed0b20a
Compare
if not in a virtualenv **and** --user wasn't specified. Previously, this would print an error even if --user was specified. I believe the spirit of `--require-virtualenv` is that it was meant to be used as `require_virtualenv = True` in the pip config file and what it really seeks to do is to prevent the user from messing with packages in the system python envvironment. Thus, I'd argue that --user shouldn't cause an error, because it doesn't mess with the system python. With this change, output looks like this: $ python -m pip install --require-virtualenv foo ****************************************************** Using pip outside a virtualenv and without --user is not recommended! Doing stuff with the system python's packages can break your system. Did you mean to use a virtualenv or use --user? ******************************************************
ed0b20a
to
82a2f35
Compare
Updated to make the diff a bit easier to understand at a glance. |
'Could not find an activated virtualenv (required).' | ||
) | ||
sys.exit(VIRTUALENV_NOT_FOUND) | ||
if not getattr(options, 'use_user_site'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is odd to me. If I've set the option to require a virtualenv, it shouldn't allow a user install? that's redefining the option.
Agreed. Actually was surprised to find it wasn't closed earlier, given the other concerns. |
Make
--require-virtualenv
output more infoif not in a virtualenv and
--user
wasn't specified.