init: remove spack.concretizer global variable

This commit is contained in:
Todd Gamblin 2018-04-26 14:00:46 -07:00 committed by scheibelp
parent d4709673b5
commit 3e6d85c404
5 changed files with 97 additions and 75 deletions

View File

@ -62,11 +62,6 @@
tty.die('while initializing Spack RepoPath:', e.message)
#: Concretizer class implements policy decisions for concretization
from spack.concretize import Concretizer
concretizer = Concretizer()
#: Needed for test dependencies
from spack.package_prefs import PackageTesting
package_testing = PackageTesting()

View File

@ -31,6 +31,7 @@
import spack
import spack.cmd
import spack.concretize
import spack.config
import spack.mirror
import spack.cmd.common.arguments as arguments
@ -168,57 +169,57 @@ def mirror_create(args):
"""Create a directory to be used as a spack mirror, and fill it with
package archives."""
# try to parse specs from the command line first.
spack.concretizer.disable_compiler_existence_check()
specs = spack.cmd.parse_specs(args.specs, concretize=True)
with spack.concretize.disable_compiler_existence_check():
specs = spack.cmd.parse_specs(args.specs, concretize=True)
# If there is a file, parse each line as a spec and add it to the list.
if args.file:
if specs:
tty.die("Cannot pass specs on the command line with --file.")
specs = _read_specs_from_file(args.file)
# If there is a file, parse each line as a spec and add it to the list.
if args.file:
if specs:
tty.die("Cannot pass specs on the command line with --file.")
specs = _read_specs_from_file(args.file)
# If nothing is passed, use all packages.
if not specs:
specs = [Spec(n) for n in spack.repo.all_package_names()]
specs.sort(key=lambda s: s.format("$_$@").lower())
# If nothing is passed, use all packages.
if not specs:
specs = [Spec(n) for n in spack.repo.all_package_names()]
specs.sort(key=lambda s: s.format("$_$@").lower())
# If the user asked for dependencies, traverse spec DAG get them.
if args.dependencies:
new_specs = set()
for spec in specs:
spec.concretize()
for s in spec.traverse():
new_specs.add(s)
specs = list(new_specs)
# If the user asked for dependencies, traverse spec DAG get them.
if args.dependencies:
new_specs = set()
for spec in specs:
spec.concretize()
for s in spec.traverse():
new_specs.add(s)
specs = list(new_specs)
# Default name for directory is spack-mirror-<DATESTAMP>
directory = args.directory
if not directory:
timestamp = datetime.now().strftime("%Y-%m-%d")
directory = 'spack-mirror-' + timestamp
# Default name for directory is spack-mirror-<DATESTAMP>
directory = args.directory
if not directory:
timestamp = datetime.now().strftime("%Y-%m-%d")
directory = 'spack-mirror-' + timestamp
# Make sure nothing is in the way.
existed = False
if os.path.isfile(directory):
tty.error("%s already exists and is a file." % directory)
elif os.path.isdir(directory):
existed = True
# Make sure nothing is in the way.
existed = False
if os.path.isfile(directory):
tty.error("%s already exists and is a file." % directory)
elif os.path.isdir(directory):
existed = True
# Actually do the work to create the mirror
present, mirrored, error = spack.mirror.create(
directory, specs, num_versions=args.one_version_per_spec)
p, m, e = len(present), len(mirrored), len(error)
# Actually do the work to create the mirror
present, mirrored, error = spack.mirror.create(
directory, specs, num_versions=args.one_version_per_spec)
p, m, e = len(present), len(mirrored), len(error)
verb = "updated" if existed else "created"
tty.msg(
"Successfully %s mirror in %s" % (verb, directory),
"Archive stats:",
" %-4d already present" % p,
" %-4d added" % m,
" %-4d failed to fetch." % e)
if error:
tty.error("Failed downloads:")
colify(s.cformat("$_$@") for s in error)
verb = "updated" if existed else "created"
tty.msg(
"Successfully %s mirror in %s" % (verb, directory),
"Archive stats:",
" %-4d already present" % p,
" %-4d added" % m,
" %-4d failed to fetch." % e)
if error:
tty.error("Failed downloads:")
colify(s.cformat("$_$@") for s in error)
def mirror(parser, args):

View File

