summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmen Stoppels <me@harmenstoppels.nl>2024-09-01 11:25:51 +0200
committerGitHub <noreply@github.com>2024-09-01 11:25:51 +0200
commitf7de621d0c1d4524c3dde8baee204fb8864c1ecd (patch)
tree1f30349723f6011e588115bef79441ce2ae63632
parenta5f404cff592cf173a3fa1907f1fb912657db8e4 (diff)
downloadspack-f7de621d0c1d4524c3dde8baee204fb8864c1ecd.tar.gz
spack-f7de621d0c1d4524c3dde8baee204fb8864c1ecd.tar.bz2
spack-f7de621d0c1d4524c3dde8baee204fb8864c1ecd.tar.xz
spack-f7de621d0c1d4524c3dde8baee204fb8864c1ecd.zip
Remove redundant inspect.getmodule(self) idiom in packages (#46073)
-rw-r--r--lib/spack/spack/build_environment.py14
-rw-r--r--lib/spack/spack/build_systems/autotools.py14
-rw-r--r--lib/spack/spack/build_systems/cargo.py8
-rw-r--r--lib/spack/spack/build_systems/cmake.py11
-rw-r--r--lib/spack/spack/build_systems/go.py6
-rw-r--r--lib/spack/spack/build_systems/makefile.py5
-rw-r--r--lib/spack/spack/build_systems/meson.py7
-rw-r--r--lib/spack/spack/build_systems/msbuild.py5
-rw-r--r--lib/spack/spack/build_systems/nmake.py9
-rw-r--r--lib/spack/spack/build_systems/octave.py4
-rw-r--r--lib/spack/spack/build_systems/perl.py5
-rw-r--r--lib/spack/spack/build_systems/python.py3
-rw-r--r--lib/spack/spack/build_systems/qmake.py8
-rw-r--r--lib/spack/spack/build_systems/r.py3
-rw-r--r--lib/spack/spack/build_systems/ruby.py9
-rw-r--r--lib/spack/spack/build_systems/scons.py9
-rw-r--r--lib/spack/spack/build_systems/sip.py12
-rw-r--r--lib/spack/spack/build_systems/waf.py6
-rw-r--r--lib/spack/spack/builder.py4
-rw-r--r--lib/spack/spack/package_base.py9
-rw-r--r--lib/spack/spack/test/build_environment.py2
-rw-r--r--lib/spack/spack/test/concretize.py6
-rw-r--r--var/spack/repos/builtin/packages/evtgen/package.py2
-rw-r--r--var/spack/repos/builtin/packages/fjcontrib/package.py6
-rw-r--r--var/spack/repos/builtin/packages/grackle/package.py5
-rw-r--r--var/spack/repos/builtin/packages/intel-tbb/package.py14
-rw-r--r--var/spack/repos/builtin/packages/lorene/package.py5
-rw-r--r--var/spack/repos/builtin/packages/ollama/package.py8
-rw-r--r--var/spack/repos/builtin/packages/perl-bioperl/package.py8
-rw-r--r--var/spack/repos/builtin/packages/perl-io-socket-ssl/package.py6
-rw-r--r--var/spack/repos/builtin/packages/perl-net-ssleay/package.py6
-rw-r--r--var/spack/repos/builtin/packages/pexsi/package.py5
-rw-r--r--var/spack/repos/builtin/packages/wannier90/package.py3
33 files changed, 84 insertions, 143 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index 6e91b17bdc..e807bf6fd0 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -1553,21 +1553,21 @@ class ModuleChangePropagator:
_PROTECTED_NAMES = ("package", "current_module", "modules_in_mro", "_set_attributes")
- def __init__(self, package):
+ def __init__(self, package: spack.package_base.PackageBase) -> None:
self._set_self_attributes("package", package)
self._set_self_attributes("current_module", package.module)
#: Modules for the classes in the MRO up to PackageBase
modules_in_mro = []
- for cls in type(package).__mro__:
- module = cls.module
+ for cls in package.__class__.__mro__:
+ module = getattr(cls, "module", None)
- if module == self.current_module:
- continue
-
- if module == spack.package_base:
+ if module is None or module is spack.package_base:
break
+ if module is self.current_module:
+ continue
+
modules_in_mro.append(module)
self._set_self_attributes("modules_in_mro", modules_in_mro)
self._set_self_attributes("_set_attributes", {})
diff --git a/lib/spack/spack/build_systems/autotools.py b/lib/spack/spack/build_systems/autotools.py
index ce4d6bc279..b9b9ee2f2e 100644
--- a/lib/spack/spack/build_systems/autotools.py
+++ b/lib/spack/spack/build_systems/autotools.py
@@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
import os
import os.path
import stat
@@ -549,13 +548,12 @@ To resolve this problem, please try the following:
tty.warn("* a custom AUTORECONF phase in the package *")
tty.warn("*********************************************************")
with fs.working_dir(self.configure_directory):
- m = inspect.getmodule(self.pkg)
# This line is what is needed most of the time
# --install, --verbose, --force
autoreconf_args = ["-ivf"]
autoreconf_args += self.autoreconf_search_path_args
autoreconf_args += self.autoreconf_extra_args
- m.autoreconf(*autoreconf_args)
+ self.pkg.module.autoreconf(*autoreconf_args)
@property
def autoreconf_search_path_args(self):
@@ -579,7 +577,9 @@ To resolve this problem, please try the following:
raise RuntimeError(msg.format(self.configure_directory))
# Monkey-patch the configure script in the corresponding module
- inspect.getmodule(self.pkg).configure = Executable(self.configure_abs_path)
+ globals_for_pkg = spack.build_environment.ModuleChangePropagator(self.pkg)
+ globals_for_pkg.configure = Executable(self.configure_abs_path)
+ globals_for_pkg.propagate_changes_to_mro()
def configure_args(self):
"""Return the list of all the arguments that must be passed to configure,
@@ -596,7 +596,7 @@ To resolve this problem, please try the following:
options += self.configure_args()
with fs.working_dir(self.build_directory, create=True):
- inspect.getmodule(self.pkg).configure(*options)
+ pkg.module.configure(*options)
def build(self, pkg, spec, prefix):
"""Run "make" on the build targets specified by the builder."""
@@ -604,12 +604,12 @@ To resolve this problem, please try the following:
params = ["V=1"]
params += self.build_targets
with fs.working_dir(self.build_directory):
- inspect.getmodule(self.pkg).make(*params)
+ pkg.module.make(*params)
def install(self, pkg, spec, prefix):
"""Run "make" on the install targets specified by the builder."""
with fs.working_dir(self.build_directory):
- inspect.getmodule(self.pkg).make(*self.install_targets)
+ pkg.module.make(*self.install_targets)
spack.builder.run_after("build")(execute_build_time_tests)
diff --git a/lib/spack/spack/build_systems/cargo.py b/lib/spack/spack/build_systems/cargo.py
index 2fd952d8c2..4dded46559 100644
--- a/lib/spack/spack/build_systems/cargo.py
+++ b/lib/spack/spack/build_systems/cargo.py
@@ -3,8 +3,6 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
-
import llnl.util.filesystem as fs
import spack.builder
@@ -72,9 +70,7 @@ class CargoBuilder(BaseBuilder):
def build(self, pkg, spec, prefix):
"""Runs ``cargo install`` in the source directory"""
with fs.working_dir(self.build_directory):
- inspect.getmodule(pkg).cargo(
- "install", "--root", "out", "--path", ".", *self.build_args
- )
+ pkg.module.cargo("install", "--root", "out", "--path", ".", *self.build_args)
def install(self, pkg, spec, prefix):
"""Copy build files into package prefix."""
@@ -86,4 +82,4 @@ class CargoBuilder(BaseBuilder):
def check(self):
"""Run "cargo test"."""
with fs.working_dir(self.build_directory):
- inspect.getmodule(self.pkg).cargo("test", *self.check_args)
+ self.pkg.module.cargo("test", *self.check_args)
diff --git a/lib/spack/spack/build_systems/cmake.py b/lib/spack/spack/build_systems/cmake.py
index 10949e7949..d638a3e50b 100644
--- a/lib/spack/spack/build_systems/cmake.py
+++ b/lib/spack/spack/build_systems/cmake.py
@@ -3,7 +3,6 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import collections.abc
-import inspect
import os
import pathlib
import platform
@@ -544,24 +543,24 @@ class CMakeBuilder(BaseBuilder):
options += self.cmake_args()
options.append(os.path.abspath(self.root_cmakelists_dir))
with fs.working_dir(self.build_directory, create=True):
- inspect.getmodule(self.pkg).cmake(*options)
+ pkg.module.cmake(*options)
def build(self, pkg, spec, prefix):
"""Make the build targets"""
with fs.working_dir(self.build_directory):
if self.generator == "Unix Makefiles":
- inspect.getmodule(self.pkg).make(*self.build_targets)
+ pkg.module.make(*self.build_targets)
elif self.generator == "Ninja":
self.build_targets.append("-v")
- inspect.getmodule(self.pkg).ninja(*self.build_targets)
+ pkg.module.ninja(*self.build_targets)
def install(self, pkg, spec, prefix):
"""Make the install targets"""
with fs.working_dir(self.build_directory):
if self.generator == "Unix Makefiles":
- inspect.getmodule(self.pkg).make(*self.install_targets)
+ pkg.module.make(*self.install_targets)
elif self.generator == "Ninja":
- inspect.getmodule(self.pkg).ninja(*self.install_targets)
+ pkg.module.ninja(*self.install_targets)
spack.builder.run_after("build")(execute_build_time_tests)
diff --git a/lib/spack/spack/build_systems/go.py b/lib/spack/spack/build_systems/go.py
index a22d3922e8..8bddd7548e 100644
--- a/lib/spack/spack/build_systems/go.py
+++ b/lib/spack/spack/build_systems/go.py
@@ -3,8 +3,6 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
-
import llnl.util.filesystem as fs
import spack.builder
@@ -82,7 +80,7 @@ class GoBuilder(BaseBuilder):
def build(self, pkg, spec, prefix):
"""Runs ``go build`` in the source directory"""
with fs.working_dir(self.build_directory):
- inspect.getmodule(pkg).go("build", *self.build_args)
+ pkg.module.go("build", *self.build_args)
def install(self, pkg, spec, prefix):
"""Install built binaries into prefix bin."""
@@ -95,4 +93,4 @@ class GoBuilder(BaseBuilder):
def check(self):
"""Run ``go test .`` in the source directory"""
with fs.working_dir(self.build_directory):
- inspect.getmodule(self.pkg).go("test", *self.check_args)
+ self.pkg.module.go("test", *self.check_args)
diff --git a/lib/spack/spack/build_systems/makefile.py b/lib/spack/spack/build_systems/makefile.py
index 915f71d332..25f25adfe3 100644
--- a/lib/spack/spack/build_systems/makefile.py
+++ b/lib/spack/spack/build_systems/makefile.py
@@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
from typing import List
import llnl.util.filesystem as fs
@@ -103,12 +102,12 @@ class MakefileBuilder(BaseBuilder):
def build(self, pkg, spec, prefix):
"""Run "make" on the build targets specified by the builder."""
with fs.working_dir(self.build_directory):
- inspect.getmodule(self.pkg).make(*self.build_targets)
+ pkg.module.make(*self.build_targets)
def install(self, pkg, spec, prefix):
"""Run "make" on the install targets specified by the builder."""
with fs.working_dir(self.build_directory):
- inspect.getmodule(self.pkg).make(*self.install_targets)
+ pkg.module.make(*self.install_targets)
spack.builder.run_after("build")(execute_build_time_tests)
diff --git a/lib/spack/spack/build_systems/meson.py b/lib/spack/spack/build_systems/meson.py
index 2c2bc0d1a0..cf3cd24e20 100644
--- a/lib/spack/spack/build_systems/meson.py
+++ b/lib/spack/spack/build_systems/meson.py
@@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
import os
from typing import List
@@ -195,19 +194,19 @@ class MesonBuilder(BaseBuilder):
options += self.std_meson_args
options += self.meson_args()
with fs.working_dir(self.build_directory, create=True):
- inspect.getmodule(self.pkg).meson(*options)
+ pkg.module.meson(*options)
def build(self, pkg, spec, prefix):
"""Make the build targets"""
options = ["-v"]
options += self.build_targets
with fs.working_dir(self.build_directory):
- inspect.getmodule(self.pkg).ninja(*options)
+ pkg.module.ninja(*options)
def install(self, pkg, spec, prefix):
"""Make the install targets"""
with fs.working_dir(self.build_directory):
- inspect.getmodule(self.pkg).ninja(*self.install_targets)
+ pkg.module.ninja(*self.install_targets)
spack.builder.run_after("build")(execute_build_time_tests)
diff --git a/lib/spack/spack/build_systems/msbuild.py b/lib/spack/spack/build_systems/msbuild.py
index 0edc49b880..8fb4ef936e 100644
--- a/lib/spack/spack/build_systems/msbuild.py
+++ b/lib/spack/spack/build_systems/msbuild.py
@@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
from typing import List # novm
import llnl.util.filesystem as fs
@@ -104,7 +103,7 @@ class MSBuildBuilder(BaseBuilder):
def build(self, pkg, spec, prefix):
"""Run "msbuild" on the build targets specified by the builder."""
with fs.working_dir(self.build_directory):
- inspect.getmodule(self.pkg).msbuild(
+ pkg.module.msbuild(
*self.std_msbuild_args,
*self.msbuild_args(),
self.define_targets(*self.build_targets),
@@ -114,6 +113,6 @@ class MSBuildBuilder(BaseBuilder):
"""Run "msbuild" on the install targets specified by the builder.
This is INSTALL by default"""
with fs.working_dir(self.build_directory):
- inspect.getmodule(self.pkg).msbuild(
+ pkg.module.msbuild(
*self.msbuild_install_args(), self.define_targets(*self.install_targets)
)
diff --git a/lib/spack/spack/build_systems/nmake.py b/lib/spack/spack/build_systems/nmake.py
index d378d62336..50232f3e2d 100644
--- a/lib/spack/spack/build_systems/nmake.py
+++ b/lib/spack/spack/build_systems/nmake.py
@@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
from typing import List # novm
import llnl.util.filesystem as fs
@@ -132,9 +131,7 @@ class NMakeBuilder(BaseBuilder):
if self.makefile_name:
opts.append("/F{}".format(self.makefile_name))
with fs.working_dir(self.build_directory):
- inspect.getmodule(self.pkg).nmake(
- *opts, *self.build_targets, ignore_quotes=self.ignore_quotes
- )
+ pkg.module.nmake(*opts, *self.build_targets, ignore_quotes=self.ignore_quotes)
def install(self, pkg, spec, prefix):
"""Run "nmake" on the install targets specified by the builder.
@@ -146,6 +143,4 @@ class NMakeBuilder(BaseBuilder):
opts.append("/F{}".format(self.makefile_name))
opts.append(self.define("PREFIX", fs.windows_sfn(prefix)))
with fs.working_dir(self.build_directory):
- inspect.getmodule(self.pkg).nmake(
- *opts, *self.install_targets, ignore_quotes=self.ignore_quotes
- )
+ pkg.module.nmake(*opts, *self.install_targets, ignore_quotes=self.ignore_quotes)
diff --git a/lib/spack/spack/build_systems/octave.py b/lib/spack/spack/build_systems/octave.py
index 64958ce941..1b0a88c6e7 100644
--- a/lib/spack/spack/build_systems/octave.py
+++ b/lib/spack/spack/build_systems/octave.py
@@ -2,8 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
-
import spack.builder
import spack.package_base
from spack.directives import build_system, extends
@@ -47,7 +45,7 @@ class OctaveBuilder(BaseBuilder):
def install(self, pkg, spec, prefix):
"""Install the package from the archive file"""
- inspect.getmodule(self.pkg).octave(
+ pkg.module.octave(
"--quiet",
"--norc",
"--built-in-docstrings-file=/dev/null",
diff --git a/lib/spack/spack/build_systems/perl.py b/lib/spack/spack/build_systems/perl.py
index 773a6a98e6..4caab7131b 100644
--- a/lib/spack/spack/build_systems/perl.py
+++ b/lib/spack/spack/build_systems/perl.py
@@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
import os
from typing import Iterable
@@ -134,7 +133,7 @@ class PerlBuilder(BaseBuilder):
def build_executable(self):
"""Returns the executable method to build the perl package"""
if self.build_method == "Makefile.PL":
- build_executable = inspect.getmodule(self.pkg).make
+ build_executable = self.pkg.module.make
elif self.build_method == "Build.PL":
build_executable = Executable(os.path.join(self.pkg.stage.source_path, "Build"))
return build_executable
@@ -158,7 +157,7 @@ class PerlBuilder(BaseBuilder):
options = ["Build.PL", "--install_base", prefix]
options += self.configure_args()
- inspect.getmodule(self.pkg).perl(*options)
+ pkg.module.perl(*options)
# It is possible that the shebang in the Build script that is created from
# Build.PL may be too long causing the build to fail. Patching the shebang
diff --git a/lib/spack/spack/build_systems/python.py b/lib/spack/spack/build_systems/python.py
index 969d5f5b03..bd0c57520c 100644
--- a/lib/spack/spack/build_systems/python.py
+++ b/lib/spack/spack/build_systems/python.py
@@ -4,7 +4,6 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import functools
-import inspect
import operator
import os
import re
@@ -228,7 +227,7 @@ class PythonExtension(spack.package_base.PackageBase):
# Make sure we are importing the installed modules,
# not the ones in the source directory
- python = inspect.getmodule(self).python # type: ignore[union-attr]
+ python = self.module.python
for module in self.import_modules:
with test_part(
self,
diff --git a/lib/spack/spack/build_systems/qmake.py b/lib/spack/spack/build_systems/qmake.py
index a1e679b50c..75ad3860b4 100644
--- a/lib/spack/spack/build_systems/qmake.py
+++ b/lib/spack/spack/build_systems/qmake.py
@@ -2,8 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
-
from llnl.util.filesystem import working_dir
import spack.builder
@@ -66,17 +64,17 @@ class QMakeBuilder(BaseBuilder):
def qmake(self, pkg, spec, prefix):
"""Run ``qmake`` to configure the project and generate a Makefile."""
with working_dir(self.build_directory):
- inspect.getmodule(self.pkg).qmake(*self.qmake_args())
+ pkg.module.qmake(*self.qmake_args())
def build(self, pkg, spec, prefix):
"""Make the build targets"""
with working_dir(self.build_directory):
- inspect.getmodule(self.pkg).make()
+ pkg.module.make()
def install(self, pkg, spec, prefix):
"""Make the install targets"""
with working_dir(self.build_directory):
- inspect.getmodule(self.pkg).make("install")
+ pkg.module.make("install")
def check(self):
"""Search the Makefile for a ``check:`` target and runs it if found."""
diff --git a/lib/spack/spack/build_systems/r.py b/lib/spack/spack/build_systems/r.py
index 5154f5a42d..9950d67048 100644
--- a/lib/spack/spack/build_systems/r.py
+++ b/lib/spack/spack/build_systems/r.py
@@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
from typing import Optional, Tuple
import llnl.util.lang as lang
@@ -51,7 +50,7 @@ class RBuilder(GenericBuilder):
args.extend(["--library={0}".format(self.pkg.module.r_lib_dir), self.stage.source_path])
- inspect.getmodule(self.pkg).R(*args)
+ pkg.module.R(*args)
class RPackage(Package):
diff --git a/lib/spack/spack/build_systems/ruby.py b/lib/spack/spack/build_systems/ruby.py
index 0f069e99f2..77d7ef289c 100644
--- a/lib/spack/spack/build_systems/ruby.py
+++ b/lib/spack/spack/build_systems/ruby.py
@@ -3,7 +3,6 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import glob
-import inspect
import spack.builder
import spack.package_base
@@ -52,10 +51,10 @@ class RubyBuilder(BaseBuilder):
gemspecs = glob.glob("*.gemspec")
rakefiles = glob.glob("Rakefile")
if gemspecs:
- inspect.getmodule(self.pkg).gem("build", "--norc", gemspecs[0])
+ pkg.module.gem("build", "--norc", gemspecs[0])
elif rakefiles:
- jobs = inspect.getmodule(self.pkg).make_jobs
- inspect.getmodule(self.pkg).rake("package", "-j{0}".format(jobs))
+ jobs = pkg.module.make_jobs
+ pkg.module.rake("package", "-j{0}".format(jobs))
else:
# Some Ruby packages only ship `*.gem` files, so nothing to build
pass
@@ -70,6 +69,6 @@ class RubyBuilder(BaseBuilder):
# if --install-dir is not used, GEM_PATH is deleted from the
# environement, and Gems required to build native extensions will
# not be found. Those extensions are built during `gem install`.
- inspect.getmodule(self.pkg).gem(
+ pkg.module.gem(
"install", "--norc", "--ignore-dependencies", "--install-dir", prefix, gems[0]
)
diff --git a/lib/spack/spack/build_systems/scons.py b/lib/spack/spack/build_systems/scons.py
index 0d2ea175a1..4a32b690f7 100644
--- a/lib/spack/spack/build_systems/scons.py
+++ b/lib/spack/spack/build_systems/scons.py
@@ -2,8 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
-
import spack.builder
import spack.package_base
from spack.directives import build_system, depends_on
@@ -63,8 +61,7 @@ class SConsBuilder(BaseBuilder):
def build(self, pkg, spec, prefix):
"""Build the package."""
- args = self.build_args(spec, prefix)
- inspect.getmodule(self.pkg).scons(*args)
+ pkg.module.scons(*self.build_args(spec, prefix))
def install_args(self, spec, prefix):
"""Arguments to pass to install."""
@@ -72,9 +69,7 @@ class SConsBuilder(BaseBuilder):
def install(self, pkg, spec, prefix):
"""Install the package."""
- args = self.install_args(spec, prefix)
-
- inspect.getmodule(self.pkg).scons("install", *args)
+ pkg.module.scons("install", *self.install_args(spec, prefix))
def build_test(self):
"""Run unit tests after build.
diff --git a/lib/spack/spack/build_systems/sip.py b/lib/spack/spack/build_systems/sip.py
index f1263c12a6..f297c59a00 100644
--- a/lib/spack/spack/build_systems/sip.py
+++ b/lib/spack/spack/build_systems/sip.py
@@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
import os
import re
@@ -86,14 +85,13 @@ class SIPPackage(spack.package_base.PackageBase):
def python(self, *args, **kwargs):
"""The python ``Executable``."""
- inspect.getmodule(self).python(*args, **kwargs)
+ self.pkg.module.python(*args, **kwargs)
def test_imports(self):
"""Attempts to import modules of the installed package."""
# Make sure we are importing the installed modules,
# not the ones in the source directory
- python = inspect.getmodule(self).python
for module in self.import_modules:
with spack.install_test.test_part(
self,
@@ -101,7 +99,7 @@ class SIPPackage(spack.package_base.PackageBase):
purpose="checking import of {0}".format(module),
work_dir="spack-test",
):
- python("-c", "import {0}".format(module))
+ self.python("-c", "import {0}".format(module))
@spack.builder.builder("sip")
@@ -136,7 +134,7 @@ class SIPBuilder(BaseBuilder):
"""Configure the package."""
# https://www.riverbankcomputing.com/static/Docs/sip/command_line_tools.html
- args = ["--verbose", "--target-dir", inspect.getmodule(self.pkg).python_platlib]
+ args = ["--verbose", "--target-dir", pkg.module.python_platlib]
args.extend(self.configure_args())
# https://github.com/Python-SIP/sip/commit/cb0be6cb6e9b756b8b0db3136efb014f6fb9b766
@@ -155,7 +153,7 @@ class SIPBuilder(BaseBuilder):
args = self.build_args()
with working_dir(self.build_directory):
- inspect.getmodule(self.pkg).make(*args)
+ pkg.module.make(*args)
def build_args(self):
"""Arguments to pass to build."""
@@ -166,7 +164,7 @@ class SIPBuilder(BaseBuilder):
args = self.install_args()
with working_dir(self.build_directory):
- inspect.getmodule(self.pkg).make("install", *args)
+ pkg.module.make("install", *args)
def install_args(self):
"""Arguments to pass to install."""
diff --git a/lib/spack/spack/build_systems/waf.py b/lib/spack/spack/build_systems/waf.py
index 0fd78d48da..a0110c5c34 100644
--- a/lib/spack/spack/build_systems/waf.py
+++ b/lib/spack/spack/build_systems/waf.py
@@ -2,8 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
-
from llnl.util.filesystem import working_dir
import spack.builder
@@ -90,11 +88,11 @@ class WafBuilder(BaseBuilder):
def python(self, *args, **kwargs):
"""The python ``Executable``."""
- inspect.getmodule(self.pkg).python(*args, **kwargs)
+ self.pkg.module.python(*args, **kwargs)
def waf(self, *args, **kwargs):
"""Runs the waf ``Executable``."""
- jobs = inspect.getmodule(self.pkg).make_jobs
+ jobs = self.pkg.module.make_jobs
with working_dir(self.build_directory):
self.python("waf", "-j{0}".format(jobs), *args, **kwargs)
diff --git a/lib/spack/spack/builder.py b/lib/spack/spack/builder.py
index 2f947335a8..7590016c33 100644
--- a/lib/spack/spack/builder.py
+++ b/lib/spack/spack/builder.py
@@ -6,7 +6,6 @@ import collections
import collections.abc
import copy
import functools
-import inspect
from typing import List, Optional, Tuple
from llnl.util import lang
@@ -97,11 +96,10 @@ def _create(pkg):
Args:
pkg (spack.package_base.PackageBase): package object for which we need a builder
"""
- package_module = inspect.getmodule(pkg)
package_buildsystem = buildsystem_name(pkg)
default_builder_cls = BUILDER_CLS[package_buildsystem]
builder_cls_name = default_builder_cls.__name__
- builder_cls = getattr(package_module, builder_cls_name, None)
+ builder_cls = getattr(pkg.module, builder_cls_name, None)
if builder_cls:
return builder_cls(pkg)
diff --git a/lib/spack/spack/package_base.py b/lib/spack/spack/package_base.py
index 681b079706..65c9e856bb 100644
--- a/lib/spack/spack/package_base.py
+++ b/lib/spack/spack/package_base.py
@@ -16,7 +16,6 @@ import functools
import glob
import hashlib
import importlib
-import inspect
import io
import os
import re
@@ -1744,7 +1743,7 @@ class PackageBase(WindowsRPath, PackageViewMixin, RedistributionMixin, metaclass
bool: True if 'target' is found, else False
"""
# Prevent altering LC_ALL for 'make' outside this function
- make = copy.deepcopy(inspect.getmodule(self).make)
+ make = copy.deepcopy(self.module.make)
# Use English locale for missing target message comparison
make.add_default_env("LC_ALL", "C")
@@ -1794,7 +1793,7 @@ class PackageBase(WindowsRPath, PackageViewMixin, RedistributionMixin, metaclass
"""
if self._has_make_target(target):
# Execute target
- inspect.getmodule(self).make(target, *args, **kwargs)
+ self.module.make(target, *args, **kwargs)
def _has_ninja_target(self, target):
"""Checks to see if 'target' is a valid target in a Ninja build script.
@@ -1805,7 +1804,7 @@ class PackageBase(WindowsRPath, PackageViewMixin, RedistributionMixin, metaclass
Returns:
bool: True if 'target' is found, else False
"""
- ninja = inspect.getmodule(self).ninja
+ ninja = self.module.ninja
# Check if we have a Ninja build script
if not os.path.exists("build.ninja"):
@@ -1834,7 +1833,7 @@ class PackageBase(WindowsRPath, PackageViewMixin, RedistributionMixin, metaclass
"""
if self._has_ninja_target(target):
# Execute target
- inspect.getmodule(self).ninja(target, *args, **kwargs)
+ self.module.ninja(target, *args, **kwargs)
def _get_needed_resources(self):
# We use intersects here cause it would also work if self.spec is abstract
diff --git a/lib/spack/spack/test/build_environment.py b/lib/spack/spack/test/build_environment.py
index 3d3bbf27cd..3ae41acc9c 100644
--- a/lib/spack/spack/test/build_environment.py
+++ b/lib/spack/spack/test/build_environment.py
@@ -592,7 +592,7 @@ class TestModuleMonkeyPatcher:
# We can also propagate the settings to classes in the MRO
module_wrapper.propagate_changes_to_mro()
- for cls in type(s.package).__mro__:
+ for cls in s.package.__class__.__mro__:
current_module = cls.module
if current_module == spack.package_base:
break
diff --git a/lib/spack/spack/test/concretize.py b/lib/spack/spack/test/concretize.py
index 66ae350bcd..eaef82930d 100644
--- a/lib/spack/spack/test/concretize.py
+++ b/lib/spack/spack/test/concretize.py
@@ -775,15 +775,15 @@ class TestConcretize:
s = Spec("mpileaks")
s.concretize()
- assert llnl.util.lang.ObjectWrapper not in type(s).__mro__
+ assert llnl.util.lang.ObjectWrapper not in s.__class__.__mro__
# Spec wrapped in a build interface
build_interface = s["mpileaks"]
- assert llnl.util.lang.ObjectWrapper in type(build_interface).__mro__
+ assert llnl.util.lang.ObjectWrapper in build_interface.__class__.__mro__
# Mimics asking the build interface from a build interface
build_interface = s["mpileaks"]["mpileaks"]
- assert llnl.util.lang.ObjectWrapper in type(build_interface).__mro__
+ assert llnl.util.lang.ObjectWrapper in build_interface.__class__.__mro__
@pytest.mark.regression("7705")
def test_regression_issue_7705(self):
diff --git a/var/spack/repos/builtin/packages/evtgen/package.py b/var/spack/repos/builtin/packages/evtgen/package.py
index 093f029ab8..41a44bad54 100644
--- a/var/spack/repos/builtin/packages/evtgen/package.py
+++ b/var/spack/repos/builtin/packages/evtgen/package.py
@@ -97,7 +97,7 @@ class Evtgen(CMakePackage):
options += self.configure_args()
with working_dir(self.build_directory, create=True):
- inspect.getmodule(self).configure(*options)
+ configure(*options)
@when("@:01")
def configure_args(self):
diff --git a/var/spack/repos/builtin/packages/fjcontrib/package.py b/var/spack/repos/builtin/packages/fjcontrib/package.py
index a7acaa64c0..2563359dd9 100644
--- a/var/spack/repos/builtin/packages/fjcontrib/package.py
+++ b/var/spack/repos/builtin/packages/fjcontrib/package.py
@@ -3,8 +3,6 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
-
from spack.package import *
@@ -87,9 +85,9 @@ class Fjcontrib(AutotoolsPackage):
def build(self, spec, prefix):
with working_dir(self.build_directory):
for target in self.build_targets:
- inspect.getmodule(self).make(target)
+ make(target)
def install(self, spec, prefix):
with working_dir(self.build_directory):
for target in self.install_targets:
- inspect.getmodule(self).make(target)
+ make(target)
diff --git a/var/spack/repos/builtin/packages/grackle/package.py b/var/spack/repos/builtin/packages/grackle/package.py
index e87b2ef93e..a859ab4ad1 100644
--- a/var/spack/repos/builtin/packages/grackle/package.py
+++ b/var/spack/repos/builtin/packages/grackle/package.py
@@ -3,7 +3,6 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
import os.path
from spack.package import *
@@ -51,9 +50,7 @@ class Grackle(Package):
"@LINK_VARIABLES_DEFINITION": link_variables,
}
- template = join_path(
- os.path.dirname(inspect.getmodule(self).__file__), "Make.mach.template"
- )
+ template = join_path(os.path.dirname(__file__), "Make.mach.template")
makefile = join_path(
self.stage.source_path, "src", "clib", "Make.mach.{0}".format(grackle_architecture)
)
diff --git a/var/spack/repos/builtin/packages/intel-tbb/package.py b/var/spack/repos/builtin/packages/intel-tbb/package.py
index 7e1bff25ab..d3c6e9fef9 100644
--- a/var/spack/repos/builtin/packages/intel-tbb/package.py
+++ b/var/spack/repos/builtin/packages/intel-tbb/package.py
@@ -4,7 +4,6 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import glob
-import inspect
import platform
import sys
@@ -316,14 +315,13 @@ class MakefileBuilder(spack.build_systems.makefile.MakefileBuilder, SetupEnviron
if spec.satisfies("@2017.8,2018.1:"):
# Generate and install the CMake Config file.
- cmake_args = (
- "-DTBB_ROOT={0}".format(prefix),
- "-DTBB_OS={0}".format(platform.system()),
- "-P",
- "tbb_config_generator.cmake",
- )
with working_dir(join_path(self.stage.source_path, "cmake")):
- inspect.getmodule(self).cmake(*cmake_args)
+ cmake(
+ f"-DTBB_ROOT={prefix}",
+ f"-DTBB_OS={platform.system()}",
+ "-P",
+ "tbb_config_generator.cmake",
+ )
@run_after("install")
def darwin_fix(self):
diff --git a/var/spack/repos/builtin/packages/lorene/package.py b/var/spack/repos/builtin/packages/lorene/package.py
index 76ad46d1e1..685495d902 100644
--- a/var/spack/repos/builtin/packages/lorene/package.py
+++ b/var/spack/repos/builtin/packages/lorene/package.py
@@ -3,7 +3,6 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
import os
from spack.package import *
@@ -80,9 +79,7 @@ class Lorene(MakefilePackage):
("@LIB_LAPACK@", lapack_libs + " " + blas_libs),
("@LIB_PGPLOT@", pgplot_libdirs + " " + pgplot_libs),
]
- local_settings_template = join_path(
- os.path.dirname(inspect.getmodule(self).__file__), "local_settings.template"
- )
+ local_settings_template = join_path(os.path.dirname(__file__), "local_settings.template")
local_settings = join_path(self.stage.source_path, "local_settings")
copy(local_settings_template, local_settings)
for key, value in substitutions:
diff --git a/var/spack/repos/builtin/packages/ollama/package.py b/var/spack/repos/builtin/packages/ollama/package.py
index 8213efdebc..98a171998f 100644
--- a/var/spack/repos/builtin/packages/ollama/package.py
+++ b/var/spack/repos/builtin/packages/ollama/package.py
@@ -49,9 +49,5 @@ class GoBuilder(spack.build_systems.go.GoBuilder):
def generate(self, pkg, spec, prefix):
"""Runs ``go generate`` in the source directory"""
- import inspect
-
- import llnl.util.filesystem as fs
-
- with fs.working_dir(self.build_directory):
- inspect.getmodule(pkg).go("generate", *self.generate_args)
+ with working_dir(self.build_directory):
+ go("generate", *self.generate_args)
diff --git a/var/spack/repos/builtin/packages/perl-bioperl/package.py b/var/spack/repos/builtin/packages/perl-bioperl/package.py
index ddbcc265b6..790446ad91 100644
--- a/var/spack/repos/builtin/packages/perl-bioperl/package.py
+++ b/var/spack/repos/builtin/packages/perl-bioperl/package.py
@@ -3,8 +3,6 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
-
from spack.package import *
@@ -105,7 +103,7 @@ class PerlBioperl(PerlPackage):
f.writelines(config_answers)
with open(config_answers_filename, "r") as f:
- inspect.getmodule(self).perl("Build.PL", "--install_base=%s" % self.prefix, input=f)
+ perl("Build.PL", "--install_base=%s" % self.prefix, input=f)
# Need to also override the build and install methods to make sure that the
# Build script is run through perl and not use the shebang, as it might be
@@ -113,8 +111,8 @@ class PerlBioperl(PerlPackage):
# `@run_after(configure)` step defined in `PerlPackage`.
@when("@1.007002")
def build(self, spec, prefix):
- inspect.getmodule(self).perl("Build")
+ perl("Build")
@when("@1.007002")
def install(self, spec, prefix):
- inspect.getmodule(self).perl("Build", "install")
+ perl("Build", "install")
diff --git a/var/spack/repos/builtin/packages/perl-io-socket-ssl/package.py b/var/spack/repos/builtin/packages/perl-io-socket-ssl/package.py
index 143360fd20..08e6aa2117 100644
--- a/var/spack/repos/builtin/packages/perl-io-socket-ssl/package.py
+++ b/var/spack/repos/builtin/packages/perl-io-socket-ssl/package.py
@@ -3,8 +3,6 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
-
from spack.package import *
@@ -23,7 +21,7 @@ class PerlIoSocketSsl(PerlPackage):
def configure(self, spec, prefix):
self.build_method = "Makefile.PL"
- self.build_executable = inspect.getmodule(self).make
+ self.build_executable = make
# Should I do external tests?
config_answers = ["n\n"]
config_answers_filename = "spack-config.in"
@@ -32,4 +30,4 @@ class PerlIoSocketSsl(PerlPackage):
f.writelines(config_answers)
with open(config_answers_filename, "r") as f:
- inspect.getmodule(self).perl("Makefile.PL", f"INSTALL_BASE={prefix}", input=f)
+ perl("Makefile.PL", f"INSTALL_BASE={prefix}", input=f)
diff --git a/var/spack/repos/builtin/packages/perl-net-ssleay/package.py b/var/spack/repos/builtin/packages/perl-net-ssleay/package.py
index f03f030f00..03d27156da 100644
--- a/var/spack/repos/builtin/packages/perl-net-ssleay/package.py
+++ b/var/spack/repos/builtin/packages/perl-net-ssleay/package.py
@@ -3,8 +3,6 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
-
from spack.package import *
@@ -25,7 +23,7 @@ class PerlNetSsleay(PerlPackage):
def configure(self, spec, prefix):
self.build_method = "Makefile.PL"
- self.build_executable = inspect.getmodule(self).make
+ self.build_executable = make
# Do you want to run external tests?
config_answers = ["\n"]
config_answers_filename = "spack-config.in"
@@ -35,4 +33,4 @@ class PerlNetSsleay(PerlPackage):
with open(config_answers_filename, "r") as f:
env["OPENSSL_PREFIX"] = self.spec["openssl"].prefix
- inspect.getmodule(self).perl("Makefile.PL", "INSTALL_BASE={0}".format(prefix), input=f)
+ perl("Makefile.PL", "INSTALL_BASE={0}".format(prefix), input=f)
diff --git a/var/spack/repos/builtin/packages/pexsi/package.py b/var/spack/repos/builtin/packages/pexsi/package.py
index b8ef54bc26..04d1350d5e 100644
--- a/var/spack/repos/builtin/packages/pexsi/package.py
+++ b/var/spack/repos/builtin/packages/pexsi/package.py
@@ -3,9 +3,6 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
-import os.path
-
import spack.build_systems.cmake
import spack.build_systems.makefile
from spack.package import *
@@ -94,7 +91,7 @@ class MakefileBuilder(spack.build_systems.makefile.MakefileBuilder):
substitutions.append(("@FLDFLAGS", fldflags.lstrip()))
- template = join_path(os.path.dirname(inspect.getmodule(self).__file__), "make.inc")
+ template = join_path(os.path.dirname(__file__), "make.inc")
makefile = join_path(pkg.stage.source_path, "make.inc")
copy(template, makefile)
for key, value in substitutions:
diff --git a/var/spack/repos/builtin/packages/wannier90/package.py b/var/spack/repos/builtin/packages/wannier90/package.py
index 54f0f7f6d1..417cdc38f7 100644
--- a/var/spack/repos/builtin/packages/wannier90/package.py
+++ b/var/spack/repos/builtin/packages/wannier90/package.py
@@ -3,7 +3,6 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import inspect
import os.path
from spack.package import *
@@ -80,7 +79,7 @@ class Wannier90(MakefilePackage):
"@LIBS": (lapack + blas + mpi).joined(),
}
- template = join_path(os.path.dirname(inspect.getmodule(self).__file__), "make.sys")
+ template = join_path(os.path.dirname(__file__), "make.sys")
copy(template, self.makefile_name)
for key, value in substitutions.items():