diff options
author | Jurko Gospodnetić <jurko.gospodnetic@pke.hr> | 2014-06-04 08:03:41 +0200 |
---|---|---|
committer | Jurko Gospodnetić <jurko.gospodnetic@pke.hr> | 2014-06-04 08:03:41 +0200 |
commit | bbdcce69110d8783f21c121bc97fc902809aedf5 (patch) | |
tree | 8dfd6f3d290a38f8d6641deaf02ef8a0bc071b3d | |
parent | 1f7d40e5e48a6f97fe851db93b5e48d8881e713f (diff) | |
download | external_python_setuptools-bbdcce69110d8783f21c121bc97fc902809aedf5.tar.gz external_python_setuptools-bbdcce69110d8783f21c121bc97fc902809aedf5.tar.bz2 external_python_setuptools-bbdcce69110d8783f21c121bc97fc902809aedf5.zip |
extract duplicate code
Extracted code for collecting a list of zipimporter cache entries related to a
given path into _collect_zipimporter_cache_entries().
--HG--
extra : rebase_source : 54ab881d794f95467e811511433a2cd31595339e
-rwxr-xr-x | setuptools/command/easy_install.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 39911f17..3f60fae5 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1657,33 +1657,38 @@ def update_dist_caches(dist_path, fix_zipimporter_caches): # really needed. _uncache(normalized_path, zipimport._zip_directory_cache) -def _uncache(normalized_path, cache): - to_remove = [] +def _collect_zipimporter_cache_entries(normalized_path, cache): + """ + Return zipimporter cache entry keys related to a given normalized path. + + Alternative path spellings (e.g. those using different character case or + those using alternative path separators) related to the same path are + included. Any sub-path entries are included as well, i.e. those + corresponding to zip archives embedded in other zip archives. + + """ + result = [] prefix_len = len(normalized_path) for p in cache: np = normalize_path(p) if (np.startswith(normalized_path) and np[prefix_len:prefix_len + 1] in (os.sep, '')): - to_remove.append(p) - for p in to_remove: + result.append(p) + return result + +def _uncache(normalized_path, cache): + for p in _collect_zipimporter_cache_entries(normalized_path, cache): del cache[p] def _replace_zip_directory_cache_data(normalized_path): - cache = zipimport._zip_directory_cache - to_update = [] - prefix_len = len(normalized_path) - for p in cache: - np = normalize_path(p) - if (np.startswith(normalized_path) and - np[prefix_len:prefix_len + 1] in (os.sep, '')): - to_update.append(p) # N.B. In theory, we could load the zip directory information just once for # all updated path spellings, and then copy it locally and update its # contained path strings to contain the correct spelling, but that seems # like a way too invasive move (this cache structure is not officially # documented anywhere and could in theory change with new Python releases) # for no significant benefit. - for p in to_update: + cache = zipimport._zip_directory_cache + for p in _collect_zipimporter_cache_entries(normalized_path, cache): # N.B. pypy's custom zipimport._zip_directory_cache implementation does # not support the complete dict interface, e.g. it does not support the # dict.pop() method. For more detailed information see the following |