init: move spack.repo global variable into its own module

- spack.repository module is now spack.repo

- `spack.repo` is now `spack.repo.path()` and loaded lazily

- Added `spack.repo.get()` and `spack.repo.all_package_names()` as
  convenience functions to simplify the new lazy interface.

- updated tests and code
This commit is contained in:
Todd Gamblin 2018-04-28 23:23:16 -07:00 committed by scheibelp
parent 2a09b627c9
commit c615d2be06
63 changed files with 257 additions and 233 deletions

View file

@ -445,7 +445,7 @@ Spack repo namespaces are actually Python namespaces tacked on under
``spack.pkg``. The search semantics of ``repos.yaml`` are actually
implemented using Python's built-in `sys.path
<https://docs.python.org/2/library/sys.html#sys.path>`_ search. The
:py:mod:`spack.repository` module implements a custom `Python importer
:py:mod:`spack.repo` module implements a custom `Python importer
<https://docs.python.org/2/library/imp.html>`_.
.. warning::

View file

@ -23,7 +23,6 @@
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
import sys
#: major, minor, patch version for Spack, in a tuple
spack_version_info = (0, 11, 2)
@ -32,29 +31,9 @@
spack_version = '.'.join(str(v) for v in spack_version_info)
# Set up the default packages database.
import spack.error
try:
import spack.repository
repo = spack.repository.RepoPath()
sys.meta_path.append(repo)
except spack.error.SpackError as e:
import llnl.util.tty as tty
tty.die('while initializing Spack RepoPath:', e.message)
#-----------------------------------------------------------------------------
# When packages call 'from spack import *', we import a set of things that
# should be useful for builds.
#
# Spack internal code should call 'import spack' and accesses other
# variables (spack.repo, paths, etc.) directly.
#
# TODO: maybe this should be separated out to build_environment.py?
# TODO: it's not clear where all the stuff that needs to be included in
# packages should live. This file is overloaded for spack core vs.
# for packages.
#
#-----------------------------------------------------------------------------
__all__ = []

View file

@ -587,8 +587,8 @@ def setup_package(pkg, dirty):
for dspec in pkg.spec.traverse(order='post', root=False,
deptype=('build', 'test')):
# If a user makes their own package repo, e.g.
# spack.repos.mystuff.libelf.Libelf, and they inherit from
# an existing class like spack.repos.original.libelf.Libelf,
# spack.pkg.mystuff.libelf.Libelf, and they inherit from
# an existing class like spack.pkg.original.libelf.Libelf,
# then set the module variables for both classes so the
# parent class can still use them if it gets called.
spkg = dspec.package

View file

@ -31,6 +31,7 @@
from llnl.util.tty.colify import colify_table
import spack.paths
import spack.repo
from spack.util.executable import which
from spack.cmd import spack_is_git_repo

View file

@ -23,7 +23,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
import llnl.util.tty as tty
import spack
import spack.repo
import spack.cmd
import spack.cmd.common.arguments as arguments

View file

@ -26,8 +26,10 @@
import llnl.util.tty as tty
import spack
import spack.cmd
import spack.repo
import spack.store
import spack.spec
import spack.binary_distribution as bindist
description = "create, download and install binary packages"

View file

@ -27,8 +27,9 @@
import argparse
import llnl.util.tty as tty
import spack
import spack.cmd
import spack.repo
import spack.util.crypto
import spack.util.web
from spack.util.naming import valid_fully_qualified_module_name

View file

@ -26,9 +26,10 @@
import llnl.util.tty as tty
import spack
import spack.caches
import spack.cmd
import spack.repo
import spack.stage
description = "remove temporary build files and/or downloaded archives"
section = "build"

View file

@ -32,7 +32,7 @@
import spack.cmd
import spack.util.web
from llnl.util.filesystem import mkdirp
from spack.repository import Repo
import spack.repo
from spack.spec import Spec
from spack.util.executable import which, ProcessError
from spack.util.naming import mod_to_class
@ -648,17 +648,17 @@ def get_repository(args, name):
# Figure out where the new package should live
repo_path = args.repo
if repo_path is not None:
repo = Repo(repo_path)
repo = spack.repo.Repo(repo_path)
if spec.namespace and spec.namespace != repo.namespace:
tty.die("Can't create package with namespace {0} in repo with "
"namespace {1}".format(spec.namespace, repo.namespace))
else:
if spec.namespace:
repo = spack.repo.get_repo(spec.namespace, None)
repo = spack.repo.path().get_repo(spec.namespace, None)
if not repo:
tty.die("Unknown namespace: '{0}'".format(spec.namespace))
else:
repo = spack.repo.first_repo()
repo = spack.repo.path().first_repo()
# Set the namespace on the spec if it's not there already
if not spec.namespace:

View file

@ -27,8 +27,8 @@
import llnl.util.tty as tty
from llnl.util.tty.colify import colify
import spack
import spack.store
import spack.repo
import spack.cmd
description = "show dependencies of a package"
@ -73,8 +73,9 @@ def dependencies(parser, args):
if not spec.virtual:
packages = [spec.package]
else:
packages = [spack.repo.get(s.name)
for s in spack.repo.providers_for(spec)]
packages = [
spack.repo.get(s.name)
for s in spack.repo.path().providers_for(spec)]
dependencies = set()
for pkg in packages:

View file

