diff options
author | Andy Freeland <andy.freeland@redjack.com> | 2015-09-23 23:05:36 -0400 |
---|---|---|
committer | Andy Freeland <andy.freeland@redjack.com> | 2015-09-29 16:01:32 -0400 |
commit | fac2891abb128c87a5ee33c3ec9f10bc3419aae7 (patch) | |
tree | 7e6346c491531065d8c0d9fd2dbb89ae7c58f342 | |
parent | 6be4627f89d668647f11695d381fce8e451f8269 (diff) | |
download | pip-fac2891abb128c87a5ee33c3ec9f10bc3419aae7.tar.gz |
Fix user directory expansion when HOME=/
On versions of CPython affected by <http://bugs.python.org/issue14768>
(Python 2.6, some versions of Python 2.7 and 3.3),
`os.path.expanduser('~/path')` returns `//path` rather than `/path` when
`HOME=/`. This affects pip when `os.path.expanduser('~/.cache/pip')` is
expanded to `/\\\\.cache/pip`. Although `HOME=/` is probably uncommon on
most Linux systems, it is extremely common in Docker images.
Fixes #2996.
-rw-r--r-- | CHANGES.txt | 3 | ||||
-rw-r--r-- | pip/utils/appdirs.py | 18 |
2 files changed, 18 insertions, 3 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index fe06a5f7c..5c3d279dd 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -29,6 +29,9 @@ * When installing, if building a wheel fails, clear up the build directory before falling back to a source install. :issue:`3047`. +* Fix user directory expansion when ``HOME=/``. Workaround for Python bug + http://bugs.python.org/issue14768, reported in :issue:`2996`. + **7.1.2 (2015-08-22)** diff --git a/pip/utils/appdirs.py b/pip/utils/appdirs.py index 5dd66eb1e..680a2c6fd 100644 --- a/pip/utils/appdirs.py +++ b/pip/utils/appdirs.py @@ -45,7 +45,11 @@ def user_cache_dir(appname): path = os.path.join(path, appname) else: # Get the base path - path = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache")) + path = os.getenv( + "XDG_CACHE_HOME", + # Workaround for http://bugs.python.org/issue14768 + os.path.join(os.path.expanduser("~"), ".cache") + ) # Add our app name to it path = os.path.join(path, appname) @@ -90,7 +94,11 @@ def user_data_dir(appname, roaming=False): ) else: path = os.path.join( - os.getenv('XDG_DATA_HOME', os.path.expanduser("~/.local/share")), + os.getenv( + 'XDG_DATA_HOME', + # Workaround for http://bugs.python.org/issue14768 + os.path.join(os.path.expanduser("~"), ".local/share") + ), appname, ) @@ -122,7 +130,11 @@ def user_config_dir(appname, roaming=True): elif sys.platform == "darwin": path = user_data_dir(appname) else: - path = os.getenv('XDG_CONFIG_HOME', os.path.expanduser("~/.config")) + path = os.getenv( + 'XDG_CONFIG_HOME', + # Workaround for http://bugs.python.org/issue14768 + os.path.join(os.path.expanduser("~"), ".config") + ) path = os.path.join(path, appname) return path |