diff options
Diffstat (limited to 'pip/_vendor/distlib/util.py')
-rw-r--r-- | pip/_vendor/distlib/util.py | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/pip/_vendor/distlib/util.py b/pip/_vendor/distlib/util.py index e64d078b6..29ec519ab 100644 --- a/pip/_vendor/distlib/util.py +++ b/pip/_vendor/distlib/util.py @@ -154,9 +154,9 @@ def in_venv(): def get_executable(): - if sys.platform == 'darwin' and ('__VENV_LAUNCHER__' + if sys.platform == 'darwin' and ('__PYVENV_LAUNCHER__' in os.environ): - result = os.environ['__VENV_LAUNCHER__'] + result = os.environ['__PYVENV_LAUNCHER__'] else: result = sys.executable return result @@ -595,7 +595,6 @@ def get_cache_base(suffix=None): else: # Assume posix, or old Windows result = os.path.expanduser('~') - result = os.path.join(result, suffix) # we use 'isdir' instead of 'exists', because we want to # fail if there's a file with that name if os.path.isdir(result): @@ -612,7 +611,7 @@ def get_cache_base(suffix=None): if not usable: result = tempfile.mkdtemp() logger.warning('Default location unusable, using %s', result) - return result + return os.path.join(result, suffix) def path_to_cache_dir(path): @@ -768,6 +767,50 @@ def get_package_data(name, version): return _get_external_data(url) +class Cache(object): + """ + A class implementing a cache for resources that need to live in the file system + e.g. shared libraries. This class was moved from resources to here because it + could be used by other modules, e.g. the wheel module. + """ + + def __init__(self, base): + """ + Initialise an instance. + + :param base: The base directory where the cache should be located. + """ + # we use 'isdir' instead of 'exists', because we want to + # fail if there's a file with that name + if not os.path.isdir(base): + os.makedirs(base) + if (os.stat(base).st_mode & 0o77) != 0: + logger.warning('Directory \'%s\' is not private', base) + self.base = os.path.abspath(os.path.normpath(base)) + + def prefix_to_dir(self, prefix): + """ + Converts a resource prefix to a directory name in the cache. + """ + return path_to_cache_dir(prefix) + + def clear(self): + """ + Clear the cache. + """ + not_removed = [] + for fn in os.listdir(self.base): + fn = os.path.join(self.base, fn) + try: + if os.path.islink(fn) or os.path.isfile(fn): + os.remove(fn) + elif os.path.isdir(fn): + shutil.rmtree(fn) + except Exception: + not_removed.append(fn) + return not_removed + + class EventMixin(object): """ A very simple publish/subscribe system. |