@ -27,7 +27,7 @@
import llnl.util.tty as tty
from llnl.util.tty.colify import colify
import spack
import spack.repo
import spack.store
import spack.cmd
@ -57,14 +57,14 @@ def inverted_dependencies():
actual dependents.
"""
dag = {}
for pkg in spack.repo.all_packages():
for pkg in spack.repo.path().all_packages():
dag.setdefault(pkg.name, set())
for dep in pkg.dependencies:
deps = [dep]
# expand virtuals if necessary
if spack.repo.is_virtual(dep):
deps += [s.name for s in spack.repo.providers_for(dep)]
if spack.repo.path().is_virtual(dep):
deps += [s.name for s in spack.repo.path().providers_for(dep)]
for d in deps:
dag.setdefault(d, set()).add(pkg.name)

View file

@ -28,9 +28,9 @@
import llnl.util.tty as tty
import spack
import spack.config
import spack.cmd
import spack.repo
import spack.cmd.common.arguments as arguments
from spack.stage import DIYStage
@ -78,7 +78,7 @@ def diy(self, args):
tty.die("spack diy only takes one spec.")
spec = specs[0]
if not spack.repo.exists(spec.name):
if not spack.repo.path().exists(spec.name):
tty.die("No package for '{0}' was found.".format(spec.name),
" Use `spack create` to create a new package")

View file

@ -29,8 +29,8 @@
import spack.cmd
import spack.paths
import spack.repo
from spack.spec import Spec
from spack.repository import Repo
from spack.util.editor import editor
description = "open package files in $EDITOR"
@ -48,11 +48,11 @@ def edit_package(name, repo_path, namespace):
"""
# Find the location of the package
if repo_path:
repo = Repo(repo_path)
repo = spack.repo.Repo(repo_path)
elif namespace:
repo = spack.repo.get_repo(namespace)
repo = spack.repo.path().get_repo(namespace)
else:
repo = spack.repo
repo = spack.repo.path()
path = repo.filename_for_package_name(name)
spec = Spec(name)

View file

@ -27,9 +27,9 @@
import llnl.util.tty as tty
from llnl.util.tty.colify import colify
import spack
import spack.cmd
import spack.cmd.find
import spack.repo
import spack.store
from spack.directory_layout import YamlViewExtensionsLayout
@ -105,7 +105,7 @@ def extensions(parser, args):
if show_packages:
#
# List package names of extensions
extensions = spack.repo.extensions_for(spec)
extensions = spack.repo.path().extensions_for(spec)
if not extensions:
tty.msg("%s has no extensions." % spec.cshort_spec)
else:

View file

@ -26,8 +26,9 @@
import llnl.util.tty as tty
import spack
import spack.cmd
import spack.config
import spack.repo
import spack.cmd.common.arguments as arguments
description = "fetch archives for packages"

View file

@ -26,8 +26,8 @@
import llnl.util.tty as tty
import llnl.util.lang
import spack
import spack.database
import spack.repo
import spack.cmd.common.arguments as arguments
from spack.cmd import display_specs
@ -147,7 +147,7 @@ def find(parser, args):
# If tags have been specified on the command line, filter by tags
if args.tags:
packages_with_tags = spack.repo.packages_with_tags(*args.tags)
packages_with_tags = spack.repo.path().packages_with_tags(*args.tags)
query_specs = [x for x in query_specs if x.name in packages_with_tags]
# Display the result

View file

@ -25,15 +25,15 @@
from __future__ import print_function
import textwrap
from six.moves import zip_longest
import llnl.util.tty.color as color
from llnl.util.tty.colify import colify
import llnl.util.tty.color as color
import spack
import spack.fetch_strategy as fs
import spack.repo
import spack.spec
import spack.fetch_strategy as fs
description = 'get detailed information on a particular package'
section = 'basic'

View file

@ -37,7 +37,8 @@
import llnl.util.tty as tty
from llnl.util.tty.colify import colify
import spack
import spack.dependency
import spack.repo
import spack.cmd.common.arguments as arguments
description = "list and search available packages"
@ -184,7 +185,7 @@ def rst(pkg_names):
reversed(sorted(pkg.versions))))
print()
for deptype in spack.all_deptypes:
for deptype in spack.dependency.all_deptypes:
deps = pkg.dependencies_of_type(deptype)
if deps:
print('%s Dependencies' % deptype.capitalize())
@ -272,7 +273,7 @@ def head(n, span_id, title, anchor=None):
print(', '.join(str(v) for v in reversed(sorted(pkg.versions))))
print('</dd>')
for deptype in spack.all_deptypes:
for deptype in spack.dependency.all_deptypes:
deps = pkg.dependencies_of_type(deptype)
if deps:
print('<dt>%s Dependencies:</dt>' % deptype.capitalize())
@ -301,7 +302,8 @@ def list(parser, args):
# Filter by tags
if args.tags:
packages_with_tags = set(spack.repo.packages_with_tags(*args.tags))
packages_with_tags = set(
spack.repo.path().packages_with_tags(*args.tags))
sorted_packages = set(sorted_packages) & packages_with_tags
sorted_packages = sorted(sorted_packages)

View file