@ -36,6 +36,7 @@
from __future__ import print_function
from itertools import chain
from functools_backport import reverse_order
from contextlib import contextmanager
from six import iteritems
import spack
@ -47,23 +48,48 @@
from spack.version import ver, Version, VersionList, VersionRange
from spack.package_prefs import PackagePrefs, spec_externals, is_spec_buildable
#: controls whether we check that compiler versions actually exist during
#: concretization. Used for testing.
check_for_compiler_existence = True
#: Concretizer singleton
_concretizer = None
#: impements rudimentary logic for ABI compatibility
abi = spack.abi.ABI()
_abi_checker = None
def _abi():
"""Get an ABI checker object."""
global _abi_checker
if _abi_checker is None:
_abi_checker = spack.abi.ABI()
return _abi_checker
def concretizer():
"""Get concretizer singleton."""
global _concretizer
if _concretizer is None:
_concretizer = Concretizer()
return _concretizer
@contextmanager
def disable_compiler_existence_check():
global check_for_compiler_existence
saved = check_for_compiler_existence
check_for_compiler_existence = False
yield
check_for_compiler_existence = saved
class Concretizer(object):
"""You can subclass this class to override some of the default
concretization strategies, or you can override all of them.
"""
def __init__(self):
self.check_for_compiler_existence = True
def disable_compiler_existence_check(self):
self.check_for_compiler_existence = False
def enable_compiler_existence_check(self):
self.check_for_compiler_existence = True
def _valid_virtuals_and_externals(self, spec):
"""Returns a list of candidate virtual dep providers and external
@ -137,8 +163,8 @@ def choose_virtual_or_external(self, spec):
return sorted(candidates,
reverse=True,
key=lambda spec: (
abi.compatible(spec, abi_exemplar, loose=True),
abi.compatible(spec, abi_exemplar)))
_abi().compatible(spec, abi_exemplar, loose=True),
_abi().compatible(spec, abi_exemplar)))
def concretize_version(self, spec):
"""If the spec is already concrete, return. Otherwise take
@ -299,7 +325,7 @@ def _proper_compiler_style(cspec, aspec):
return spack.compilers.compilers_for_spec(cspec, arch_spec=aspec)
if spec.compiler and spec.compiler.concrete:
if (self.check_for_compiler_existence and not
if (check_for_compiler_existence and not
_proper_compiler_style(spec.compiler, spec.architecture)):
_compiler_concretization_failure(
spec.compiler, spec.architecture)
@ -313,7 +339,7 @@ def _proper_compiler_style(cspec, aspec):
# Check if the compiler is already fully specified
if (other_compiler and other_compiler.concrete and
not self.check_for_compiler_existence):
not check_for_compiler_existence):
spec.compiler = other_compiler.copy()
return True
@ -407,7 +433,7 @@ def concretize_compiler_flags(self, spec):
compiler = spack.compilers.compiler_for_spec(
spec.compiler, spec.architecture)
except spack.compilers.NoCompilerForSpecError:
if self.check_for_compiler_existence:
if check_for_compiler_existence:
raise
return ret
for flag in compiler.flags:

View File

@ -1675,13 +1675,15 @@ def _concretize_helper(self, presets=None, visited=None):
# to presets below, their constraints will all be merged, but we'll
# still need to select a concrete package later.
if not self.virtual:
import spack.concretize
concretizer = spack.concretize.concretizer()
changed |= any(
(spack.concretizer.concretize_architecture(self),
spack.concretizer.concretize_compiler(self),
spack.concretizer.concretize_compiler_flags(
self), # has to be concretized after compiler
spack.concretizer.concretize_version(self),
spack.concretizer.concretize_variants(self)))
(concretizer.concretize_architecture(self),
concretizer.concretize_compiler(self),
# flags must be concretized after compiler
concretizer.concretize_compiler_flags(self),
concretizer.concretize_version(self),
concretizer.concretize_variants(self)))
presets[self.name] = self
visited.add(self.name)
@ -1742,8 +1744,9 @@ def _expand_virtual_packages(self):
if not replacement:
# Get a list of possible replacements in order of
# preference.
candidates = spack.concretizer.choose_virtual_or_external(
spec)
import spack.concretize
concretizer = spack.concretize.concretizer()
candidates = concretizer.choose_virtual_or_external(spec)
# Try the replacements in order, skipping any that cause
# satisfiability problems.

View File

@ -152,13 +152,10 @@ def test_concretize_disable_compiler_existence_check(self):
with pytest.raises(spack.concretize.UnavailableCompilerVersionError):
check_concretize('dttop %gcc@100.100')
try:
spack.concretizer.disable_compiler_existence_check()
with spack.concretize.disable_compiler_existence_check():
spec = check_concretize('dttop %gcc@100.100')
assert spec.satisfies('%gcc@100.100')
assert spec['dtlink3'].satisfies('%gcc@100.100')
finally:
spack.concretizer.enable_compiler_existence_check()
def test_concretize_with_provides_when(self):
"""Make sure insufficient versions of MPI are not in providers list when