-
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
[WIP] Implement --global and try to default to --user when it makes sense #2418
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import os | ||
import posixpath | ||
import shutil | ||
import site | ||
import stat | ||
import subprocess | ||
import sys | ||
|
@@ -39,7 +40,7 @@ | |
'make_path_relative', 'normalize_path', | ||
'renames', 'get_terminal_size', 'get_prog', | ||
'unzip_file', 'untar_file', 'unpack_file', 'call_subprocess', | ||
'captured_stdout', 'remove_tracebacks'] | ||
'captured_stdout', 'remove_tracebacks', 'default_user_site'] | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -54,6 +55,37 @@ def get_prog(): | |
return 'pip' | ||
|
||
|
||
def default_user_site(): | ||
# Avoid circular import, the running_under_virtualenv should probably be | ||
# in pip.utils anyways TBH. | ||
from pip.locations import running_under_virtualenv, distutils_scheme | ||
|
||
# If we're running inside of a virtual environment, we do not want to | ||
# install to the --user directory. | ||
if running_under_virtualenv(): | ||
return False | ||
|
||
# If the Python we're running under does not have their user packages | ||
# enabled then we do not want to install to the user directory since it | ||
# may or may not work or exist. | ||
if not site.ENABLE_USER_SITE: | ||
return False | ||
|
||
# If any of our potentional locations for writing files is not writable by | ||
# us then we want to use the --user scheme instead of the --global scheme. | ||
# TODO: We should figure out a way to make this work for --root and | ||
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. if someone intentionally specifies a note that our |
||
# --isolated and such options as well. | ||
# TODO: Figure out if this works when the directories don't exist. | ||
for path in distutils_scheme("").values(): | ||
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. is there a concern here with using distutils directly, vs setuptools, since for sdist, that's where the scheme is determined? |
||
if not os.access(path, os.W_OK): | ||
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. This doesn't seem to behave properly on Windows. I was expecting this check to happen at a higher level - about the point where pip would terminate with an error but instead retry with 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. Retrying with 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. How soon do we know the destination subfolder? Can we switch when trying to create that (and maybe bring creation sooner if necessary)? 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. I'm not sure, but thinking about it more the other side of this is that we don't want 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. os.access currently always returns True for directories on Windows: http://bugs.python.org/issue2528 |
||
return True | ||
|
||
# If we get to this point, then we will assume that we want to use | ||
# --global, as that is the most backwards compatible policy and it will | ||
# mean that ``sudo pip install`` continues to work as it had previously. | ||
return False | ||
|
||
|
||
# Retry every half second for up to 3 seconds | ||
@retry(stop_max_delay=3000, wait_fixed=500) | ||
def rmtree(dir, ignore_errors=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.
I don't know enough about how command options translate to environment variables and/or config file entries. Does this mean that
PIP_GLOBAL
or aglobal
setting in the config file would make global the default (once the hard-coded default becomes "user")? If not, how would someone say they wanted to have global as the default?