@ -29,6 +29,7 @@
import spack.paths
import spack.cmd
import spack.repo
description = "print out locations of various directories used by Spack"
section = "environment"
@ -79,7 +80,7 @@ def location(parser, args):
print(spack.paths.prefix)
elif args.packages:
print(spack.repo.first_repo().root)
print(spack.repo.path().first_repo().root)
elif args.stages:
print(spack.paths.stage_path)
@ -101,7 +102,7 @@ def location(parser, args):
if args.package_dir:
# This one just needs the spec name.
print(spack.repo.dirname_for_package_name(spec.name))
print(spack.repo.path().dirname_for_package_name(spec.name))
else:
# These versions need concretized specs.

View file

@ -29,11 +29,11 @@
import llnl.util.tty as tty
from llnl.util.tty.colify import colify
import spack
import spack.cmd
import spack.concretize
import spack.config
import spack.mirror
import spack.repo
import spack.cmd.common.arguments as arguments
from spack.spec import Spec
from spack.error import SpackError

View file

@ -27,10 +27,12 @@
import collections
import os
import shutil
import spack.modules
from llnl.util import filesystem, tty
import spack.cmd
from llnl.util import filesystem, tty
import spack.modules
import spack.repo
from spack.cmd.common import arguments
description = "manipulate module files"
@ -278,9 +280,10 @@ def refresh(module_types, specs, args):
cls = spack.modules.module_types[module_type]
# skip unknown packages.
writers = [
cls(spec) for spec in specs if spack.repo.exists(spec.name)
] # skip unknown packages.
cls(spec) for spec in specs
if spack.repo.path().exists(spec.name)]
# Filter blacklisted packages early
writers = [x for x in writers if not x.conf.blacklisted]

View file

@ -26,7 +26,7 @@
import llnl.util.tty as tty
import spack
import spack.repo
import spack.cmd
import spack.cmd.common.arguments as arguments

View file

@ -25,13 +25,14 @@
from __future__ import print_function
import os
import argparse
import llnl.util.tty as tty
from llnl.util.tty.colify import colify
from llnl.util.filesystem import working_dir
import spack.paths
import spack.repo
from spack.util.executable import which
from spack.cmd import spack_is_git_repo
@ -90,7 +91,7 @@ def list_packages(rev):
def pkg_add(args):
for pkg_name in args.packages:
filename = spack.repo.filename_for_package_name(pkg_name)
filename = spack.repo.path().filename_for_package_name(pkg_name)
if not os.path.isfile(filename):
tty.die("No such package: %s. Path does not exist:" %
pkg_name, filename)

View file

@ -27,8 +27,8 @@
import llnl.util.tty.colify as colify
import spack
import spack.cmd
import spack.repo
description = "list packages that provide a particular virtual package"
section = "basic"
@ -46,7 +46,7 @@ def setup_parser(subparser):
def providers(parser, args):
valid_virtuals = sorted(spack.repo.provider_index.providers.keys())
valid_virtuals = sorted(spack.repo.path().provider_index.providers.keys())
buffer = six.StringIO()
isatty = sys.stdout.isatty()
@ -77,5 +77,5 @@ def providers(parser, args):
for spec in specs:
if sys.stdout.isatty():
print("{0}:".format(spec))
spack.cmd.display_specs(sorted(spack.repo.providers_for(spec)))
spack.cmd.display_specs(sorted(spack.repo.path().providers_for(spec)))
print('')

View file

@ -30,7 +30,7 @@
import spack.spec
import spack.config
from spack.repository import Repo, create_repo, canonicalize_path, RepoError
from spack.repo import Repo, create_repo, canonicalize_path, RepoError
description = "manage package source repositories"
section = "config"

View file

@ -26,8 +26,8 @@
import llnl.util.tty as tty
import spack
import spack.cmd
import spack.repo
description = "revert checked out package source code"
section = "build"

View file

@ -29,13 +29,15 @@
import sys
import llnl.util.tty as tty
import spack
from llnl.util.filesystem import set_executable
import spack.repo
import spack.store
import spack.cmd
import spack.cmd.install as install
import spack.cmd.common.arguments as arguments
from llnl.util.filesystem import set_executable
from spack import which
from spack.util.executable import which
from spack.stage import DIYStage
description = "create a configuration script and module, but don't build"
@ -135,7 +137,7 @@ def setup(self, args):
# Take a write lock before checking for existence.
with spack.store.db.write_transaction():
spec = specs[0]
if not spack.repo.exists(spec.name):
if not spack.repo.path().exists(spec.name):
tty.die("No package for '{0}' was found.".format(spec.name),
" Use `spack create` to create a new package")
if not spec.versions.concrete:

View file

@ -26,7 +26,7 @@
import llnl.util.tty as tty
import spack
import spack.repo
import spack.cmd
import spack.cmd.common.arguments as arguments

View file

@ -29,7 +29,7 @@
import spack
import spack.cmd
import spack.store
import spack.repository
import spack.repo
from llnl.util import tty
@ -149,7 +149,7 @@ def do_uninstall(specs, force):
try:
# should work if package is known to spack
packages.append(item.package)
except spack.repository.UnknownEntityError:
except spack.repo.UnknownEntityError:
# The package.py file has gone away -- but still
# want to uninstall.
spack.Package.uninstall_by_spec(item, force=True)

View file

