From 5ef30e0a51abf8886e28a8561998c09aa89e8083 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 17 May 2018 11:43:23 -0700 Subject: make check_for_compiler_existence an instance variable --- lib/spack/spack/cmd/mirror.py | 2 +- lib/spack/spack/concretize.py | 30 ++++++++++++++---------------- lib/spack/spack/test/concretize.py | 2 +- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/spack/spack/cmd/mirror.py b/lib/spack/spack/cmd/mirror.py index 42703fd232..9780611227 100644 --- a/lib/spack/spack/cmd/mirror.py +++ b/lib/spack/spack/cmd/mirror.py @@ -169,7 +169,7 @@ 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. - with spack.concretize.disable_compiler_existence_check(): + with spack.concretize.concretizer.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. diff --git a/lib/spack/spack/concretize.py b/lib/spack/spack/concretize.py index 2f57cb7504..58aca31a1f 100644 --- a/lib/spack/spack/concretize.py +++ b/lib/spack/spack/concretize.py @@ -50,10 +50,6 @@ import spack.error 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 = llnl.util.lang.Singleton(lambda: Concretizer()) @@ -63,19 +59,21 @@ concretizer = llnl.util.lang.Singleton(lambda: Concretizer()) _abi = llnl.util.lang.Singleton(lambda: spack.abi.ABI()) -@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): + # controls whether we check that compiler versions actually exist + # during concretization. Used for testing and for mirror creation + self.check_for_compiler_existence = True + + @contextmanager + def disable_compiler_existence_check(self): + saved = self.check_for_compiler_existence + self.check_for_compiler_existence = False + yield + self.check_for_compiler_existence = saved def _valid_virtuals_and_externals(self, spec): """Returns a list of candidate virtual dep providers and external @@ -311,7 +309,7 @@ class Concretizer(object): return spack.compilers.compilers_for_spec(cspec, arch_spec=aspec) if spec.compiler and spec.compiler.concrete: - if (check_for_compiler_existence and not + if (self.check_for_compiler_existence and not _proper_compiler_style(spec.compiler, spec.architecture)): _compiler_concretization_failure( spec.compiler, spec.architecture) @@ -325,7 +323,7 @@ class Concretizer(object): # Check if the compiler is already fully specified if (other_compiler and other_compiler.concrete and - not check_for_compiler_existence): + not self.check_for_compiler_existence): spec.compiler = other_compiler.copy() return True @@ -419,7 +417,7 @@ class Concretizer(object): compiler = spack.compilers.compiler_for_spec( spec.compiler, spec.architecture) except spack.compilers.NoCompilerForSpecError: - if check_for_compiler_existence: + if self.check_for_compiler_existence: raise return ret for flag in compiler.flags: diff --git a/lib/spack/spack/test/concretize.py b/lib/spack/spack/test/concretize.py index 028bc23583..a90b355d84 100644 --- a/lib/spack/spack/test/concretize.py +++ b/lib/spack/spack/test/concretize.py @@ -153,7 +153,7 @@ class TestConcretize(object): with pytest.raises(spack.concretize.UnavailableCompilerVersionError): check_concretize('dttop %gcc@100.100') - with spack.concretize.disable_compiler_existence_check(): + with spack.concretize.concretizer.disable_compiler_existence_check(): spec = check_concretize('dttop %gcc@100.100') assert spec.satisfies('%gcc@100.100') assert spec['dtlink3'].satisfies('%gcc@100.100') -- cgit v1.2.3-60-g2f50