Skip to content

Commit

Permalink
PyPIRepository: cache return value of get_dependencies
Browse files Browse the repository at this point in the history
This improves performance, especially for VCS editable dependencies.

Fixes: jazzband#159
  • Loading branch information
blueyed committed May 12, 2015
1 parent 6e3a76a commit 8609b52
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def __init__(self):
# project
self._available_versions_cache = {}

# Cache for get_dependencies.
self._get_dependencies_cache = {}

# Setup file paths
self.freshen_build_caches()
self._download_dir = os.path.expanduser('~/.pip-tools/pkgs')
Expand Down Expand Up @@ -102,6 +105,9 @@ def get_dependencies(self, ireq):
if not (ireq.editable or is_pinned_requirement(ireq)):
raise TypeError('Expected pinned or editable InstallRequirement, got {}'.format(ireq))

if ireq in self._get_dependencies_cache:
return self._get_dependencies_cache[ireq]

if not os.path.isdir(self._download_dir):
os.makedirs(self._download_dir)
if not os.path.isdir(self._wheel_download_dir):
Expand All @@ -113,4 +119,5 @@ def get_dependencies(self, ireq):
wheel_download_dir=self._wheel_download_dir,
session=self.session)
dependencies = reqset._prepare_file(self.finder, ireq)
return set(dependencies)
self._get_dependencies_cache[ireq] = set(dependencies)
return self._get_dependencies_cache[ireq]

0 comments on commit 8609b52

Please sign in to comment.