imports: move conditional
to directives.py
`conditional()`, which defines conditional variant values, and the other ways to declare variant values should probably be in a layer above `spack.variant`. This does the simple thing and moves *just* `conditional()` to `spack.directives` to avoid a circular import. We can revisit the public variant interface later, when we split packages from core. Co-authored-by: Harmen Stoppels <me@harmenstoppels.nl> Signed-off-by: Todd Gamblin <tgamblin@llnl.gov>
This commit is contained in:
parent
a9e6074996
commit
6961514122
@ -64,6 +64,7 @@ class OpenMpi(Package):
|
||||
"DirectiveMeta",
|
||||
"DisableRedistribute",
|
||||
"version",
|
||||
"conditional",
|
||||
"conflicts",
|
||||
"depends_on",
|
||||
"extends",
|
||||
@ -577,6 +578,15 @@ def _execute_patch(pkg_or_dep: Union["spack.package_base.PackageBase", Dependenc
|
||||
return _execute_patch
|
||||
|
||||
|
||||
def conditional(*values: List[Any], when: Optional[WhenType] = None):
|
||||
"""Conditional values that can be used in variant declarations."""
|
||||
# _make_when_spec returns None when the condition is statically false.
|
||||
when = _make_when_spec(when)
|
||||
return spack.variant.ConditionalVariantValues(
|
||||
spack.variant.Value(x, when=when) for x in values
|
||||
)
|
||||
|
||||
|
||||
@directive("variants")
|
||||
def variant(
|
||||
name: str,
|
||||
|
@ -103,12 +103,7 @@
|
||||
from spack.spec import InvalidSpecDetected, Spec
|
||||
from spack.util.executable import *
|
||||
from spack.util.filesystem import file_command, fix_darwin_install_name, mime_type
|
||||
from spack.variant import (
|
||||
any_combination_of,
|
||||
auto_or_any_combination_of,
|
||||
conditional,
|
||||
disjoint_sets,
|
||||
)
|
||||
from spack.variant import any_combination_of, auto_or_any_combination_of, disjoint_sets
|
||||
from spack.version import Version, ver
|
||||
|
||||
# These are just here for editor support; they will be replaced when the build env
|
||||
|
@ -266,7 +266,7 @@ def _flatten(values) -> Collection:
|
||||
|
||||
flattened: List = []
|
||||
for item in values:
|
||||
if isinstance(item, _ConditionalVariantValues):
|
||||
if isinstance(item, ConditionalVariantValues):
|
||||
flattened.extend(item)
|
||||
else:
|
||||
flattened.append(item)
|
||||
@ -884,17 +884,10 @@ def prevalidate_variant_value(
|
||||
)
|
||||
|
||||
|
||||
class _ConditionalVariantValues(lang.TypedMutableSequence):
|
||||
class ConditionalVariantValues(lang.TypedMutableSequence):
|
||||
"""A list, just with a different type"""
|
||||
|
||||
|
||||
def conditional(*values: List[Any], when: Optional["spack.directives.WhenType"] = None):
|
||||
"""Conditional values that can be used in variant declarations."""
|
||||
# _make_when_spec returns None when the condition is statically false.
|
||||
when = spack.directives._make_when_spec(when)
|
||||
return _ConditionalVariantValues([Value(x, when=when) for x in values])
|
||||
|
||||
|
||||
class DuplicateVariantError(error.SpecError):
|
||||
"""Raised when the same variant occurs in a spec twice."""
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
|
||||
from spack.package import *
|
||||
from spack.variant import _ConditionalVariantValues
|
||||
from spack.variant import ConditionalVariantValues
|
||||
|
||||
|
||||
class Geant4(CMakePackage):
|
||||
@ -180,7 +180,7 @@ class Geant4(CMakePackage):
|
||||
|
||||
def std_when(values):
|
||||
for v in values:
|
||||
if isinstance(v, _ConditionalVariantValues):
|
||||
if isinstance(v, ConditionalVariantValues):
|
||||
for c in v:
|
||||
yield (c.value, c.when)
|
||||
else:
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
from spack.package import *
|
||||
from spack.variant import _ConditionalVariantValues
|
||||
from spack.variant import ConditionalVariantValues
|
||||
|
||||
|
||||
class Vecgeom(CMakePackage, CudaPackage):
|
||||
@ -196,7 +196,7 @@ class Vecgeom(CMakePackage, CudaPackage):
|
||||
|
||||
def std_when(values):
|
||||
for v in values:
|
||||
if isinstance(v, _ConditionalVariantValues):
|
||||
if isinstance(v, ConditionalVariantValues):
|
||||
for c in v:
|
||||
yield (c.value, c.when)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user