summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/__init__.py4
-rw-r--r--lib/spack/spack/cmd/repo.py2
-rw-r--r--lib/spack/spack/cmd/uninstall.py4
-rw-r--r--lib/spack/spack/repo_loader.py110
-rw-r--r--lib/spack/spack/repository.py (renamed from lib/spack/spack/packages.py)19
-rw-r--r--lib/spack/spack/test/directory_layout.py4
-rw-r--r--lib/spack/spack/test/mock_packages_test.py4
-rw-r--r--lib/spack/spack/test/package_sanity.py4
-rw-r--r--lib/spack/spack/test/packages.py2
9 files changed, 25 insertions, 128 deletions
diff --git a/lib/spack/spack/__init__.py b/lib/spack/spack/__init__.py
index 549d0a9a0f..20ae8c9272 100644
--- a/lib/spack/spack/__init__.py
+++ b/lib/spack/spack/__init__.py
@@ -54,11 +54,11 @@ etc_path = join_path(prefix, "etc")
#
# Set up the default packages database.
#
-import spack.packages
+import spack.repository
_repo_paths = spack.config.get_repos_config()
if not _repo_paths:
tty.die("Spack configuration contains no package repositories.")
-db = spack.packages.PackageFinder(*_repo_paths)
+db = spack.repository.RepoPath(*_repo_paths)
sys.meta_path.append(db)
#
diff --git a/lib/spack/spack/cmd/repo.py b/lib/spack/spack/cmd/repo.py
index e290f60b7b..87f21b833d 100644
--- a/lib/spack/spack/cmd/repo.py
+++ b/lib/spack/spack/cmd/repo.py
@@ -32,7 +32,7 @@ from llnl.util.filesystem import join_path, mkdirp
import spack.spec
import spack.config
from spack.util.environment import get_path
-from spack.packages import repo_config_filename
+from spack.repository import repo_config_filename
import os
import exceptions
diff --git a/lib/spack/spack/cmd/uninstall.py b/lib/spack/spack/cmd/uninstall.py
index e80f2d2636..eba76ef71d 100644
--- a/lib/spack/spack/cmd/uninstall.py
+++ b/lib/spack/spack/cmd/uninstall.py
@@ -30,7 +30,7 @@ from llnl.util.tty.colify import colify
import spack
import spack.cmd
-import spack.packages
+import spack.repository
from spack.cmd.find import display_specs
from spack.package import PackageStillNeededError
@@ -80,7 +80,7 @@ def uninstall(parser, args):
# should work if package is known to spack
pkgs.append(s.package)
- except spack.packages.UnknownPackageError, e:
+ except spack.repository.UnknownPackageError, e:
# The package.py file has gone away -- but still want to uninstall.
spack.Package(s).do_uninstall(force=True)
diff --git a/lib/spack/spack/repo_loader.py b/lib/spack/spack/repo_loader.py
deleted file mode 100644
index 441011cf98..0000000000
--- a/lib/spack/spack/repo_loader.py
+++ /dev/null
@@ -1,110 +0,0 @@
-import re
-import sys
-import types
-import traceback
-
-from llnl.util.lang import *
-import spack
-
-# Name of module under which packages are imported
-imported_packages_module = 'spack.repos'
-
-# Name of the package file inside a package directory
-package_file_name = 'package.py'
-
-class LazyLoader:
- """The LazyLoader handles cases when repo modules or classes
- are imported. It watches for 'spack.repos.*' loads, then
- redirects the load to the appropriate module."""
- def find_module(self, fullname, pathname):
- if not fullname.startswith(imported_packages_module):
- return None
-
- partial_name = fullname[len(imported_packages_module)+1:]
-
- print "partial: ", partial_name
- print
-
- last_dot = partial_name.rfind('.')
- repo = partial_name[:last_dot]
- module = partial_name[last_dot+1:]
-
- repo_loader = spack.db.repo_loaders.get(repo)
- if repo_loader:
- try:
- self.mod = repo_loader.get_module(module)
- return self
- except (ImportError, spack.packages.UnknownPackageError):
- return None
-
- def load_module(self, fullname):
- return self.mod
-
-#sys.meta_path.append(LazyLoader())
-
-_reponames = {}
-class RepoNamespace(types.ModuleType):
- """The RepoNamespace holds the repository namespaces under
- spack.repos. For example, when accessing spack.repos.original
- this class will use __getattr__ to translate the 'original'
- into one of spack's known repositories"""
- def __init__(self):
- sys.modules[imported_packages_module] = self
-
- def __getattr__(self, name):
- if name in _reponames:
- return _reponames[name]
- raise AttributeError
-
- @property
- def __file__(self):
- return None
-
- @property
- def __path__(self):
- return []
-
-
-class RepoLoader(types.ModuleType):
- """Each RepoLoader is associated with a repository, and the RepoLoader is
- responsible for loading packages out of that repository. For example,
- a RepoLoader may be responsible for spack.repos.original, and when someone
- references spack.repos.original.libelf that RepoLoader will load the
- libelf package."""
- def __init__(self, reponame, repopath):
- self.path = repopath
- self.reponame = reponame
- self.module_name = imported_packages_module + '.' + reponame
- if not reponame in _reponames:
- _reponames[reponame] = self
-
- sys.modules[self.module_name] = self
-
-
- @property
- def __path__(self):
- return [ self.path ]
-
-
- def __getattr__(self, name):
- if name[0] == '_':
- raise AttributeError
- return self.get_module(name)
-
-
- @memoized
- def get_module(self, pkg_name):
- import os
- import imp
- import llnl.util.tty as tty
-
-
- try:
- module_name = imported_packages_module + '.' + self.reponame + '.' + pkg_name
- module = imp.load_source(module_name, file_path)
-
- except ImportError, e:
- tty.die("Error while importing %s from %s:\n%s" % (
- pkg_name, file_path, e.message))
-
- return module
diff --git a/lib/spack/spack/packages.py b/lib/spack/spack/repository.py
index 8114b7f1aa..c1545b3654 100644
--- a/lib/spack/spack/packages.py
+++ b/lib/spack/spack/repository.py
@@ -67,8 +67,8 @@ def _make_namespace_module(ns):
return module
-class PackageFinder(object):
- """A PackageFinder is a wrapper around a list of Repos.
+class RepoPath(object):
+ """A RepoPath is a list of repos that function as one.
It functions exactly like a Repo, but it operates on the
combined results of the Repos in its list instead of on a
@@ -83,7 +83,10 @@ class PackageFinder(object):
self._provider_index = None
for root in repo_dirs:
- repo = Repo(root)
+ # Try to make it a repo if it's not one.
+ if not isinstance(root, Repo):
+ repo = Repo(root)
+ # Add the repo to the path.
self.put_last(repo)
@@ -94,7 +97,11 @@ class PackageFinder(object):
TODO: Maybe there is a cleaner way.
"""
- attrs = ['repos', 'by_namespace', 'by_path', '_all_package_names', '_provider_index']
+ attrs = ['repos',
+ 'by_namespace',
+ 'by_path',
+ '_all_package_names',
+ '_provider_index']
for attr in attrs:
tmp = getattr(self, attr)
setattr(self, attr, getattr(other, attr))
@@ -185,7 +192,7 @@ class PackageFinder(object):
return repo
# No repo provides the namespace, but it is a valid prefix of
- # something in the PackageFinder.
+ # something in the RepoPath.
if self.by_namespace.is_prefix(fullname):
return self
@@ -603,7 +610,7 @@ class UnknownPackageError(spack.error.SpackError):
class DuplicateRepoError(spack.error.SpackError):
- """Raised when duplicate repos are added to a PackageFinder."""
+ """Raised when duplicate repos are added to a RepoPath."""
def __init__(self, msg, repo1, repo2):
super(UnknownPackageError, self).__init__(
"%s: %s, %s" % (msg, repo1, repo2))
diff --git a/lib/spack/spack/test/directory_layout.py b/lib/spack/spack/test/directory_layout.py
index 55b3f0b18f..580620e0e8 100644
--- a/lib/spack/spack/test/directory_layout.py
+++ b/lib/spack/spack/test/directory_layout.py
@@ -34,7 +34,7 @@ from llnl.util.filesystem import *
import spack
from spack.spec import Spec
-from spack.packages import PackageFinder
+from spack.repository import RepoPath
from spack.directory_layout import YamlDirectoryLayout
# number of packages to test (to reduce test time)
@@ -123,7 +123,7 @@ class DirectoryLayoutTest(unittest.TestCase):
information about installed packages' specs to uninstall
or query them again if the package goes away.
"""
- mock_db = PackageFinder(spack.mock_packages_path)
+ mock_db = RepoPath(spack.mock_packages_path)
not_in_mock = set.difference(
set(spack.db.all_package_names()),
diff --git a/lib/spack/spack/test/mock_packages_test.py b/lib/spack/spack/test/mock_packages_test.py
index 071c21b7e0..8c6273def0 100644
--- a/lib/spack/spack/test/mock_packages_test.py
+++ b/lib/spack/spack/test/mock_packages_test.py
@@ -27,7 +27,7 @@ import unittest
import spack
import spack.config
-from spack.packages import PackageFinder
+from spack.repository import RepoPath
from spack.spec import Spec
@@ -36,7 +36,7 @@ class MockPackagesTest(unittest.TestCase):
# Use the mock packages database for these tests. This allows
# us to set up contrived packages that don't interfere with
# real ones.
- self.db = PackageFinder(spack.mock_packages_path)
+ self.db = RepoPath(spack.mock_packages_path)
spack.db.swap(self.db)
spack.config.clear_config_caches()
diff --git a/lib/spack/spack/test/package_sanity.py b/lib/spack/spack/test/package_sanity.py
index a398568244..0a132fd701 100644
--- a/lib/spack/spack/test/package_sanity.py
+++ b/lib/spack/spack/test/package_sanity.py
@@ -28,7 +28,7 @@ This test does sanity checks on Spack's builtin package database.
import unittest
import spack
-from spack.packages import PackageFinder
+from spack.repository import RepoPath
class PackageSanityTest(unittest.TestCase):
@@ -46,7 +46,7 @@ class PackageSanityTest(unittest.TestCase):
def ztest_get_all_mock_packages(self):
"""Get the mock packages once each too."""
- db = PackageFinder(spack.mock_packages_path)
+ db = RepoPath(spack.mock_packages_path)
spack.db.swap(db)
self.check_db()
spack.db.swap(db)
diff --git a/lib/spack/spack/test/packages.py b/lib/spack/spack/test/packages.py
index 2d19d9ddc7..8a786e364e 100644
--- a/lib/spack/spack/test/packages.py
+++ b/lib/spack/spack/test/packages.py
@@ -27,7 +27,7 @@ import unittest
from llnl.util.filesystem import join_path
import spack
-from spack.packages import Repo
+from spack.repository import Repo
from spack.util.naming import mod_to_class
from spack.test.mock_packages_test import *