@ -26,7 +26,7 @@
from collections import defaultdict
import spack
import spack.repo
from llnl.util import tty
from spack.url import parse_version_offset, parse_name_offset
@ -144,7 +144,7 @@ def url_list(args):
urls = set()
# Gather set of URLs from all packages
for pkg in spack.repo.all_packages():
for pkg in spack.repo.path().all_packages():
url = getattr(pkg.__class__, 'url', None)
urls = url_list_parsing(args, urls, url, pkg)
@ -178,7 +178,7 @@ def url_summary(args):
tty.msg('Generating a summary of URL parsing in Spack...')
# Loop through all packages
for pkg in spack.repo.all_packages():
for pkg in spack.repo.path().all_packages():
urls = set()
url = getattr(pkg.__class__, 'url', None)

View file

@ -26,7 +26,8 @@
from llnl.util.tty.colify import colify
import llnl.util.tty as tty
import spack
import spack.repo
description = "list available versions of a package"
section = "packaging"

View file

@ -39,7 +39,7 @@
from contextlib import contextmanager
from six import iteritems
import spack
import spack.repo
import spack.abi
import spack.spec
import spack.compilers
@ -102,7 +102,7 @@ def _valid_virtuals_and_externals(self, spec):
pref_key = lambda spec: 0 # no-op pref key
if spec.virtual:
candidates = spack.repo.providers_for(spec)
candidates = spack.repo.path().providers_for(spec)
if not candidates:
raise spack.spec.UnsatisfiableProviderSpecError(
candidates[0], spec)

View file

