diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2016-08-27 08:55:25 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2016-08-27 08:55:25 -0400 |
| commit | beec7ff9b0e301e6fffb21f9a8d999829eb8e678 (patch) | |
| tree | bf3f144df5546fa977b131967dead57a18d45ebb /pkg_resources | |
| parent | 691e6ac03339d6aef045e05872b286d91e9f49b9 (diff) | |
| download | python-setuptools-git-beec7ff9b0e301e6fffb21f9a8d999829eb8e678.tar.gz | |
Rely on appdirs for resolving a cache dir for Python-Eggs. Fixes #763.
Diffstat (limited to 'pkg_resources')
| -rw-r--r-- | pkg_resources/__init__.py | 50 |
1 files changed, 9 insertions, 41 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 27d70a60..a93a3da7 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -65,6 +65,7 @@ try: except ImportError: importlib_machinery = None +from pkg_resources.extern import appdirs from pkg_resources.extern import packaging __import__('pkg_resources.extern.packaging.version') __import__('pkg_resources.extern.packaging.specifiers') @@ -1358,48 +1359,15 @@ class ResourceManager: def get_default_cache(): - """Determine the default cache location - - This returns the ``PYTHON_EGG_CACHE`` environment variable, if set. - Otherwise, on Windows, it returns a "Python-Eggs" subdirectory of the - "Application Data" directory. On all other systems, it's "~/.python-eggs". """ - try: - return os.environ['PYTHON_EGG_CACHE'] - except KeyError: - pass - - if os.name != 'nt': - return os.path.expanduser('~/.python-eggs') - - # XXX this may be locale-specific! - app_data = 'Application Data' - app_homes = [ - # best option, should be locale-safe - (('APPDATA',), None), - (('USERPROFILE',), app_data), - (('HOMEDRIVE', 'HOMEPATH'), app_data), - (('HOMEPATH',), app_data), - (('HOME',), None), - # 95/98/ME - (('WINDIR',), app_data), - ] - - for keys, subdir in app_homes: - dirname = '' - for key in keys: - if key in os.environ: - dirname = os.path.join(dirname, os.environ[key]) - else: - break - else: - if subdir: - dirname = os.path.join(dirname, subdir) - return os.path.join(dirname, 'Python-Eggs') - else: - raise RuntimeError( - "Please set the PYTHON_EGG_CACHE environment variable" - ) + Return the ``PYTHON_EGG_CACHE`` environment variable + or a platform-relevant user cache dir for an app + named "Python-Eggs". + """ + return ( + os.environ.get('PYTHON_EGG_CACHE') + or appdirs.user_cache_dir(appname='Python-Eggs') + ) def safe_name(name): |
