Add audit check to spot when= arguments using wrong named specs (#41107)

* Add audit check to spot when= arguments using named specs

* Fix package issues caught by the new audit
This commit is contained in:
Massimiliano Culpo 2023-11-16 14:19:05 +01:00
parent b49022822d
commit d5ef4f8c83
9 changed files with 71 additions and 24 deletions

View file

@ -776,7 +776,7 @@ def _version_constraints_are_satisfiable_by_some_version_in_repo(pkgs, error_cls
) )
except Exception: except Exception:
summary = ( summary = (
"{0}: dependency on {1} cannot be satisfied " "by known versions of {1.name}" "{0}: dependency on {1} cannot be satisfied by known versions of {1.name}"
).format(pkg_name, s) ).format(pkg_name, s)
details = ["happening in " + filename] details = ["happening in " + filename]
if dependency_pkg_cls is not None: if dependency_pkg_cls is not None:
@ -818,6 +818,53 @@ def _analyze_variants_in_directive(pkg, constraint, directive, error_cls):
return errors return errors
@package_directives
def _named_specs_in_when_arguments(pkgs, error_cls):
"""Reports named specs in the 'when=' attribute of a directive.
Note that 'conflicts' is the only directive allowing that.
"""
errors = []
for pkg_name in pkgs:
pkg_cls = spack.repo.PATH.get_pkg_class(pkg_name)
def _extracts_errors(triggers, summary):
_errors = []
for trigger in list(triggers):
when_spec = spack.spec.Spec(trigger)
if when_spec.name is not None and when_spec.name != pkg_name:
details = [f"using '{trigger}', should be '^{trigger}'"]
_errors.append(error_cls(summary=summary, details=details))
return _errors
for dname, triggers in pkg_cls.dependencies.items():
summary = f"{pkg_name}: wrong 'when=' condition for the '{dname}' dependency"
errors.extend(_extracts_errors(triggers, summary))
for vname, (variant, triggers) in pkg_cls.variants.items():
summary = f"{pkg_name}: wrong 'when=' condition for the '{vname}' variant"
errors.extend(_extracts_errors(triggers, summary))
for provided, triggers in pkg_cls.provided.items():
summary = f"{pkg_name}: wrong 'when=' condition for the '{provided}' virtual"
errors.extend(_extracts_errors(triggers, summary))
for _, triggers in pkg_cls.requirements.items():
triggers = [when_spec for when_spec, _, _ in triggers]
summary = f"{pkg_name}: wrong 'when=' condition in 'requires' directive"
errors.extend(_extracts_errors(triggers, summary))
triggers = list(pkg_cls.patches)
summary = f"{pkg_name}: wrong 'when=' condition in 'patch' directives"
errors.extend(_extracts_errors(triggers, summary))
triggers = list(pkg_cls.resources)
summary = f"{pkg_name}: wrong 'when=' condition in 'resource' directives"
errors.extend(_extracts_errors(triggers, summary))
return llnl.util.lang.dedupe(errors)
#: Sanity checks on package directives #: Sanity checks on package directives
external_detection = AuditClass( external_detection = AuditClass(
group="externals", group="externals",

View file

@ -18,7 +18,7 @@ class Cpr(CMakePackage):
version("1.9.2", sha256="3bfbffb22c51f322780d10d3ca8f79424190d7ac4b5ad6ad896de08dbd06bf31") version("1.9.2", sha256="3bfbffb22c51f322780d10d3ca8f79424190d7ac4b5ad6ad896de08dbd06bf31")
depends_on("curl") depends_on("curl")
depends_on("git", when="build") depends_on("git", type="build")
def cmake_args(self): def cmake_args(self):
_force = "_FORCE" if self.spec.satisfies("@:1.9") else "" _force = "_FORCE" if self.spec.satisfies("@:1.9") else ""

View file

@ -45,21 +45,21 @@ class Interproscan(Package):
) )
resource( resource(
when="5.56-89.0 +databases", when="@5.56-89.0 +databases",
name="databases", name="databases",
url="https://ftp.ebi.ac.uk/pub/databases/interpro/iprscan/5/5.56-89.0/alt/interproscan-data-5.56-89.0.tar.gz", url="https://ftp.ebi.ac.uk/pub/databases/interpro/iprscan/5/5.56-89.0/alt/interproscan-data-5.56-89.0.tar.gz",
sha256="49cd0c69711f9469f3b68857f4581b23ff12765ca2b12893d18e5a9a5cd8032d", sha256="49cd0c69711f9469f3b68857f4581b23ff12765ca2b12893d18e5a9a5cd8032d",
) )
resource( resource(
when="5.38-76.0 +databases", when="@5.38-76.0 +databases",
name="databases", name="databases",
url="https://ftp.ebi.ac.uk/pub/databases/interpro/iprscan/5/5.38-76.0/alt/interproscan-data-5.38-76.0.tar.gz", url="https://ftp.ebi.ac.uk/pub/databases/interpro/iprscan/5/5.38-76.0/alt/interproscan-data-5.38-76.0.tar.gz",
sha256="e05e15d701037504f92ecf849c20317e70df28e78ff1945826b3c1e16d9b9cce", sha256="e05e15d701037504f92ecf849c20317e70df28e78ff1945826b3c1e16d9b9cce",
) )
resource( resource(
when="5.36-75.0 +databases", when="@5.36-75.0 +databases",
name="databases", name="databases",
url="https://ftp.ebi.ac.uk/pub/databases/interpro/iprscan/5/5.36-75.0/alt/interproscan-data-5.36-75.0.tar.gz", url="https://ftp.ebi.ac.uk/pub/databases/interpro/iprscan/5/5.36-75.0/alt/interproscan-data-5.36-75.0.tar.gz",
sha256="e9b1e6f2d1c20d06661a31a08c973bc8ddf039a4cf1e45ec4443200375e5d6a4", sha256="e9b1e6f2d1c20d06661a31a08c973bc8ddf039a4cf1e45ec4443200375e5d6a4",

View file

@ -314,7 +314,7 @@ class Lbann(CachedCMakePackage, CudaPackage, ROCmPackage):
depends_on("py-protobuf+cpp@3.10.0:", type=("build", "run"), when="@:0.90,0.99: +pfe") depends_on("py-protobuf+cpp@3.10.0:", type=("build", "run"), when="@:0.90,0.99: +pfe")
depends_on("protobuf+shared@3.10.0:", when="@:0.90,0.99:") depends_on("protobuf+shared@3.10.0:", when="@:0.90,0.99:")
depends_on("zlib-api", when="protobuf@3.11.0:") depends_on("zlib-api", when="^protobuf@3.11.0:")
# using cereal@1.3.1 and above requires changing the # using cereal@1.3.1 and above requires changing the
# find_package call to lowercase, so stick with :1.3.0 # find_package call to lowercase, so stick with :1.3.0

View file

@ -17,7 +17,7 @@ class PyAbipy(PythonPackage):
version("0.2.0", sha256="c72b796ba0f9ea4299eac3085bede092d2652e9e5e8074d3badd19ef7b600792") version("0.2.0", sha256="c72b796ba0f9ea4299eac3085bede092d2652e9e5e8074d3badd19ef7b600792")
variant("gui", default=False, description="Build the GUI") variant("gui", default=False, description="Build the GUI")
variant("ipython", default=False, when="0.2.0", description="Build IPython support") variant("ipython", default=False, when="@0.2.0", description="Build IPython support")
depends_on("py-setuptools", type="build") depends_on("py-setuptools", type="build")
# in newer pip versions --install-option does not exist # in newer pip versions --install-option does not exist

View file

@ -32,7 +32,7 @@ class PyKombu(PythonPackage):
depends_on("py-amqp@5.0.0:5", when="@5.0.0:5.0.2", type=("build", "run")) depends_on("py-amqp@5.0.0:5", when="@5.0.0:5.0.2", type=("build", "run"))
depends_on("py-amqp@5.0.9:5.0", when="@5.2.3", type=("build", "run")) depends_on("py-amqp@5.0.9:5.0", when="@5.2.3", type=("build", "run"))
depends_on("py-vine", when="@5.1.0:", type=("build", "run")) depends_on("py-vine", when="@5.1.0:", type=("build", "run"))
depends_on("py-importlib-metadata@0.18:", type=("build", "run"), when="python@:3.7") depends_on("py-importlib-metadata@0.18:", type=("build", "run"), when="^python@:3.7")
depends_on("py-cached-property", type=("build", "run"), when="python@:3.7") depends_on("py-cached-property", type=("build", "run"), when="^python@:3.7")
depends_on("py-redis@3.4.1:3,4.0.2:", when="+redis", type=("build", "run")) depends_on("py-redis@3.4.1:3,4.0.2:", when="+redis", type=("build", "run"))

View file

@ -170,20 +170,20 @@ class PyNvidiaDali(PythonPackage):
) )
cuda120_versions = ( cuda120_versions = (
"1.27.0-cuda120", "@1.27.0-cuda120",
"1.26.0-cuda120", "@1.26.0-cuda120",
"1.25.0-cuda120", "@1.25.0-cuda120",
"1.24.0-cuda120", "@1.24.0-cuda120",
"1.23.0-cuda120", "@1.23.0-cuda120",
"1.22.0-cuda120", "@1.22.0-cuda120",
) )
cuda110_versions = ( cuda110_versions = (
"1.27.0-cuda110", "@1.27.0-cuda110",
"1.26.0-cuda110", "@1.26.0-cuda110",
"1.25.0-cuda110", "@1.25.0-cuda110",
"1.24.0-cuda110", "@1.24.0-cuda110",
"1.23.0-cuda110", "@1.23.0-cuda110",
"1.22.0-cuda110", "@1.22.0-cuda110",
) )
for v in cuda120_versions: for v in cuda120_versions:

View file

@ -18,6 +18,6 @@ class PyPdbfixer(PythonPackage):
version("1.7", sha256="a0bef3c52a7bbe69a6aea5333f51f3e7d158339be5829aed19b0344bd66d4eea") version("1.7", sha256="a0bef3c52a7bbe69a6aea5333f51f3e7d158339be5829aed19b0344bd66d4eea")
depends_on("py-setuptools", type="build") depends_on("py-setuptools", type="build")
depends_on("openmm@7.1:7.5", type=("build", "run"), when="1.7") depends_on("openmm@7.1:7.5", type=("build", "run"), when="@1.7")
depends_on("openmm@7.6:", type=("build", "run"), when="@1.8:") depends_on("openmm@7.6:", type=("build", "run"), when="@1.8:")
depends_on("py-numpy", type=("build", "run")) depends_on("py-numpy", type=("build", "run"))

View file

@ -29,5 +29,5 @@ class PyTensorflowDatasets(PythonPackage):
depends_on("py-tensorflow-metadata", type=("build", "run")) depends_on("py-tensorflow-metadata", type=("build", "run"))
depends_on("py-termcolor", type=("build", "run")) depends_on("py-termcolor", type=("build", "run"))
depends_on("py-tqdm", type=("build", "run")) depends_on("py-tqdm", type=("build", "run"))
depends_on("py-typing-extensions", type=("build", "run"), when="python@:3.7") depends_on("py-typing-extensions", type=("build", "run"), when="^python@:3.7")
depends_on("py-importlib-resources", type=("build", "run"), when="python@:3.8") depends_on("py-importlib-resources", type=("build", "run"), when="^python@:3.8")