@ -55,7 +55,7 @@
from llnl.util.lock import Lock, WriteTransaction, ReadTransaction
import spack.store
import spack.repository
import spack.repo
import spack.spec
import spack.util.spack_yaml as syaml
import spack.util.spack_json as sjson
@ -903,7 +903,7 @@ def query(
if explicit is not any and rec.explicit != explicit:
continue
if known is not any and spack.repo.exists(
if known is not any and spack.repo.path().exists(
rec.spec.name) != known:
continue

View file

@ -43,6 +43,8 @@
import spack
import spack.config
import spack.paths
import spack.repo
import spack.util.debug
from spack.error import SpackError
@ -347,13 +349,12 @@ def setup_main_options(args):
tty.set_stacktrace(args.stacktrace)
if args.debug:
import spack.util.debug as debug
debug.register_interrupt_handler()
spack.util.debug.register_interrupt_handler()
spack.config.set('config:debug', True, scope='command_line')
if args.mock:
from spack.repository import RepoPath
spack.repo.swap(RepoPath(spack.paths.mock_packages_path))
rp = spack.repo.RepoPath(spack.paths.mock_packages_path)
spack.repo.set_path(rp)
# If the user asked for it, don't check ssl certs.
if args.insecure:

View file

@ -53,7 +53,6 @@
import llnl.util.tty as tty
import spack
import spack.config
import spack.paths
import spack.store
@ -64,7 +63,7 @@
import spack.hooks
import spack.mirror
import spack.mixins
import spack.repository
import spack.repo
import spack.url
import spack.util.web
import spack.multimethod
@ -662,9 +661,9 @@ def possible_dependencies(
visited = set([self.name])
for i, name in enumerate(self.dependencies):
if spack.repo.is_virtual(name):
if spack.repo.path().is_virtual(name):
if expand_virtuals:
providers = spack.repo.providers_for(name)
providers = spack.repo.path().providers_for(name)
dep_names = [spec.name for spec in providers]
else:
visited.add(name)
@ -1934,7 +1933,7 @@ def uninstall_by_spec(spec, force=False):
# Try to get the pcakage for the spec
try:
pkg = spec.package
except spack.repository.UnknownEntityError:
except spack.repo.UnknownEntityError:
pkg = None
# Pre-uninstall hook runs first.
@ -2313,25 +2312,25 @@ def dump_packages(spec, path):
# Create a source repo and get the pkg directory out of it.
try:
source_repo = spack.repository.Repo(source_repo_root)
source_repo = spack.repo.Repo(source_repo_root)
source_pkg_dir = source_repo.dirname_for_package_name(
node.name)
except spack.repository.RepoError:
except spack.repo.RepoError:
tty.warn("Warning: Couldn't copy in provenance for %s" %
node.name)
# Create a destination repository
dest_repo_root = join_path(path, node.namespace)
if not os.path.exists(dest_repo_root):
spack.repository.create_repo(dest_repo_root)
repo = spack.repository.Repo(dest_repo_root)
spack.repo.create_repo(dest_repo_root)
repo = spack.repo.Repo(dest_repo_root)
# Get the location of the package in the dest repo.
dest_pkg_dir = repo.dirname_for_package_name(node.name)
if node is not spec:
install_tree(source_pkg_dir, dest_pkg_dir)
else:
spack.repo.dump_provenance(node, dest_pkg_dir)
spack.repo.path().dump_provenance(node, dest_pkg_dir)
def print_pkg(message):

View file

@ -27,7 +27,7 @@
from llnl.util.lang import classproperty
import spack
import spack.repo
import spack.error
from spack.util.path import canonicalize_path
from spack.version import VersionList
@ -51,7 +51,7 @@ def get_packages_config():
# by sometihng, not just packages/names that don't exist.
# So, this won't include, e.g., 'all'.
virtuals = [(pkg_name, pkg_name._start_mark) for pkg_name in config
if spack.repo.is_virtual(pkg_name)]
if spack.repo.path().is_virtual(pkg_name)]
# die if there are virtuals in `packages.py`
if virtuals:

View file

@ -26,7 +26,7 @@
import os
import platform
import re
import spack
import spack.repo
import spack.cmd
from spack.util.executable import Executable, ProcessError
from llnl.util.filesystem import filter_file

View file

@ -33,6 +33,8 @@
import re
import traceback
import json
from contextlib import contextmanager
from six import string_types
try:
from collections.abc import Mapping
@ -222,8 +224,7 @@ def update_package(self, pkg_name):
pkg_name (str): name of the package to be removed from the index
"""
package = spack.repo.get(pkg_name)
package = path().get(pkg_name)
# Remove the package from the list of packages, if present
for pkg_list in self._tag_dict.values():
@ -345,13 +346,19 @@ def make_tag_index_cache(packages_path, namespace):
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
single package repository.
It functions exactly like a Repo, but it operates on the combined
results of the Repos in its list instead of on a single package
repository.
Args:
repos (list): list Repo objects or paths to put in this RepoPath
Optional Args:
repo_namespace (str): super-namespace for all packages in this
RepoPath (used when importing repos as modules)
"""
def __init__(self, *repo_dirs, **kwargs):
# super-namespace for all packages in the RepoPath
def __init__(self, *repos, **kwargs):
self.super_namespace = kwargs.get('namespace', repo_namespace)
self.repos = []
@ -361,41 +368,17 @@ def __init__(self, *repo_dirs, **kwargs):
self._all_package_names = None
self._provider_index = None
# If repo_dirs is empty, just use the configuration
if not repo_dirs:
import spack.config
repo_dirs = spack.config.get('repos')
if not repo_dirs:
raise NoRepoConfiguredError(
"Spack configuration contains no package repositories.")
# Add each repo to this path.
for root in repo_dirs:
for repo in repos:
try:
repo = Repo(root, self.super_namespace)
if isinstance(repo, string_types):
repo = Repo(repo, self.super_namespace)
self.put_last(repo)
except RepoError as e:
tty.warn("Failed to initialize repository at '%s'." % root,
tty.warn("Failed to initialize repository: '%s'." % repo,
e.message,
"To remove the bad repository, run this command:",
" spack repo rm %s" % root)
def swap(self, other):
"""Convenience function to make swapping repositories easier.
This is currently used by mock tests.
TODO: Maybe there is a cleaner way.
"""
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))
setattr(other, attr, tmp)
" spack repo rm %s" % repo)
def _add(self, repo):
"""Add a repository to the namespace and path indexes.
@ -1096,6 +1079,70 @@ def create_repo(root, namespace=None):
return full_path, namespace
#: Singleton repo path instance
_path = None
def set_path(repo):
"""Set the path() singleton to a specific value.
Overwrite _path and register it as an importer in sys.meta_path if
it is a ``Repo`` or ``RepoPath``.
"""
global _path
_path = repo
# make the new repo_path an importer if needed
append = isinstance(repo, (Repo, RepoPath))
if append:
sys.meta_path.append(_path)
return append
def path():
"""Get the singleton RepoPath instance for Spack.
Create a RepoPath, add it to sys.meta_path, and return it.
TODO: consider not making this a singleton.
"""
if _path is None:
repo_dirs = spack.config.get('repos')
if not repo_dirs:
raise NoRepoConfiguredError(
"Spack configuration contains no package repositories.")
set_path(RepoPath(*repo_dirs))
return _path
def get(spec):
"""Convenience wrapper around ``spack.repo.get()``."""
return path().get(spec)
def all_package_names():
"""Convenience wrapper around ``spack.repo.all_package_names()``."""
return path().all_package_names()
@contextmanager
def swap(repo_path):
"""Temporarily use another RepoPath."""
global _path
# swap out _path for repo_path
saved = _path
remove_from_meta = set_path(repo_path)
yield
# restore _path and sys.meta_path
if remove_from_meta:
sys.meta_path.remove(repo_path)
_path = saved
class RepoError(spack.error.SpackError):
"""Superclass for repository-related errors."""

View file

@ -114,12 +114,11 @@
from llnl.util.lang import check_kwargs
from llnl.util.tty.color import cwrite, colorize, cescape, get_color_when
import spack
import spack.architecture
import spack.compilers as compilers
import spack.error
import spack.parse
import spack.repo
import spack.store
import spack.util.spack_json as sjson
import spack.util.spack_yaml as syaml
@ -1229,7 +1228,7 @@ def package_class(self):
"""Internal package call gets only the class object for a package.
Use this to just get package metadata.
"""
return spack.repo.get_pkg_class(self.fullname)
return spack.repo.path().get_pkg_class(self.fullname)
@property
def virtual(self):
@ -1245,7 +1244,7 @@ def virtual(self):
@staticmethod
def is_virtual(name):
"""Test if a name is virtual without requiring a Spec."""
return (name is not None) and (not spack.repo.exists(name))
return (name is not None) and (not spack.repo.path().exists(name))
@property
def concrete(self):
@ -1850,7 +1849,7 @@ def concretize(self, tests=False):
# we can do it as late as possible to allow as much
# compatibility across repositories as possible.
if s.namespace is None:
s.namespace = spack.repo.repo_for_pkg(s.name).namespace
s.namespace = spack.repo.path().repo_for_pkg(s.name).namespace
if s.concrete:
continue
@ -2456,7 +2455,7 @@ def satisfies(self, other, deps=True, strict=False, strict_deps=False):
if not self.virtual and other.virtual:
try:
pkg = spack.repo.get(self.fullname)
except spack.repository.UnknownEntityError:
except spack.repo.UnknownEntityError:
# If we can't get package info on this spec, don't treat
# it as a provider of this vdep.
return False

View file

@ -26,6 +26,7 @@
import spack
import pytest
import spack.repo
from spack.build_environment import get_std_cmake_args
from spack.spec import Spec

View file

@ -31,7 +31,7 @@
import spack.paths
from spack.cmd.flake8 import flake8, setup_parser, changed_files
from spack.repository import Repo
from spack.repo import Repo
from spack.util.executable import which

View file

@ -165,8 +165,8 @@ def test_install_output_on_build_error(mock_packages, mock_archive, mock_fetch,
@pytest.mark.disable_clean_stage_check
def test_install_output_on_python_error(mock_packages, mock_archive, mock_fetch,
config, install_mockery):
def test_install_output_on_python_error(
mock_packages, mock_archive, mock_fetch, config, install_mockery):
out = install('failing-build', fail_on_error=False)
assert isinstance(install.error, spack.build_environment.ChildError)
assert install.error.name == 'InstallError'

View file

@ -24,8 +24,9 @@
##############################################################################
import pytest
import llnl.util.lang
import spack
import spack.architecture
import spack.repo
from spack.concretize import find_spec
from spack.spec import Spec, CompilerSpec
@ -161,7 +162,7 @@ def test_concretize_with_provides_when(self):
"""Make sure insufficient versions of MPI are not in providers list when
we ask for some advanced version.
"""
repo = spack.repo
repo = spack.repo.path()
assert not any(
s.satisfies('mpich2@:1.0') for s in repo.providers_for('mpi@2.1')
)
@ -181,7 +182,7 @@ def test_concretize_with_provides_when(self):
def test_provides_handles_multiple_providers_of_same_vesrion(self):
"""
"""
providers = spack.repo.providers_for('mpi@3.0')
providers = spack.repo.path().providers_for('mpi@3.0')
# Note that providers are repo-specific, so we don't misinterpret
# providers, but vdeps are not namespace-specific, so we can
@ -216,8 +217,6 @@ def test_architecture_deep_inheritance(self):
information from the root even when partial architecture information
is provided by an intermediate dependency.
"""
saved_repo = spack.repo
default_dep = ('link', 'build')
bazpkg = MockPackage('bazpkg', [], [])
@ -225,9 +224,7 @@ def test_architecture_deep_inheritance(self):
foopkg = MockPackage('foopkg', [barpkg], [default_dep])
mock_repo = MockPackageMultiRepo([foopkg, barpkg, bazpkg])
spack.repo = mock_repo
try:
with spack.repo.swap(mock_repo):
spec = Spec('foopkg %clang@3.3 os=CNL target=footar' +
' ^barpkg os=SuSE11 ^bazpkg os=be')
spec.concretize()
@ -235,9 +232,6 @@ def test_architecture_deep_inheritance(self):
for s in spec.traverse(root=False):
assert s.architecture.target == spec.architecture.target
finally:
spack.repo = saved_repo
def test_compiler_flags_from_user_are_grouped(self):
spec = Spec('a%gcc cflags="-O -foo-flag foo-val" platform=test')
spec.concretize()

