From 9992b563dbf8e0d0732d501e1a163ba0f633e265 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Thu, 23 Jan 2025 12:15:43 +0100 Subject: [PATCH] Improve `spack.build_systems` typing (#48590) --- .../docs/build_systems/custompackage.rst | 4 +-- lib/spack/spack/build_systems/aspell_dict.py | 19 +++++++------- lib/spack/spack/build_systems/autotools.py | 26 +++++-------------- lib/spack/spack/build_systems/cached_cmake.py | 6 ++++- lib/spack/spack/build_systems/cargo.py | 10 +++++-- lib/spack/spack/build_systems/cmake.py | 15 +++-------- lib/spack/spack/build_systems/generic.py | 7 +++++ lib/spack/spack/build_systems/go.py | 10 +++++-- lib/spack/spack/build_systems/lua.py | 24 +++++++++++------ lib/spack/spack/build_systems/makefile.py | 15 +++-------- lib/spack/spack/build_systems/maven.py | 12 ++++++--- lib/spack/spack/build_systems/meson.py | 15 +++-------- lib/spack/spack/build_systems/msbuild.py | 10 +++++-- lib/spack/spack/build_systems/nmake.py | 10 +++++-- lib/spack/spack/build_systems/octave.py | 6 ++++- lib/spack/spack/build_systems/perl.py | 14 +++++++--- lib/spack/spack/build_systems/python.py | 1 + lib/spack/spack/build_systems/qmake.py | 14 +++++++--- lib/spack/spack/build_systems/racket.py | 17 +++++++----- lib/spack/spack/build_systems/ruby.py | 10 +++++-- lib/spack/spack/build_systems/scons.py | 10 +++++-- lib/spack/spack/build_systems/sip.py | 14 +++++++--- lib/spack/spack/build_systems/waf.py | 14 +++++++--- 23 files changed, 174 insertions(+), 109 deletions(-) diff --git a/lib/spack/docs/build_systems/custompackage.rst b/lib/spack/docs/build_systems/custompackage.rst index 452efcb95ec..737e9c74247 100644 --- a/lib/spack/docs/build_systems/custompackage.rst +++ b/lib/spack/docs/build_systems/custompackage.rst @@ -56,13 +56,13 @@ If you look at the ``perl`` package, you'll see: .. code-block:: python - phases = ["configure", "build", "install"] + phases = ("configure", "build", "install") Similarly, ``cmake`` defines: .. code-block:: python - phases = ["bootstrap", "build", "install"] + phases = ("bootstrap", "build", "install") If we look at the ``cmake`` example, this tells Spack's ``PackageBase`` class to run the ``bootstrap``, ``build``, and ``install`` functions diff --git a/lib/spack/spack/build_systems/aspell_dict.py b/lib/spack/spack/build_systems/aspell_dict.py index fcaa2c0cb5e..50ad140d29c 100644 --- a/lib/spack/spack/build_systems/aspell_dict.py +++ b/lib/spack/spack/build_systems/aspell_dict.py @@ -6,7 +6,9 @@ import llnl.util.filesystem as fs import spack.directives +import spack.spec import spack.util.executable +import spack.util.prefix from .autotools import AutotoolsBuilder, AutotoolsPackage @@ -17,19 +19,18 @@ class AspellBuilder(AutotoolsBuilder): to the Aspell extensions. """ - def configure(self, pkg, spec, prefix): + def configure( + self, + pkg: "AspellDictPackage", # type: ignore[override] + spec: spack.spec.Spec, + prefix: spack.util.prefix.Prefix, + ): aspell = spec["aspell"].prefix.bin.aspell prezip = spec["aspell"].prefix.bin.prezip destdir = prefix - sh = spack.util.executable.which("sh") - sh( - "./configure", - "--vars", - "ASPELL={0}".format(aspell), - "PREZIP={0}".format(prezip), - "DESTDIR={0}".format(destdir), - ) + sh = spack.util.executable.Executable("/bin/sh") + sh("./configure", "--vars", f"ASPELL={aspell}", f"PREZIP={prezip}", f"DESTDIR={destdir}") # Aspell dictionaries install their bits into their prefix.lib diff --git a/lib/spack/spack/build_systems/autotools.py b/lib/spack/spack/build_systems/autotools.py index 19e38e7e47b..e1d771fef71 100644 --- a/lib/spack/spack/build_systems/autotools.py +++ b/lib/spack/spack/build_systems/autotools.py @@ -534,7 +534,7 @@ def build_directory(self) -> str: return build_dir @spack.phase_callbacks.run_before("autoreconf") - def delete_configure_to_force_update(self) -> None: + def _delete_configure_to_force_update(self) -> None: if self.force_autoreconf: fs.force_remove(self.configure_abs_path) @@ -547,7 +547,7 @@ def autoreconf_search_path_args(self) -> List[str]: return _autoreconf_search_path_args(self.spec) @spack.phase_callbacks.run_after("autoreconf") - def set_configure_or_die(self) -> None: + def _set_configure_or_die(self) -> None: """Ensure the presence of a "configure" script, or raise. If the "configure" is found, a module level attribute is set. @@ -571,10 +571,7 @@ def configure_args(self) -> List[str]: return [] def autoreconf( - self, - pkg: spack.package_base.PackageBase, - spec: spack.spec.Spec, - prefix: spack.util.prefix.Prefix, + self, pkg: AutotoolsPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix ) -> None: """Not needed usually, configure should be already there""" @@ -603,10 +600,7 @@ def autoreconf( self.pkg.module.autoreconf(*autoreconf_args) def configure( - self, - pkg: spack.package_base.PackageBase, - spec: spack.spec.Spec, - prefix: spack.util.prefix.Prefix, + self, pkg: AutotoolsPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix ) -> None: """Run "configure", with the arguments specified by the builder and an appropriately set prefix. @@ -619,10 +613,7 @@ def configure( pkg.module.configure(*options) def build( - self, - pkg: spack.package_base.PackageBase, - spec: spack.spec.Spec, - prefix: spack.util.prefix.Prefix, + self, pkg: AutotoolsPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix ) -> None: """Run "make" on the build targets specified by the builder.""" # See https://autotools.io/automake/silent.html @@ -632,10 +623,7 @@ def build( pkg.module.make(*params) def install( - self, - pkg: spack.package_base.PackageBase, - spec: spack.spec.Spec, - prefix: spack.util.prefix.Prefix, + self, pkg: AutotoolsPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix ) -> None: """Run "make" on the install targets specified by the builder.""" with fs.working_dir(self.build_directory): @@ -832,7 +820,7 @@ def installcheck(self) -> None: self.pkg._if_make_target_execute("installcheck") @spack.phase_callbacks.run_after("install") - def remove_libtool_archives(self) -> None: + def _remove_libtool_archives(self) -> None: """Remove all .la files in prefix sub-folders if the package sets ``install_libtool_archives`` to be False. """ diff --git a/lib/spack/spack/build_systems/cached_cmake.py b/lib/spack/spack/build_systems/cached_cmake.py index 8e2b76110dc..9649cea1baa 100644 --- a/lib/spack/spack/build_systems/cached_cmake.py +++ b/lib/spack/spack/build_systems/cached_cmake.py @@ -10,6 +10,8 @@ import llnl.util.tty as tty import spack.phase_callbacks +import spack.spec +import spack.util.prefix from .cmake import CMakeBuilder, CMakePackage @@ -330,7 +332,9 @@ def initconfig_package_entries(self): """This method is to be overwritten by the package""" return [] - def initconfig(self, pkg, spec, prefix): + def initconfig( + self, pkg: "CachedCMakePackage", spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: cache_entries = ( self.std_initconfig_entries() + self.initconfig_compiler_entries() diff --git a/lib/spack/spack/build_systems/cargo.py b/lib/spack/spack/build_systems/cargo.py index 2e5c6e4ffc0..8a254c3c5c4 100644 --- a/lib/spack/spack/build_systems/cargo.py +++ b/lib/spack/spack/build_systems/cargo.py @@ -7,6 +7,8 @@ import spack.builder import spack.package_base import spack.phase_callbacks +import spack.spec +import spack.util.prefix from spack.directives import build_system, depends_on from spack.multimethod import when @@ -81,12 +83,16 @@ def check_args(self): def setup_build_environment(self, env): env.set("CARGO_HOME", self.stage.path) - def build(self, pkg, spec, prefix): + def build( + self, pkg: CargoPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Runs ``cargo install`` in the source directory""" with fs.working_dir(self.build_directory): pkg.module.cargo("install", "--root", "out", "--path", ".", *self.build_args) - def install(self, pkg, spec, prefix): + def install( + self, pkg: CargoPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Copy build files into package prefix.""" with fs.working_dir(self.build_directory): fs.install_tree("out", prefix) diff --git a/lib/spack/spack/build_systems/cmake.py b/lib/spack/spack/build_systems/cmake.py index 8c2c1df7638..c166e3ea63b 100644 --- a/lib/spack/spack/build_systems/cmake.py +++ b/lib/spack/spack/build_systems/cmake.py @@ -454,10 +454,7 @@ def cmake_args(self) -> List[str]: return [] def cmake( - self, - pkg: spack.package_base.PackageBase, - spec: spack.spec.Spec, - prefix: spack.util.prefix.Prefix, + self, pkg: CMakePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix ) -> None: """Runs ``cmake`` in the build directory""" @@ -474,10 +471,7 @@ def cmake( pkg.module.cmake(*options) def build( - self, - pkg: spack.package_base.PackageBase, - spec: spack.spec.Spec, - prefix: spack.util.prefix.Prefix, + self, pkg: CMakePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix ) -> None: """Make the build targets""" with fs.working_dir(self.build_directory): @@ -488,10 +482,7 @@ def build( pkg.module.ninja(*self.build_targets) def install( - self, - pkg: spack.package_base.PackageBase, - spec: spack.spec.Spec, - prefix: spack.util.prefix.Prefix, + self, pkg: CMakePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix ) -> None: """Make the install targets""" with fs.working_dir(self.build_directory): diff --git a/lib/spack/spack/build_systems/generic.py b/lib/spack/spack/build_systems/generic.py index 3d30633e0ff..d27495b31cf 100644 --- a/lib/spack/spack/build_systems/generic.py +++ b/lib/spack/spack/build_systems/generic.py @@ -7,6 +7,8 @@ import spack.directives import spack.package_base import spack.phase_callbacks +import spack.spec +import spack.util.prefix from ._checks import BuilderWithDefaults, apply_macos_rpath_fixups, execute_install_time_tests @@ -48,3 +50,8 @@ class GenericBuilder(BuilderWithDefaults): # unconditionally perform any post-install phase tests spack.phase_callbacks.run_after("install")(execute_install_time_tests) + + def install( + self, pkg: Package, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: + raise NotImplementedError diff --git a/lib/spack/spack/build_systems/go.py b/lib/spack/spack/build_systems/go.py index b9b32f22999..fed19cc8215 100644 --- a/lib/spack/spack/build_systems/go.py +++ b/lib/spack/spack/build_systems/go.py @@ -7,6 +7,8 @@ import spack.builder import spack.package_base import spack.phase_callbacks +import spack.spec +import spack.util.prefix from spack.directives import build_system, extends from spack.multimethod import when @@ -88,12 +90,16 @@ def check_args(self): """Argument for ``go test`` during check phase""" return [] - def build(self, pkg, spec, prefix): + def build( + self, pkg: GoPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Runs ``go build`` in the source directory""" with fs.working_dir(self.build_directory): pkg.module.go("build", *self.build_args) - def install(self, pkg, spec, prefix): + def install( + self, pkg: GoPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Install built binaries into prefix bin.""" with fs.working_dir(self.build_directory): fs.mkdirp(prefix.bin) diff --git a/lib/spack/spack/build_systems/lua.py b/lib/spack/spack/build_systems/lua.py index c02678dc299..e8b1698f297 100644 --- a/lib/spack/spack/build_systems/lua.py +++ b/lib/spack/spack/build_systems/lua.py @@ -7,7 +7,9 @@ import spack.builder import spack.package_base +import spack.spec import spack.util.executable +import spack.util.prefix from spack.directives import build_system, depends_on, extends from spack.multimethod import when @@ -55,7 +57,9 @@ class LuaBuilder(spack.builder.Builder): #: Names associated with package attributes in the old build-system format legacy_attributes = () - def unpack(self, pkg, spec, prefix): + def unpack( + self, pkg: LuaPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: if os.path.splitext(pkg.stage.archive_file)[1] == ".rock": directory = pkg.luarocks("unpack", pkg.stage.archive_file, output=str) dirlines = directory.split("\n") @@ -66,15 +70,16 @@ def unpack(self, pkg, spec, prefix): def _generate_tree_line(name, prefix): return """{{ name = "{name}", root = "{prefix}" }};""".format(name=name, prefix=prefix) - def generate_luarocks_config(self, pkg, spec, prefix): + def generate_luarocks_config( + self, pkg: LuaPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: spec = self.pkg.spec table_entries = [] for d in spec.traverse(deptype=("build", "run")): if d.package.extends(self.pkg.extendee_spec): table_entries.append(self._generate_tree_line(d.name, d.prefix)) - path = self._luarocks_config_path() - with open(path, "w", encoding="utf-8") as config: + with open(self._luarocks_config_path(), "w", encoding="utf-8") as config: config.write( """ deps_mode="all" @@ -85,23 +90,26 @@ def generate_luarocks_config(self, pkg, spec, prefix): "\n".join(table_entries) ) ) - return path - def preprocess(self, pkg, spec, prefix): + def preprocess( + self, pkg: LuaPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Override this to preprocess source before building with luarocks""" pass def luarocks_args(self): return [] - def install(self, pkg, spec, prefix): + def install( + self, pkg: LuaPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: rock = "." specs = find(".", "*.rockspec", recursive=False) if specs: rock = specs[0] rocks_args = self.luarocks_args() rocks_args.append(rock) - self.pkg.luarocks("--tree=" + prefix, "make", *rocks_args) + pkg.luarocks("--tree=" + prefix, "make", *rocks_args) def _luarocks_config_path(self): return os.path.join(self.pkg.stage.source_path, "spack_luarocks.lua") diff --git a/lib/spack/spack/build_systems/makefile.py b/lib/spack/spack/build_systems/makefile.py index d9040f19271..017e8e9decf 100644 --- a/lib/spack/spack/build_systems/makefile.py +++ b/lib/spack/spack/build_systems/makefile.py @@ -98,29 +98,20 @@ def build_directory(self) -> str: return self.pkg.stage.source_path def edit( - self, - pkg: spack.package_base.PackageBase, - spec: spack.spec.Spec, - prefix: spack.util.prefix.Prefix, + self, pkg: MakefilePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix ) -> None: """Edit the Makefile before calling make. The default is a no-op.""" pass def build( - self, - pkg: spack.package_base.PackageBase, - spec: spack.spec.Spec, - prefix: spack.util.prefix.Prefix, + self, pkg: MakefilePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix ) -> None: """Run "make" on the build targets specified by the builder.""" with fs.working_dir(self.build_directory): pkg.module.make(*self.build_targets) def install( - self, - pkg: spack.package_base.PackageBase, - spec: spack.spec.Spec, - prefix: spack.util.prefix.Prefix, + self, pkg: MakefilePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix ) -> None: """Run "make" on the install targets specified by the builder.""" with fs.working_dir(self.build_directory): diff --git a/lib/spack/spack/build_systems/maven.py b/lib/spack/spack/build_systems/maven.py index e9f119a9592..4713d20e046 100644 --- a/lib/spack/spack/build_systems/maven.py +++ b/lib/spack/spack/build_systems/maven.py @@ -5,6 +5,8 @@ import spack.builder import spack.package_base +import spack.spec +import spack.util.prefix from spack.directives import build_system, depends_on from spack.multimethod import when from spack.util.executable import which @@ -58,16 +60,20 @@ def build_args(self): """List of args to pass to build phase.""" return [] - def build(self, pkg, spec, prefix): + def build( + self, pkg: MavenPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Compile code and package into a JAR file.""" with fs.working_dir(self.build_directory): - mvn = which("mvn") + mvn = which("mvn", required=True) if self.pkg.run_tests: mvn("verify", *self.build_args()) else: mvn("package", "-DskipTests", *self.build_args()) - def install(self, pkg, spec, prefix): + def install( + self, pkg: MavenPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Copy to installation prefix.""" with fs.working_dir(self.build_directory): fs.install_tree(".", prefix) diff --git a/lib/spack/spack/build_systems/meson.py b/lib/spack/spack/build_systems/meson.py index b4e9d92c0f4..18a3d29ab50 100644 --- a/lib/spack/spack/build_systems/meson.py +++ b/lib/spack/spack/build_systems/meson.py @@ -188,10 +188,7 @@ def meson_args(self) -> List[str]: return [] def meson( - self, - pkg: spack.package_base.PackageBase, - spec: spack.spec.Spec, - prefix: spack.util.prefix.Prefix, + self, pkg: MesonPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix ) -> None: """Run ``meson`` in the build directory""" options = [] @@ -204,10 +201,7 @@ def meson( pkg.module.meson(*options) def build( - self, - pkg: spack.package_base.PackageBase, - spec: spack.spec.Spec, - prefix: spack.util.prefix.Prefix, + self, pkg: MesonPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix ) -> None: """Make the build targets""" options = ["-v"] @@ -216,10 +210,7 @@ def build( pkg.module.ninja(*options) def install( - self, - pkg: spack.package_base.PackageBase, - spec: spack.spec.Spec, - prefix: spack.util.prefix.Prefix, + self, pkg: MesonPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix ) -> None: """Make the install targets""" with fs.working_dir(self.build_directory): diff --git a/lib/spack/spack/build_systems/msbuild.py b/lib/spack/spack/build_systems/msbuild.py index 8002222b9e4..f83057c39c4 100644 --- a/lib/spack/spack/build_systems/msbuild.py +++ b/lib/spack/spack/build_systems/msbuild.py @@ -7,6 +7,8 @@ import spack.builder import spack.package_base +import spack.spec +import spack.util.prefix from spack.directives import build_system, conflicts from ._checks import BuilderWithDefaults @@ -99,7 +101,9 @@ def msbuild_install_args(self): as `msbuild_args` by default.""" return self.msbuild_args() - def build(self, pkg, spec, prefix): + def build( + self, pkg: MSBuildPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Run "msbuild" on the build targets specified by the builder.""" with fs.working_dir(self.build_directory): pkg.module.msbuild( @@ -108,7 +112,9 @@ def build(self, pkg, spec, prefix): self.define_targets(*self.build_targets), ) - def install(self, pkg, spec, prefix): + def install( + self, pkg: MSBuildPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Run "msbuild" on the install targets specified by the builder. This is INSTALL by default""" with fs.working_dir(self.build_directory): diff --git a/lib/spack/spack/build_systems/nmake.py b/lib/spack/spack/build_systems/nmake.py index d6b715b9c07..8362a0e5b5b 100644 --- a/lib/spack/spack/build_systems/nmake.py +++ b/lib/spack/spack/build_systems/nmake.py @@ -7,6 +7,8 @@ import spack.builder import spack.package_base +import spack.spec +import spack.util.prefix from spack.directives import build_system, conflicts from ._checks import BuilderWithDefaults @@ -123,7 +125,9 @@ def nmake_install_args(self): Individual packages should override to specify NMake args to command line""" return [] - def build(self, pkg, spec, prefix): + def build( + self, pkg: NMakePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Run "nmake" on the build targets specified by the builder.""" opts = self.std_nmake_args opts += self.nmake_args() @@ -132,7 +136,9 @@ def build(self, pkg, spec, prefix): with fs.working_dir(self.build_directory): pkg.module.nmake(*opts, *self.build_targets, ignore_quotes=self.ignore_quotes) - def install(self, pkg, spec, prefix): + def install( + self, pkg: NMakePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Run "nmake" on the install targets specified by the builder. This is INSTALL by default""" opts = self.std_nmake_args diff --git a/lib/spack/spack/build_systems/octave.py b/lib/spack/spack/build_systems/octave.py index 4570e51a034..9e5eabe5dec 100644 --- a/lib/spack/spack/build_systems/octave.py +++ b/lib/spack/spack/build_systems/octave.py @@ -3,6 +3,8 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) import spack.builder import spack.package_base +import spack.spec +import spack.util.prefix from spack.directives import build_system, extends from spack.multimethod import when @@ -42,7 +44,9 @@ class OctaveBuilder(BuilderWithDefaults): #: Names associated with package attributes in the old build-system format legacy_attributes = () - def install(self, pkg, spec, prefix): + def install( + self, pkg: OctavePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Install the package from the archive file""" pkg.module.octave( "--quiet", diff --git a/lib/spack/spack/build_systems/perl.py b/lib/spack/spack/build_systems/perl.py index bab542b2dc5..4784d21b2a2 100644 --- a/lib/spack/spack/build_systems/perl.py +++ b/lib/spack/spack/build_systems/perl.py @@ -10,6 +10,8 @@ import spack.builder import spack.package_base import spack.phase_callbacks +import spack.spec +import spack.util.prefix from spack.directives import build_system, depends_on, extends from spack.install_test import SkipTest, test_part from spack.multimethod import when @@ -149,7 +151,9 @@ def configure_args(self): """ return [] - def configure(self, pkg, spec, prefix): + def configure( + self, pkg: PerlPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Run Makefile.PL or Build.PL with arguments consisting of an appropriate installation base directory followed by the list returned by :py:meth:`~.PerlBuilder.configure_args`. @@ -173,7 +177,9 @@ def fix_shebang(self): repl = "#!/usr/bin/env perl" filter_file(pattern, repl, "Build", backup=False) - def build(self, pkg, spec, prefix): + def build( + self, pkg: PerlPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Builds a Perl package.""" self.build_executable() @@ -184,6 +190,8 @@ def check(self): """Runs built-in tests of a Perl package.""" self.build_executable("test") - def install(self, pkg, spec, prefix): + def install( + self, pkg: PerlPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Installs a Perl package.""" self.build_executable("install") diff --git a/lib/spack/spack/build_systems/python.py b/lib/spack/spack/build_systems/python.py index 4484620d1f5..e09408fcd7f 100644 --- a/lib/spack/spack/build_systems/python.py +++ b/lib/spack/spack/build_systems/python.py @@ -28,6 +28,7 @@ import spack.repo import spack.spec import spack.store +import spack.util.prefix from spack.directives import build_system, depends_on, extends from spack.error import NoHeadersError, NoLibrariesError from spack.install_test import test_part diff --git a/lib/spack/spack/build_systems/qmake.py b/lib/spack/spack/build_systems/qmake.py index 4bf6b994d1e..7d95db4d8e0 100644 --- a/lib/spack/spack/build_systems/qmake.py +++ b/lib/spack/spack/build_systems/qmake.py @@ -6,6 +6,8 @@ import spack.builder import spack.package_base import spack.phase_callbacks +import spack.spec +import spack.util.prefix from spack.directives import build_system, depends_on from ._checks import BuilderWithDefaults, execute_build_time_tests @@ -62,17 +64,23 @@ def qmake_args(self): """List of arguments passed to qmake.""" return [] - def qmake(self, pkg, spec, prefix): + def qmake( + self, pkg: QMakePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Run ``qmake`` to configure the project and generate a Makefile.""" with working_dir(self.build_directory): pkg.module.qmake(*self.qmake_args()) - def build(self, pkg, spec, prefix): + def build( + self, pkg: QMakePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Make the build targets""" with working_dir(self.build_directory): pkg.module.make() - def install(self, pkg, spec, prefix): + def install( + self, pkg: QMakePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Make the install targets""" with working_dir(self.build_directory): pkg.module.make("install") diff --git a/lib/spack/spack/build_systems/racket.py b/lib/spack/spack/build_systems/racket.py index 99338767f80..bd3988073e2 100644 --- a/lib/spack/spack/build_systems/racket.py +++ b/lib/spack/spack/build_systems/racket.py @@ -9,6 +9,8 @@ import llnl.util.tty as tty import spack.builder +import spack.spec +import spack.util.prefix from spack.build_environment import SPACK_NO_PARALLEL_MAKE from spack.config import determine_number_of_jobs from spack.directives import build_system, extends, maintainers @@ -74,18 +76,22 @@ def build_directory(self): ret = os.path.join(ret, self.subdirectory) return ret - def install(self, pkg, spec, prefix): + def install( + self, pkg: RacketPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Install everything from build directory.""" raco = Executable("raco") with fs.working_dir(self.build_directory): - parallel = self.pkg.parallel and (not env_flag(SPACK_NO_PARALLEL_MAKE)) + parallel = pkg.parallel and (not env_flag(SPACK_NO_PARALLEL_MAKE)) + name = pkg.racket_name + assert name is not None, "Racket package name is not set" args = [ "pkg", "install", "-t", "dir", "-n", - self.pkg.racket_name, + name, "--deps", "fail", "--ignore-implies", @@ -101,8 +107,7 @@ def install(self, pkg, spec, prefix): except ProcessError: args.insert(-2, "--skip-installed") raco(*args) - msg = ( - "Racket package {0} was already installed, uninstalling via " + tty.warn( + f"Racket package {name} was already installed, uninstalling via " "Spack may make someone unhappy!" ) - tty.warn(msg.format(self.pkg.racket_name)) diff --git a/lib/spack/spack/build_systems/ruby.py b/lib/spack/spack/build_systems/ruby.py index 5b8d0c6be58..f1263396c3e 100644 --- a/lib/spack/spack/build_systems/ruby.py +++ b/lib/spack/spack/build_systems/ruby.py @@ -5,6 +5,8 @@ import spack.builder import spack.package_base +import spack.spec +import spack.util.prefix from spack.directives import build_system, extends, maintainers from ._checks import BuilderWithDefaults @@ -42,7 +44,9 @@ class RubyBuilder(BuilderWithDefaults): #: Names associated with package attributes in the old build-system format legacy_attributes = () - def build(self, pkg, spec, prefix): + def build( + self, pkg: RubyPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Build a Ruby gem.""" # ruby-rake provides both rake.gemspec and Rakefile, but only @@ -58,7 +62,9 @@ def build(self, pkg, spec, prefix): # Some Ruby packages only ship `*.gem` files, so nothing to build pass - def install(self, pkg, spec, prefix): + def install( + self, pkg: RubyPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Install a Ruby gem. The ruby package sets ``GEM_HOME`` to tell gem where to install to.""" diff --git a/lib/spack/spack/build_systems/scons.py b/lib/spack/spack/build_systems/scons.py index b9b2f572019..d47f0a428a3 100644 --- a/lib/spack/spack/build_systems/scons.py +++ b/lib/spack/spack/build_systems/scons.py @@ -4,6 +4,8 @@ import spack.builder import spack.package_base import spack.phase_callbacks +import spack.spec +import spack.util.prefix from spack.directives import build_system, depends_on from ._checks import BuilderWithDefaults, execute_build_time_tests @@ -59,7 +61,9 @@ def build_args(self, spec, prefix): """Arguments to pass to build.""" return [] - def build(self, pkg, spec, prefix): + def build( + self, pkg: SConsPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Build the package.""" pkg.module.scons(*self.build_args(spec, prefix)) @@ -67,7 +71,9 @@ def install_args(self, spec, prefix): """Arguments to pass to install.""" return [] - def install(self, pkg, spec, prefix): + def install( + self, pkg: SConsPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Install the package.""" pkg.module.scons("install", *self.install_args(spec, prefix)) diff --git a/lib/spack/spack/build_systems/sip.py b/lib/spack/spack/build_systems/sip.py index fac53704eef..44b5f1a9e64 100644 --- a/lib/spack/spack/build_systems/sip.py +++ b/lib/spack/spack/build_systems/sip.py @@ -11,6 +11,8 @@ import spack.install_test import spack.package_base import spack.phase_callbacks +import spack.spec +import spack.util.prefix from spack.directives import build_system, depends_on, extends from spack.multimethod import when from spack.util.executable import Executable @@ -130,7 +132,9 @@ class SIPBuilder(BuilderWithDefaults): build_directory = "build" - def configure(self, pkg, spec, prefix): + def configure( + self, pkg: SIPPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Configure the package.""" # https://www.riverbankcomputing.com/static/Docs/sip/command_line_tools.html @@ -148,7 +152,9 @@ def configure_args(self): """Arguments to pass to configure.""" return [] - def build(self, pkg, spec, prefix): + def build( + self, pkg: SIPPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Build the package.""" args = self.build_args() @@ -159,7 +165,9 @@ def build_args(self): """Arguments to pass to build.""" return [] - def install(self, pkg, spec, prefix): + def install( + self, pkg: SIPPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Install the package.""" args = self.install_args() diff --git a/lib/spack/spack/build_systems/waf.py b/lib/spack/spack/build_systems/waf.py index d9667aeccb8..7bc7c889788 100644 --- a/lib/spack/spack/build_systems/waf.py +++ b/lib/spack/spack/build_systems/waf.py @@ -6,6 +6,8 @@ import spack.builder import spack.package_base import spack.phase_callbacks +import spack.spec +import spack.util.prefix from spack.directives import build_system, depends_on from ._checks import BuilderWithDefaults, execute_build_time_tests, execute_install_time_tests @@ -97,7 +99,9 @@ def waf(self, *args, **kwargs): with working_dir(self.build_directory): self.python("waf", "-j{0}".format(jobs), *args, **kwargs) - def configure(self, pkg, spec, prefix): + def configure( + self, pkg: WafPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Configures the project.""" args = ["--prefix={0}".format(self.pkg.prefix)] args += self.configure_args() @@ -108,7 +112,9 @@ def configure_args(self): """Arguments to pass to configure.""" return [] - def build(self, pkg, spec, prefix): + def build( + self, pkg: WafPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Executes the build.""" args = self.build_args() @@ -118,7 +124,9 @@ def build_args(self): """Arguments to pass to build.""" return [] - def install(self, pkg, spec, prefix): + def install( + self, pkg: WafPackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix + ) -> None: """Installs the targets on the system.""" args = self.install_args()