-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Display message on Windows when modifying pip #4490
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Display a message to run the right command for modifying pip on Windows |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,6 +314,23 @@ def populate_requirement_set(requirement_set, args, options, finder, | |
'You must give at least one requirement to %(name)s ' | ||
'(see "pip help %(name)s")' % opts) | ||
|
||
# On Windows, any operation modifying pip should be run as: | ||
# python -m pip ... | ||
# See https://github.com/pypa/pip/issues/1299 for more discussion | ||
should_show_use_python_msg = ( | ||
sys.platform == 'win32' and | ||
requirement_set.has_requirement('pip') and | ||
"pip" in os.path.basename(sys.argv[0]) | ||
) | ||
if should_show_use_python_msg: | ||
new_command = [ | ||
sys.executable, "-m", "pip" | ||
] + sys.argv[1:] | ||
raise CommandError( | ||
'To modify pip, please run the following command:\n{}' | ||
.format(" ".join(new_command)) | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this be better as a warning rather than an error? I can't immediately think of an existing scenario where the test (Hypothetical example, if there's a 3rd party tool called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The whole point is to not proceed with a command that might modify the
I do think that one shouldn't go around breaking existing workflows in general. In this case though, I'd argue that the gains from breaking such tools (that already not supported) in exchange for a much better UX on running There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, on thinking about it, I'm OK with this approach. If it causes issues for people, we can always improve the check. Or add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yep! ^.^ |
||
|
||
def _build_package_finder(self, options, session, | ||
platform=None, python_versions=None, | ||
abi=None, implementation=None): | ||
|
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 checks fails at least on Jython and IronPython. I've used
os.sep != '/'
which is hackish but works.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.
Thanks for spotting that. I don't have much experience with these.
Would
os.name == 'nt'
work on those platforms?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.
Unfortunately
os.name
won't work with Jython where it'sjava
regardless the OS. They do haveos._name
with the same semantics asos.name
on CPython, so something likegetattr(os, '_name', os.name)
could work.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.
@pekkaklarck It seems Jython has
sys.platform
attribute - http://www.jython.org/docs/library/sys.html, IronPython says "IronPython is a implementation of Python 2.7, any Python documentation is useful when using IronPython" which leads me to believe the same would work there too.So, now, I'm confused about whether this works or not.
It's likely that one of the core developers has a better idea of what the scene with these other implementations is than I do. I'll play it safe and wait for their comment. :)
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.
Both Jython and IronPython have
sys.platform
attribute, but its value is different to CPython. On Jython it's something like'java1.8.0_131'
and on IronPython'cli'
. These values don't change depending on the OS.I agree this is a topic where comments from core developers would be good. Preventing changes to pip breaking it on alternative Python implementations would probably also require some collaboration with the developers of these implementations.
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.
There's
pip.compat.WINDOWS
which works (according to the comment next to the definition) for cpython and ironpython. I don't know why it doesn't work for Jython (I suspect it means that Jython support might be broken in other places...) Also, I don't know if it would show Cygwin as a Windows system (and I don't even know if it should - Cygwin is a weird mixture of Unix and Windows).But using
pip.compat.WINDOWS
for the check is probably the correct thing to do, and separate issues should be raised if that symbol isn't giving the right result on Jython or any other systems...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.
On it!
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.
Jython trunk, which will be the 2.7.1 release:
On OS X:
On Windows:
On Ubuntu 16.04:
We can stop here, and just suggest some combination of the data above to determine the correct functionality is the right way to do this.
But you are a Python enthusiast, so it's worth pointing out that
os.name
has grown some functionality with Jython 2.7.1, as described in http://bugs.jython.org/issue2557 - this is the targets functionality, and it's whyos.name == 'java'
isTrue
above, despite the__repr__
being'java ( ==posix for targets )'
. This is implemented by providing a specific target string implementation in Jython. (Fortunately adding new builtin types in Jython is rather cheap.)You might think this would allow for immediate comparison of
os.name == 'posix'
, but the Python ecosystem is just too rich in its complexification for something so simple like that to work; in this case I'm trying this out on OSX:Instead, it's necessary to register such interest, via
os.name.addtarget('org\.python.*')
, which is global; or via a scheme that enables for this registration to be done from a distance. See the above Jython bug for more details.