init: remove spack.concretizer global variable
This commit is contained in:
parent
d4709673b5
commit
3e6d85c404
@ -62,11 +62,6 @@
|
|||||||
tty.die('while initializing Spack RepoPath:', e.message)
|
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
|
#: Needed for test dependencies
|
||||||
from spack.package_prefs import PackageTesting
|
from spack.package_prefs import PackageTesting
|
||||||
package_testing = PackageTesting()
|
package_testing = PackageTesting()
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
import spack
|
import spack
|
||||||
import spack.cmd
|
import spack.cmd
|
||||||
|
import spack.concretize
|
||||||
import spack.config
|
import spack.config
|
||||||
import spack.mirror
|
import spack.mirror
|
||||||
import spack.cmd.common.arguments as arguments
|
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
|
"""Create a directory to be used as a spack mirror, and fill it with
|
||||||
package archives."""
|
package archives."""
|
||||||
# try to parse specs from the command line first.
|
# try to parse specs from the command line first.
|
||||||
spack.concretizer.disable_compiler_existence_check()
|
with spack.concretize.disable_compiler_existence_check():
|
||||||
specs = spack.cmd.parse_specs(args.specs, concretize=True)
|
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 there is a file, parse each line as a spec and add it to the list.
|
||||||
if args.file:
|
if args.file:
|
||||||
if specs:
|
if specs:
|
||||||
tty.die("Cannot pass specs on the command line with --file.")
|
tty.die("Cannot pass specs on the command line with --file.")
|
||||||
specs = _read_specs_from_file(args.file)
|
specs = _read_specs_from_file(args.file)
|
||||||
|
|
||||||
# If nothing is passed, use all packages.
|
# If nothing is passed, use all packages.
|
||||||
if not specs:
|
if not specs:
|
||||||
specs = [Spec(n) for n in spack.repo.all_package_names()]
|
specs = [Spec(n) for n in spack.repo.all_package_names()]
|
||||||
specs.sort(key=lambda s: s.format("$_$@").lower())
|
specs.sort(key=lambda s: s.format("$_$@").lower())
|
||||||
|
|
||||||
# If the user asked for dependencies, traverse spec DAG get them.
|
# If the user asked for dependencies, traverse spec DAG get them.
|
||||||
if args.dependencies:
|
if args.dependencies:
|
||||||
new_specs = set()
|
new_specs = set()
|
||||||
for spec in specs:
|
for spec in specs:
|
||||||
spec.concretize()
|
spec.concretize()
|
||||||
for s in spec.traverse():
|
for s in spec.traverse():
|
||||||
new_specs.add(s)
|
new_specs.add(s)
|
||||||
specs = list(new_specs)
|
specs = list(new_specs)
|
||||||
|
|
||||||
# Default name for directory is spack-mirror-<DATESTAMP>
|
# Default name for directory is spack-mirror-<DATESTAMP>
|
||||||
directory = args.directory
|
directory = args.directory
|
||||||
if not directory:
|
if not directory:
|
||||||
timestamp = datetime.now().strftime("%Y-%m-%d")
|
timestamp = datetime.now().strftime("%Y-%m-%d")
|
||||||
directory = 'spack-mirror-' + timestamp
|
directory = 'spack-mirror-' + timestamp
|
||||||
|
|
||||||
# Make sure nothing is in the way.
|
# Make sure nothing is in the way.
|
||||||
existed = False
|
existed = False
|
||||||
if os.path.isfile(directory):
|
if os.path.isfile(directory):
|
||||||
tty.error("%s already exists and is a file." % directory)
|
tty.error("%s already exists and is a file." % directory)
|
||||||
elif os.path.isdir(directory):
|
elif os.path.isdir(directory):
|
||||||
existed = True
|
existed = True
|
||||||
|
|
||||||
# Actually do the work to create the mirror
|
# Actually do the work to create the mirror
|
||||||
present, mirrored, error = spack.mirror.create(
|
present, mirrored, error = spack.mirror.create(
|
||||||
directory, specs, num_versions=args.one_version_per_spec)
|
directory, specs, num_versions=args.one_version_per_spec)
|
||||||
p, m, e = len(present), len(mirrored), len(error)
|
p, m, e = len(present), len(mirrored), len(error)
|
||||||
|
|
||||||
verb = "updated" if existed else "created"
|
verb = "updated" if existed else "created"
|
||||||
tty.msg(
|
tty.msg(
|
||||||
"Successfully %s mirror in %s" % (verb, directory),
|
"Successfully %s mirror in %s" % (verb, directory),
|
||||||
"Archive stats:",
|
"Archive stats:",
|
||||||
" %-4d already present" % p,
|
" %-4d already present" % p,
|
||||||
" %-4d added" % m,
|
" %-4d added" % m,
|
||||||
" %-4d failed to fetch." % e)
|
" %-4d failed to fetch." % e)
|
||||||
if error:
|
if error:
|
||||||
tty.error("Failed downloads:")
|
tty.error("Failed downloads:")
|
||||||
colify(s.cformat("$_$@") for s in error)
|
colify(s.cformat("$_$@") for s in error)
|
||||||
|
|
||||||
|
|
||||||
def mirror(parser, args):
|
def mirror(parser, args):
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from functools_backport import reverse_order
|
from functools_backport import reverse_order
|
||||||
|
from contextlib import contextmanager
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
|
||||||
import spack
|
import spack
|
||||||
@ -47,23 +48,48 @@
|
|||||||
from spack.version import ver, Version, VersionList, VersionRange
|
from spack.version import ver, Version, VersionList, VersionRange
|
||||||
from spack.package_prefs import PackagePrefs, spec_externals, is_spec_buildable
|
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
|
#: 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):
|
class Concretizer(object):
|
||||||
"""You can subclass this class to override some of the default
|
"""You can subclass this class to override some of the default
|
||||||
concretization strategies, or you can override all of them.
|
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):
|
def _valid_virtuals_and_externals(self, spec):
|
||||||
"""Returns a list of candidate virtual dep providers and external
|
"""Returns a list of candidate virtual dep providers and external
|
||||||
@ -137,8 +163,8 @@ def choose_virtual_or_external(self, spec):
|
|||||||
return sorted(candidates,
|
return sorted(candidates,
|
||||||
reverse=True,
|
reverse=True,
|
||||||
key=lambda spec: (
|
key=lambda spec: (
|
||||||
abi.compatible(spec, abi_exemplar, loose=True),
|
_abi().compatible(spec, abi_exemplar, loose=True),
|
||||||
abi.compatible(spec, abi_exemplar)))
|
_abi().compatible(spec, abi_exemplar)))
|
||||||
|
|
||||||
def concretize_version(self, spec):
|
def concretize_version(self, spec):
|
||||||
"""If the spec is already concrete, return. Otherwise take
|
"""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)
|
return spack.compilers.compilers_for_spec(cspec, arch_spec=aspec)
|
||||||
|
|
||||||
if spec.compiler and spec.compiler.concrete:
|
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)):
|
_proper_compiler_style(spec.compiler, spec.architecture)):
|
||||||
_compiler_concretization_failure(
|
_compiler_concretization_failure(
|
||||||
spec.compiler, spec.architecture)
|
spec.compiler, spec.architecture)
|
||||||
@ -313,7 +339,7 @@ def _proper_compiler_style(cspec, aspec):
|
|||||||
|
|
||||||
# Check if the compiler is already fully specified
|
# Check if the compiler is already fully specified
|
||||||
if (other_compiler and other_compiler.concrete and
|
if (other_compiler and other_compiler.concrete and
|
||||||
not self.check_for_compiler_existence):
|
not check_for_compiler_existence):
|
||||||
spec.compiler = other_compiler.copy()
|
spec.compiler = other_compiler.copy()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -407,7 +433,7 @@ def concretize_compiler_flags(self, spec):
|
|||||||
compiler = spack.compilers.compiler_for_spec(
|
compiler = spack.compilers.compiler_for_spec(
|
||||||
spec.compiler, spec.architecture)
|
spec.compiler, spec.architecture)
|
||||||
except spack.compilers.NoCompilerForSpecError:
|
except spack.compilers.NoCompilerForSpecError:
|
||||||
if self.check_for_compiler_existence:
|
if check_for_compiler_existence:
|
||||||
raise
|
raise
|
||||||
return ret
|
return ret
|
||||||
for flag in compiler.flags:
|
for flag in compiler.flags:
|
||||||
|
@ -1675,13 +1675,15 @@ def _concretize_helper(self, presets=None, visited=None):
|
|||||||
# to presets below, their constraints will all be merged, but we'll
|
# to presets below, their constraints will all be merged, but we'll
|
||||||
# still need to select a concrete package later.
|
# still need to select a concrete package later.
|
||||||
if not self.virtual:
|
if not self.virtual:
|
||||||
|
import spack.concretize
|
||||||
|
concretizer = spack.concretize.concretizer()
|
||||||
changed |= any(
|
changed |= any(
|
||||||
(spack.concretizer.concretize_architecture(self),
|
(concretizer.concretize_architecture(self),
|
||||||
spack.concretizer.concretize_compiler(self),
|
concretizer.concretize_compiler(self),
|
||||||
spack.concretizer.concretize_compiler_flags(
|
# flags must be concretized after compiler
|
||||||
self), # has to be concretized after compiler
|
concretizer.concretize_compiler_flags(self),
|
||||||
spack.concretizer.concretize_version(self),
|
concretizer.concretize_version(self),
|
||||||
spack.concretizer.concretize_variants(self)))
|
concretizer.concretize_variants(self)))
|
||||||
presets[self.name] = self
|
presets[self.name] = self
|
||||||
|
|
||||||
visited.add(self.name)
|
visited.add(self.name)
|
||||||
@ -1742,8 +1744,9 @@ def _expand_virtual_packages(self):
|
|||||||
if not replacement:
|
if not replacement:
|
||||||
# Get a list of possible replacements in order of
|
# Get a list of possible replacements in order of
|
||||||
# preference.
|
# preference.
|
||||||
candidates = spack.concretizer.choose_virtual_or_external(
|
import spack.concretize
|
||||||
spec)
|
concretizer = spack.concretize.concretizer()
|
||||||
|
candidates = concretizer.choose_virtual_or_external(spec)
|
||||||
|
|
||||||
# Try the replacements in order, skipping any that cause
|
# Try the replacements in order, skipping any that cause
|
||||||
# satisfiability problems.
|
# satisfiability problems.
|
||||||
|
@ -152,13 +152,10 @@ def test_concretize_disable_compiler_existence_check(self):
|
|||||||
with pytest.raises(spack.concretize.UnavailableCompilerVersionError):
|
with pytest.raises(spack.concretize.UnavailableCompilerVersionError):
|
||||||
check_concretize('dttop %gcc@100.100')
|
check_concretize('dttop %gcc@100.100')
|
||||||
|
|
||||||
try:
|
with spack.concretize.disable_compiler_existence_check():
|
||||||
spack.concretizer.disable_compiler_existence_check()
|
|
||||||
spec = check_concretize('dttop %gcc@100.100')
|
spec = check_concretize('dttop %gcc@100.100')
|
||||||
assert spec.satisfies('%gcc@100.100')
|
assert spec.satisfies('%gcc@100.100')
|
||||||
assert spec['dtlink3'].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):
|
def test_concretize_with_provides_when(self):
|
||||||
"""Make sure insufficient versions of MPI are not in providers list when
|
"""Make sure insufficient versions of MPI are not in providers list when
|
||||||
|
Loading…
Reference in New Issue
Block a user