Add type hints to all setup_*environment functions (#49985)

This commit is contained in:
Adam J. Stewart
2025-04-23 15:41:22 +02:00
committed by GitHub
parent 47b71ba8ca
commit 3f063ace1d
950 changed files with 1845 additions and 1367 deletions

View File

@@ -91,7 +91,7 @@ there are any other variables you need to set, you can do this in the
.. code-block:: python
def setup_build_environment(self, env):
def setup_build_environment(self, env: EnvironmentModifications) -> None:
env.set("PREFIX", prefix)
env.set("BLASLIB", spec["blas"].libs.ld_flags)

View File

@@ -128,7 +128,7 @@ depend on the spec:
.. code-block:: python
def setup_run_environment(self, env):
def setup_run_environment(self, env: EnvironmentModifications) -> None:
if self.spec.satisfies("+foo"):
env.set("FOO", "bar")
@@ -142,7 +142,7 @@ For example, a simplified version of the ``python`` package could look like this
.. code-block:: python
def setup_dependent_run_environment(self, env, dependent_spec):
def setup_dependent_run_environment(self, env: EnvironmentModifications, dependent_spec: Spec) -> None:
if dependent_spec.package.extends(self.spec):
env.prepend_path("PYTHONPATH", dependent_spec.prefix.lib.python)

View File

@@ -16,6 +16,7 @@
import spack.package_base
import spack.phase_callbacks
import spack.spec
import spack.util.environment
import spack.util.prefix
from spack.directives import build_system, conflicts, depends_on
from spack.multimethod import when
@@ -846,7 +847,9 @@ def _remove_libtool_archives(self) -> None:
with open(self._removed_la_files_log, mode="w", encoding="utf-8") as f:
f.write("\n".join(libtool_files))
def setup_build_environment(self, env):
def setup_build_environment(
self, env: spack.util.environment.EnvironmentModifications
) -> None:
if self.spec.platform == "darwin" and macos_version() >= Version("11"):
# Many configure files rely on matching '10.*' for macOS version
# detection and fail to add flags if it shows as version 11.

View File

@@ -8,6 +8,7 @@
import spack.package_base
import spack.phase_callbacks
import spack.spec
import spack.util.environment
import spack.util.prefix
from spack.directives import build_system, depends_on
from spack.multimethod import when
@@ -86,7 +87,9 @@ def check_args(self):
"""Argument for ``cargo test`` during check phase"""
return []
def setup_build_environment(self, env):
def setup_build_environment(
self, env: spack.util.environment.EnvironmentModifications
) -> None:
env.set("CARGO_HOME", self.stage.path)
def build(

View File

@@ -8,6 +8,7 @@
import spack.package_base
import spack.phase_callbacks
import spack.spec
import spack.util.environment
import spack.util.prefix
from spack.directives import build_system, depends_on
from spack.multimethod import when
@@ -68,7 +69,9 @@ class GoBuilder(BuilderWithDefaults):
#: Callback names for install-time test
install_time_test_callbacks = ["check"]
def setup_build_environment(self, env):
def setup_build_environment(
self, env: spack.util.environment.EnvironmentModifications
) -> None:
env.set("GO111MODULE", "on")
env.set("GOTOOLCHAIN", "local")
env.set("GOPATH", fs.join_path(self.pkg.stage.path, "go"))

View File

@@ -23,6 +23,7 @@
import spack.error
import spack.phase_callbacks
import spack.spec
from spack.build_environment import dso_suffix
from spack.error import InstallError
from spack.util.environment import EnvironmentModifications
@@ -1016,7 +1017,7 @@ def libs(self):
debug_print(result)
return result
def setup_run_environment(self, env):
def setup_run_environment(self, env: EnvironmentModifications) -> None:
"""Adds environment variables to the generated module file.
These environment variables come from running:
@@ -1049,7 +1050,9 @@ def setup_run_environment(self, env):
env.set("F77", self.prefix.bin.ifort)
env.set("F90", self.prefix.bin.ifort)
def setup_dependent_build_environment(self, env, dependent_spec):
def setup_dependent_build_environment(
self, env: EnvironmentModifications, dependent_spec: spack.spec.Spec
) -> None:
# NB: This function is overwritten by 'mpi' provider packages:
#
# var/spack/repos/builtin/packages/intel-mpi/package.py
@@ -1061,7 +1064,12 @@ def setup_dependent_build_environment(self, env, dependent_spec):
# Handle everything in a callback version.
self._setup_dependent_env_callback(env, dependent_spec)
def _setup_dependent_env_callback(self, env, dependent_spec, compilers_of_client={}):
def _setup_dependent_env_callback(
self,
env: EnvironmentModifications,
dependent_spec: spack.spec.Spec,
compilers_of_client={},
) -> None:
# Expected to be called from a client's
# setup_dependent_build_environment(),
# with args extended to convey the client's compilers as needed.

View File

@@ -8,6 +8,7 @@
import spack.builder
import spack.package_base
import spack.spec
import spack.util.environment
import spack.util.executable
import spack.util.prefix
from spack.directives import build_system, depends_on, extends
@@ -114,5 +115,7 @@ def install(
def _luarocks_config_path(self):
return os.path.join(self.pkg.stage.source_path, "spack_luarocks.lua")
def setup_build_environment(self, env):
def setup_build_environment(
self, env: spack.util.environment.EnvironmentModifications
) -> None:
env.set("LUAROCKS_CONFIG", self._luarocks_config_path())

View File

@@ -4,6 +4,7 @@
import spack.builder
import spack.package_base
import spack.spec
import spack.util.environment
import spack.util.prefix
from spack.directives import build_system, extends
from spack.multimethod import when
@@ -57,7 +58,9 @@ def install(
"pkg prefix %s; pkg install %s" % (prefix, self.pkg.stage.archive_file),
)
def setup_build_environment(self, env):
def setup_build_environment(
self, env: spack.util.environment.EnvironmentModifications
) -> None:
# octave does not like those environment variables to be set:
env.unset("CC")
env.unset("CXX")

View File

@@ -132,7 +132,7 @@ def install_component(self, installer_path):
if not isdir(install_dir):
raise RuntimeError("install failed to directory: {0}".format(install_dir))
def setup_run_environment(self, env):
def setup_run_environment(self, env: EnvironmentModifications) -> None:
"""Adds environment variables to the generated module file.
These environment variables come from running:

View File

@@ -185,10 +185,16 @@ def __init__(self, pkg):
# These two methods don't follow the (self, spec, prefix) signature of phases nor
# the (self) signature of methods, so they are added explicitly to avoid using a
# catch-all (*args, **kwargs)
def setup_build_environment(self, env):
def setup_build_environment(
self, env: spack.util.environment.EnvironmentModifications
) -> None:
return self.pkg_with_dispatcher.setup_build_environment(env)
def setup_dependent_build_environment(self, env, dependent_spec):
def setup_dependent_build_environment(
self,
env: spack.util.environment.EnvironmentModifications,
dependent_spec: spack.spec.Spec,
) -> None:
return self.pkg_with_dispatcher.setup_dependent_build_environment(env, dependent_spec)
return Adapter(pkg)
@@ -402,7 +408,7 @@ def fixup_install(self):
# do something after the package is installed
pass
def setup_build_environment(self, env):
def setup_build_environment(self, env: EnvironmentModifications) -> None:
env.set("MY_ENV_VAR", "my_value")
class CMakeBuilder(cmake.CMakeBuilder, AnyBuilder):

View File

@@ -47,10 +47,10 @@ class Grads(AutotoolsPackage):
depends_on('readline')
depends_on('pkgconfig', type='build')
def setup_build_environment(self, env):
def setup_build_environment(self, env: EnvironmentModifications) -> None:
env.set('SUPPLIBS', '/')
def setup_run_environment(self, env):
def setup_run_environment(self, env: EnvironmentModifications) -> None:
env.set('GADDIR', self.prefix.data)
@run_after('install')

View File

@@ -517,7 +517,7 @@ class Llvm(CMakePackage, CudaPackage):
return (None, flags, None)
return (flags, None, None)
def setup_build_environment(self, env):
def setup_build_environment(self, env: EnvironmentModifications) -> None:
"""When using %clang, add only its ld.lld-$ver and/or ld.lld to our PATH"""
if self.compiler.name in ["clang", "apple-clang"]:
for lld in "ld.lld-{0}".format(self.compiler.version.version[0]), "ld.lld":
@@ -528,7 +528,7 @@ class Llvm(CMakePackage, CudaPackage):
os.symlink(bin, sym)
env.prepend_path("PATH", self.stage.path)
def setup_run_environment(self, env):
def setup_run_environment(self, env: EnvironmentModifications) -> None:
if "+clang" in self.spec:
env.set("CC", join_path(self.spec.prefix.bin, "clang"))
env.set("CXX", join_path(self.spec.prefix.bin, "clang++"))

View File

@@ -318,7 +318,7 @@ class Mfem(Package, CudaPackage, ROCmPackage):
patch('mfem-4.0.0-makefile-syntax-fix.patch', when='@4.0.0')
phases = ['configure', 'build', 'install']
def setup_build_environment(self, env):
def setup_build_environment(self, env: EnvironmentModifications) -> None:
env.unset('MFEM_DIR')
env.unset('MFEM_BUILD_DIR')

View File

@@ -281,7 +281,7 @@ class PyTorch(PythonPackage, CudaPackage):
"caffe2/CMakeLists.txt",
)
def setup_build_environment(self, env):
def setup_build_environment(self, env: EnvironmentModifications) -> None:
"""Set environment variables used to control the build.
PyTorch's ``setup.py`` is a thin wrapper around ``cmake``.

View File

@@ -440,7 +440,7 @@ class Trilinos(CMakePackage, CudaPackage):
url = "https://github.com/trilinos/Trilinos/archive/trilinos-release-{0}.tar.gz"
return url.format(version.dashed)
def setup_dependent_run_environment(self, env, dependent_spec):
def setup_dependent_run_environment(self, env: EnvironmentModifications, dependent_spec: Spec) -> None:
if "+cuda" in self.spec:
# currently Trilinos doesn't perform the memory fence so
# it relies on blocking CUDA kernel launch. This is needed
@@ -453,7 +453,7 @@ class Trilinos(CMakePackage, CudaPackage):
else:
self.spec.kokkos_cxx = spack_cxx
def setup_build_environment(self, env):
def setup_build_environment(self, env: EnvironmentModifications) -> None:
spec = self.spec
if "+cuda" in spec and "+wrapper" in spec:
if "+mpi" in spec:
@@ -847,7 +847,7 @@ class Trilinos(CMakePackage, CudaPackage):
)
filter_file(r"-lpytrilinos", "", "%s/Makefile.export.Trilinos" % self.prefix.include)
def setup_run_environment(self, env):
def setup_run_environment(self, env: EnvironmentModifications) -> None:
if "+exodus" in self.spec:
env.prepend_path("PYTHONPATH", self.prefix.lib)

View File

@@ -334,20 +334,20 @@ def test_remove_complex_package_logic_filtered():
"package_spec,expected_hash",
[
("amdfftw", "tivb752zddjgvfkogfs7cnnvp5olj6co"),
("grads", "rrlmwml3f2frdnqavmro3ias66h5b2ce"),
("llvm", "nufffum5dabmaf4l5tpfcblnbfjknvd3"),
("grads", "lomrsppasfxegyamz4r33zgwiqkveftv"),
("llvm", "paicamlvy5jkgxw4xnacaxahrixe3f3i"),
# has @when("@4.1.0") and raw unicode literals
("mfem", "whwftpqbjvzncmb52oz6izkanbha2uji"),
("mfem@4.0.0", "whwftpqbjvzncmb52oz6izkanbha2uji"),
("mfem@4.1.0", "bpi7of3xelo7fr3ta2lm6bmiruijnxcg"),
("mfem", "slf5qyyyhuj66mo5lpuhkrs35akh2zck"),
("mfem@4.0.0", "slf5qyyyhuj66mo5lpuhkrs35akh2zck"),
("mfem@4.1.0", "yo3ymaulytctas67zjn663ixw5cfyh5u"),
# has @when("@1.5.0:")
("py-torch", "qs7djgqn7dy7r3ps4g7hv2pjvjk4qkhd"),
("py-torch@1.0", "qs7djgqn7dy7r3ps4g7hv2pjvjk4qkhd"),
("py-torch@1.6", "p4ine4hc6f2ik2f2wyuwieslqbozll5w"),
("py-torch", "m3ucsddqr7hjevtgx4cad34nrtqgyjfg"),
("py-torch@1.0", "m3ucsddqr7hjevtgx4cad34nrtqgyjfg"),
("py-torch@1.6", "insaxs6bq34rvyhajdbyr4wddqeqb2t3"),
# has a print with multiple arguments
("legion", "bq2etsik5l6pbryxmbhfhzynci56ruy4"),
# has nested `with when()` blocks and loops
("trilinos", "vqrgscjrla4hi7bllink7v6v6dwxgc2p"),
("trilinos", "ojbtbu3p6gpa42sbilblo2ioanvhouxu"),
],
)
def test_package_hash_consistency(package_spec, expected_hash):