Skip to content

Commit

Permalink
Fix pex-tool#309 by deduplicating output of the distribution finder. (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
wickman authored and lorencarvalho committed Nov 30, 2016
1 parent 3e547df commit 929e58f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions pex/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,20 @@ def write_zipped_internal_cache(cls, pex, pex_info):
distribution_name, dist_digest))
if os.path.exists(cached_location):
dist = DistributionHelper.distribution_from_path(cached_location)
existing_cached_distributions.append(dist)
continue
if dist is not None:
existing_cached_distributions.append(dist)
continue
else:
dist = DistributionHelper.distribution_from_path(os.path.join(pex, internal_dist_path))
if DistributionHelper.zipsafe(dist) and not pex_info.always_write_cache:
zip_safe_distributions.append(dist)
continue
if dist is not None:
if DistributionHelper.zipsafe(dist) and not pex_info.always_write_cache:
zip_safe_distributions.append(dist)
continue

with TRACER.timed('Caching %s' % dist):
newly_cached_distributions.append(
CacheHelper.cache_distribution(zf, internal_dist_path, cached_location))

return existing_cached_distributions, newly_cached_distributions, zip_safe_distributions

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions pex/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def distribution_from_path(cls, path, name=None):
# Monkeypatch pkg_resources finders should it not already be so.
register_finders()
if name is None:
distributions = list(find_distributions(path))
distributions = set(find_distributions(path))
if len(distributions) == 1:
return distributions[0]
return distributions.pop()
else:
for dist in find_distributions(path):
if dist.project_name == name:
Expand Down

0 comments on commit 929e58f

Please sign in to comment.