View file

@ -25,6 +25,7 @@
import pytest
import spack.package_prefs
import spack.repo
import spack.util.spack_yaml as syaml
from spack.config import ConfigScope
from spack.spec import Spec
@ -41,7 +42,7 @@ def concretize_scope(config, tmpdir):
config.pop_scope()
spack.package_prefs.PackagePrefs.clear_caches()
spack.repo._provider_index = None
spack.repo.path()._provider_index = None
def concretize(abstract_spec):

View file

@ -33,7 +33,6 @@
from llnl.util.filesystem import remove_linked_tree
import spack
import spack.architecture
import spack.config
import spack.caches
@ -41,7 +40,7 @@
import spack.directory_layout
import spack.paths
import spack.platforms.test
import spack.repository
import spack.repo
import spack.stage
import spack.util.ordereddict
import spack.util.executable
@ -173,25 +172,23 @@ def __str__(self):
@pytest.fixture(scope='session')
def repo_path():
"""Session scoped RepoPath object pointing to the mock repository"""
return spack.repository.RepoPath(spack.paths.mock_packages_path)
return spack.repo.RepoPath(spack.paths.mock_packages_path)
@pytest.fixture(scope='module')
def mock_packages(repo_path):
"""Use the 'builtin.mock' repository instead of 'builtin'"""
mock_repo = copy.deepcopy(repo_path)
spack.repo.swap(mock_repo)
yield
spack.repo.swap(mock_repo)
with spack.repo.swap(mock_repo):
yield
@pytest.fixture(scope='function')
def mutable_mock_packages(mock_packages, repo_path):
"""Function-scoped mock packages, for tests that need to modify them."""
mock_repo = copy.deepcopy(repo_path)
spack.repo.swap(mock_repo)
yield
spack.repo.swap(mock_repo)
with spack.repo.swap(mock_repo):
yield
@pytest.fixture(scope='session')
@ -221,6 +218,7 @@ def configuration_dir(tmpdir_factory, linux_os):
compilers_yaml = test_path.join('data', 'compilers.yaml')
packages_yaml = test_path.join('data', 'packages.yaml')
config_yaml = test_path.join('data', 'config.yaml')
repos_yaml = test_path.join('data', 'repos.yaml')
# Create temporary 'site' and 'user' folders
tmpdir.ensure('site', dir=True)
@ -229,6 +227,7 @@ def configuration_dir(tmpdir_factory, linux_os):
# Copy the configurations that don't need further work
packages_yaml.copy(tmpdir.join('site', 'packages.yaml'))
config_yaml.copy(tmpdir.join('site', 'config.yaml'))
repos_yaml.copy(tmpdir.join('site', 'repos.yaml'))
# Write the one that needs modifications
content = ''.join(compilers_yaml.read()).format(linux_os)
@ -245,8 +244,6 @@ def config(configuration_dir):
real_configuration = spack.config._configuration
print real_configuration
scopes = [
spack.config.ConfigScope(name, str(configuration_dir.join(name)))
for name in ['site', 'system', 'user']]

