summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2016-05-24 11:50:01 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2016-08-08 21:04:23 -0700
commit7aaad89ba93e3ace4bfd835306850f43218e0ef8 (patch)
tree420d53c3e4f84e778dbb2ea6d8a0b8c1337778f5
parent2b94d7cf8eb97e7dd08ea26da0d3481dd36927d5 (diff)
downloadspack-7aaad89ba93e3ace4bfd835306850f43218e0ef8.tar.gz
spack-7aaad89ba93e3ace4bfd835306850f43218e0ef8.tar.bz2
spack-7aaad89ba93e3ace4bfd835306850f43218e0ef8.tar.xz
spack-7aaad89ba93e3ace4bfd835306850f43218e0ef8.zip
Lazily evaluate all_package_names in repository.py
- Don't need to list all packages unless we have to. - Only use the list of all packages for existence checks if we have generated it for some other purpose.
-rw-r--r--lib/spack/spack/repository.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/spack/spack/repository.py b/lib/spack/spack/repository.py
index 2c160a5f45..ae9fd7bee6 100644
--- a/lib/spack/spack/repository.py
+++ b/lib/spack/spack/repository.py
@@ -104,7 +104,7 @@ class RepoPath(object):
self.by_namespace = NamespaceTrie()
self.by_path = {}
- self._all_package_names = []
+ self._all_package_names = None
self._provider_index = None
# If repo_dirs is empty, just use the configuration
@@ -163,11 +163,6 @@ class RepoPath(object):
self.by_namespace[repo.full_namespace] = repo
self.by_path[repo.root] = repo
- # add names to the cached name list
- new_pkgs = set(repo.all_package_names())
- new_pkgs.update(set(self._all_package_names))
- self._all_package_names = sorted(new_pkgs, key=lambda n:n.lower())
-
def put_first(self, repo):
"""Add repo first in the search path."""
@@ -214,6 +209,12 @@ class RepoPath(object):
def all_package_names(self):
"""Return all unique package names in all repositories."""
+ if self._all_package_names is None:
+ all_pkgs = set()
+ for repo in self.repos:
+ for name in repo.all_package_names():
+ all_pkgs.add(name)
+ self._all_package_names = sorted(all_pkgs, key=lambda n:n.lower())
return self._all_package_names
@@ -682,10 +683,16 @@ class Repo(object):
def exists(self, pkg_name):
"""Whether a package with the supplied name exists."""
- # This does a binary search in the sorted list.
- idx = bisect_left(self.all_package_names(), pkg_name)
- return (idx < len(self._all_package_names) and
- self._all_package_names[idx] == pkg_name)
+ if self._all_package_names:
+ # This does a binary search in the sorted list.
+ idx = bisect_left(self.all_package_names(), pkg_name)
+ return (idx < len(self._all_package_names) and
+ self._all_package_names[idx] == pkg_name)
+
+ # If we haven't generated the full package list, don't.
+ # Just check whether the file exists.
+ filename = self.filename_for_package_name(pkg_name)
+ return os.path.exists(filename)
def _get_pkg_module(self, pkg_name):