View file

@ -0,0 +1,2 @@
repos:
- $spack/var/spack/repos/builtin

View file

@ -33,7 +33,7 @@
from llnl.util.tty.colify import colify
import spack
import spack.repo
import spack.store
from spack.test.conftest import MockPackageMultiRepo
from spack.util.executable import Executable
@ -432,17 +432,12 @@ def fail_while_writing():
def test_115_reindex_with_packages_not_in_repo(database, refresh_db_on_exit):
install_db = database.mock.db
saved_repo = spack.repo
# Dont add any package definitions to this repository, the idea is that
# packages should not have to be defined in the repository once they
# are installed
mock_repo = MockPackageMultiRepo([])
try:
spack.repo = mock_repo
with spack.repo.swap(MockPackageMultiRepo([])):
spack.store.db.reindex(spack.store.layout)
_check_db_sanity(install_db)
finally:
spack.repo = saved_repo
def test_external_entries_in_db(database):

View file

@ -30,11 +30,10 @@
from llnl.util.filesystem import join_path
import spack
import spack.paths
import spack.repo
from spack.directory_layout import YamlDirectoryLayout
from spack.directory_layout import InvalidDirectoryLayoutParametersError
from spack.repository import RepoPath
from spack.spec import Spec
# number of packages to test (to reduce test time)
@ -105,7 +104,7 @@ def test_read_and_write_spec(
layout.
"""
layout, tmpdir = layout_and_dir
packages = list(spack.repo.all_packages())[:max_packages]
packages = list(spack.repo.path().all_packages())[:max_packages]
for pkg in packages:
if pkg.name.startswith('external'):
@ -187,7 +186,7 @@ def test_handle_unknown_package(
or query them again if the package goes away.
"""
layout, _ = layout_and_dir
mock_db = RepoPath(spack.paths.mock_packages_path)
mock_db = spack.repo.RepoPath(spack.paths.mock_packages_path)
not_in_mock = set.difference(
set(spack.repo.all_package_names()),
@ -209,28 +208,25 @@ def test_handle_unknown_package(
layout.create_install_directory(spec)
installed_specs[spec] = layout.path_for_spec(spec)
spack.repo.swap(mock_db)
with spack.repo.swap(mock_db):
# Now check that even without the package files, we know
# enough to read a spec from the spec file.
for spec, path in installed_specs.items():
spec_from_file = layout.read_spec(
join_path(path, '.spack', 'spec.yaml'))
# Now check that even without the package files, we know
# enough to read a spec from the spec file.
for spec, path in installed_specs.items():
spec_from_file = layout.read_spec(
join_path(path, '.spack', 'spec.yaml')
)
# To satisfy these conditions, directory layouts need to
# read in concrete specs from their install dirs somehow.
assert path == layout.path_for_spec(spec_from_file)
assert spec == spec_from_file
assert spec.eq_dag(spec_from_file)
assert spec.dag_hash() == spec_from_file.dag_hash()
spack.repo.swap(mock_db)
# To satisfy these conditions, directory layouts need to
# read in concrete specs from their install dirs somehow.
assert path == layout.path_for_spec(spec_from_file)
assert spec == spec_from_file
assert spec.eq_dag(spec_from_file)
assert spec.dag_hash() == spec_from_file.dag_hash()
def test_find(layout_and_dir, config, mock_packages):
"""Test that finding specs within an install layout works."""
layout, _ = layout_and_dir
packages = list(spack.repo.all_packages())[:max_packages]
packages = list(spack.repo.path().all_packages())[:max_packages]
# Create install prefixes for all packages in the list
installed_specs = {}

View file

@ -26,6 +26,7 @@
import os
import spack.spec
import spack.repo
import spack.build_environment

View file

@ -28,7 +28,7 @@
from llnl.util.filesystem import working_dir, join_path, touch
import spack
import spack.repo
import spack.config
from spack.spec import Spec
from spack.version import ver

View file

@ -28,7 +28,7 @@
from llnl.util.filesystem import working_dir, join_path, touch
import spack
import spack.repo
import spack.config
from spack.spec import Spec
from spack.version import ver

View file

@ -25,7 +25,7 @@
import os
import pytest
import spack
import spack.repo
import spack.store
from spack.spec import Spec

View file

@ -28,7 +28,7 @@
from llnl.util.filesystem import join_path
import spack
import spack.repo
import spack.mirror
import spack.util.executable
from spack.spec import Spec

View file

@ -23,8 +23,9 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
"""Test for multi_method dispatch."""
import spack
import pytest
import spack.repo
from spack.multimethod import NoSuchMethodError

View file

@ -27,9 +27,9 @@
import pytest
import spack
import spack.repo
from spack.paths import mock_packages_path
from spack.repository import RepoPath
from spack.repo import RepoPath
def check_db():
@ -47,9 +47,8 @@ def test_get_all_packages():
def test_get_all_mock_packages():
"""Get the mock packages once each too."""
db = RepoPath(mock_packages_path)
spack.repo.swap(db)
check_db()
spack.repo.swap(db)
with spack.repo.swap(db):
check_db()
def test_all_versions_are_lowercase():
@ -66,7 +65,7 @@ def test_all_virtual_packages_have_default_providers():
"""All virtual packages must have a default provider explicitly set."""
defaults = spack.config.get('packages', scope='defaults')
default_providers = defaults['all']['providers']
providers = spack.repo.provider_index.providers
providers = spack.repo.path().provider_index.providers
for provider in providers:
assert provider in default_providers

View file

@ -26,9 +26,8 @@
from llnl.util.filesystem import join_path
import spack
import spack.repo
from spack.paths import mock_packages_path
from spack.repository import Repo
from spack.util.naming import mod_to_class
from spack.spec import Spec
from spack.util.package_hash import package_content
@ -44,7 +43,7 @@ def test_package_name(self):
assert pkg.name == 'mpich'
def test_package_filename(self):
repo = Repo(mock_packages_path)
repo = spack.repo.Repo(mock_packages_path)
filename = repo.filename_for_package_name('mpich')
assert filename == join_path(
mock_packages_path,
@ -54,7 +53,7 @@ def test_package_filename(self):
)
def test_nonexisting_package_filename(self):
repo = Repo(mock_packages_path)
repo = spack.repo.Repo(mock_packages_path)
filename = repo.filename_for_package_name('some-nonexisting-package')
assert filename == join_path(
mock_packages_path,

View file

@ -34,7 +34,7 @@
from llnl.util.filesystem import mkdirp
import spack
import spack.repo
import spack.store
import spack.binary_distribution as bindist
import spack.cmd.buildcache as buildcache

View file

@ -39,7 +39,7 @@
"""
from six import StringIO
import spack
import spack.repo
from spack.provider_index import ProviderIndex
from spack.spec import Spec

View file

@ -24,7 +24,7 @@
##############################################################################
import pytest
import spack.repository
import spack.repo
import spack.paths
@ -33,7 +33,7 @@
# given RepoPath
@pytest.fixture()
def repo_for_test():
return spack.repository.RepoPath(spack.paths.mock_packages_path)
return spack.repo.RepoPath(spack.paths.mock_packages_path)
@pytest.fixture()
@ -47,7 +47,7 @@ def extra_repo(tmpdir_factory):
repo:
namespace: extra_test_repo
""")
return spack.repository.Repo(str(repo_dir))
return spack.repo.Repo(str(repo_dir))
def test_repo_getpkg(repo_for_test):
@ -68,10 +68,10 @@ def test_repo_multi_getpkgclass(repo_for_test, extra_repo):
def test_repo_pkg_with_unknown_namespace(repo_for_test):
with pytest.raises(spack.repository.UnknownNamespaceError):
with pytest.raises(spack.repo.UnknownNamespaceError):
repo_for_test.get('unknown.a')
def test_repo_unknown_pkg(repo_for_test):
with pytest.raises(spack.repository.UnknownPackageError):
with pytest.raises(spack.repo.UnknownPackageError):
repo_for_test.get('builtin.mock.nonexistentpackage')

View file

@ -86,8 +86,6 @@ def test_test_deptype():
w->y deptypes are (link, build), w->x and y->z deptypes are (test)
"""
saved_repo = spack.repo
default = ('build', 'link')
test_only = ('test',)
@ -97,15 +95,12 @@ def test_test_deptype():
w = MockPackage('w', [x, y], [test_only, default])
mock_repo = MockPackageMultiRepo([w, x, y, z])
try:
spack.repo = mock_repo
with spack.repo.swap(mock_repo):
spec = Spec('w')
spec.concretize(tests=(w.name,))
assert ('x' in spec)
assert ('z' not in spec)
finally:
spack.repo = saved_repo
@pytest.mark.usefixtures('mutable_mock_packages')

View file

@ -28,7 +28,7 @@
from llnl.util.filesystem import join_path, touch, working_dir
import spack
import spack.repo
import spack.config
from spack.spec import Spec
from spack.version import ver

View file

@ -27,7 +27,7 @@
from llnl.util.filesystem import working_dir, is_exe
import spack
import spack.repo
import spack.config
from spack.fetch_strategy import from_list_url, URLFetchStrategy
from spack.spec import Spec

View file

@ -22,7 +22,7 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
import spack
import spack.repo
from spack import directives
from spack.error import SpackError
from spack.spec import Spec
@ -131,7 +131,7 @@ def package_hash(spec, content=None):
def package_ast(spec):
spec = Spec(spec)
filename = spack.repo.filename_for_package_name(spec.name)
filename = spack.repo.path().filename_for_package_name(spec.name)
with open(filename) as f:
text = f.read()
root = ast.parse(text)