Compare commits

...

3 Commits

Author SHA1 Message Date
Harmen Stoppels
dd9e28a621 simplify mro stuff 2024-08-30 15:07:33 +02:00
Harmen Stoppels
3d827b0ea5 build_systems: use pkg.module 2024-08-28 14:58:09 +02:00
Harmen Stoppels
45ec04ef7c builtin: remove redundant use of inspec 2024-08-28 14:58:09 +02:00
33 changed files with 94 additions and 175 deletions

View File

@ -555,7 +555,7 @@ def set_package_py_globals(pkg, context: Context = Context.BUILD):
"""Populate the Python module of a package with some useful global names. """Populate the Python module of a package with some useful global names.
This makes things easier for package writers. This makes things easier for package writers.
""" """
module = ModuleChangePropagator(pkg) module = SetPackageGlobals(pkg)
if context == Context.BUILD: if context == Context.BUILD:
module.std_cmake_args = spack.build_systems.cmake.CMakeBuilder.std_args(pkg) module.std_cmake_args = spack.build_systems.cmake.CMakeBuilder.std_args(pkg)
@ -1016,7 +1016,7 @@ def set_all_package_py_globals(self):
# setting globals for those. # setting globals for those.
if id(spec) not in self.nodes_in_subdag: if id(spec) not in self.nodes_in_subdag:
continue continue
dependent_module = ModuleChangePropagator(spec.package) dependent_module = SetPackageGlobals(spec.package)
pkg.setup_dependent_package(dependent_module, spec) pkg.setup_dependent_package(dependent_module, spec)
dependent_module.propagate_changes_to_mro() dependent_module.propagate_changes_to_mro()
@ -1543,7 +1543,7 @@ def write_log_summary(out, log_type, log, last=None):
out.write(make_log_context(warnings)) out.write(make_log_context(warnings))
class ModuleChangePropagator: class SetPackageGlobals:
"""Wrapper class to accept changes to a package.py Python module, and propagate them in the """Wrapper class to accept changes to a package.py Python module, and propagate them in the
MRO of the package. MRO of the package.
@ -1551,41 +1551,22 @@ class ModuleChangePropagator:
"setup_dependent_package" function during build environment setup. "setup_dependent_package" function during build environment setup.
""" """
_PROTECTED_NAMES = ("package", "current_module", "modules_in_mro", "_set_attributes") def __init__(self, package: spack.package_base.PackageBase) -> None:
def __init__(self, package):
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 for the classes in the MRO up to PackageBase
modules_in_mro = [] modules_in_mro = []
for cls in type(package).__mro__: for cls in package.__class__.__mro__:
module = cls.module module = getattr(cls, "module", None)
if module is None or module is spack.package_base:
if module == self.current_module:
continue
if module == spack.package_base:
break break
modules_in_mro.append(module) modules_in_mro.append(module)
self._set_self_attributes("modules_in_mro", modules_in_mro)
self._set_self_attributes("_set_attributes", {})
def _set_self_attributes(self, key, value): super().__setattr__("modules_in_mro", modules_in_mro)
super().__setattr__(key, value)
def __getattr__(self, item): def __getattr__(self, item):
return getattr(self.current_module, item) return getattr(self.modules_in_mro[0], item)
def __setattr__(self, key, value): def __setattr__(self, key, value):
if key in ModuleChangePropagator._PROTECTED_NAMES: if key == "modules_in_mro":
msg = f'Cannot set attribute "{key}" in ModuleMonkeyPatcher' raise AttributeError(f'Cannot set attribute "{key}" in ModuleMonkeyPatcher')
return AttributeError(msg) for module in self.modules_in_mro:
setattr(module, key, value)
setattr(self.current_module, key, value)
self._set_attributes[key] = value
def propagate_changes_to_mro(self):
for module_in_mro in self.modules_in_mro:
module_in_mro.__dict__.update(self._set_attributes)

View File

@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
import os import os
import os.path import os.path
import stat import stat
@ -15,6 +14,7 @@
import spack.build_environment import spack.build_environment
import spack.builder import spack.builder
import spack.package_base import spack.package_base
from spack.build_environment import SetPackageGlobals
from spack.directives import build_system, conflicts, depends_on from spack.directives import build_system, conflicts, depends_on
from spack.multimethod import when from spack.multimethod import when
from spack.operating_systems.mac_os import macos_version from spack.operating_systems.mac_os import macos_version
@ -549,13 +549,12 @@ def autoreconf(self, pkg, spec, prefix):
tty.warn("* a custom AUTORECONF phase in the package *") tty.warn("* a custom AUTORECONF phase in the package *")
tty.warn("*********************************************************") tty.warn("*********************************************************")
with fs.working_dir(self.configure_directory): with fs.working_dir(self.configure_directory):
m = inspect.getmodule(self.pkg)
# This line is what is needed most of the time # This line is what is needed most of the time
# --install, --verbose, --force # --install, --verbose, --force
autoreconf_args = ["-ivf"] autoreconf_args = ["-ivf"]
autoreconf_args += self.autoreconf_search_path_args autoreconf_args += self.autoreconf_search_path_args
autoreconf_args += self.autoreconf_extra_args autoreconf_args += self.autoreconf_extra_args
m.autoreconf(*autoreconf_args) self.pkg.module.autoreconf(*autoreconf_args)
@property @property
def autoreconf_search_path_args(self): def autoreconf_search_path_args(self):
@ -579,7 +578,7 @@ def set_configure_or_die(self):
raise RuntimeError(msg.format(self.configure_directory)) raise RuntimeError(msg.format(self.configure_directory))
# Monkey-patch the configure script in the corresponding module # Monkey-patch the configure script in the corresponding module
inspect.getmodule(self.pkg).configure = Executable(self.configure_abs_path) SetPackageGlobals(self.pkg).configure = Executable(self.configure_abs_path)
def configure_args(self): def configure_args(self):
"""Return the list of all the arguments that must be passed to configure, """Return the list of all the arguments that must be passed to configure,
@ -596,7 +595,7 @@ def configure(self, pkg, spec, prefix):
options += self.configure_args() options += self.configure_args()
with fs.working_dir(self.build_directory, create=True): 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): def build(self, pkg, spec, prefix):
"""Run "make" on the build targets specified by the builder.""" """Run "make" on the build targets specified by the builder."""
@ -604,12 +603,12 @@ def build(self, pkg, spec, prefix):
params = ["V=1"] params = ["V=1"]
params += self.build_targets params += self.build_targets
with fs.working_dir(self.build_directory): with fs.working_dir(self.build_directory):
inspect.getmodule(self.pkg).make(*params) pkg.module.make(*params)
def install(self, pkg, spec, prefix): def install(self, pkg, spec, prefix):
"""Run "make" on the install targets specified by the builder.""" """Run "make" on the install targets specified by the builder."""
with fs.working_dir(self.build_directory): 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) spack.builder.run_after("build")(execute_build_time_tests)

View File

@ -3,8 +3,6 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
import llnl.util.filesystem as fs import llnl.util.filesystem as fs
import spack.builder import spack.builder
@ -72,9 +70,7 @@ def check_args(self):
def build(self, pkg, spec, prefix): def build(self, pkg, spec, prefix):
"""Runs ``cargo install`` in the source directory""" """Runs ``cargo install`` in the source directory"""
with fs.working_dir(self.build_directory): with fs.working_dir(self.build_directory):
inspect.getmodule(pkg).cargo( pkg.module.cargo("install", "--root", "out", "--path", ".", *self.build_args)
"install", "--root", "out", "--path", ".", *self.build_args
)
def install(self, pkg, spec, prefix): def install(self, pkg, spec, prefix):
"""Copy build files into package prefix.""" """Copy build files into package prefix."""
@ -86,4 +82,4 @@ def install(self, pkg, spec, prefix):
def check(self): def check(self):
"""Run "cargo test".""" """Run "cargo test"."""
with fs.working_dir(self.build_directory): with fs.working_dir(self.build_directory):
inspect.getmodule(self.pkg).cargo("test", *self.check_args) self.pkg.module.cargo("test", *self.check_args)

View File

@ -3,7 +3,6 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import collections.abc import collections.abc
import inspect
import os import os
import pathlib import pathlib
import platform import platform
@ -539,24 +538,24 @@ def cmake(self, pkg, spec, prefix):
options += self.cmake_args() options += self.cmake_args()
options.append(os.path.abspath(self.root_cmakelists_dir)) options.append(os.path.abspath(self.root_cmakelists_dir))
with fs.working_dir(self.build_directory, create=True): 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): def build(self, pkg, spec, prefix):
"""Make the build targets""" """Make the build targets"""
with fs.working_dir(self.build_directory): with fs.working_dir(self.build_directory):
if self.generator == "Unix Makefiles": if self.generator == "Unix Makefiles":
inspect.getmodule(self.pkg).make(*self.build_targets) pkg.module.make(*self.build_targets)
elif self.generator == "Ninja": elif self.generator == "Ninja":
self.build_targets.append("-v") 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): def install(self, pkg, spec, prefix):
"""Make the install targets""" """Make the install targets"""
with fs.working_dir(self.build_directory): with fs.working_dir(self.build_directory):
if self.generator == "Unix Makefiles": if self.generator == "Unix Makefiles":
inspect.getmodule(self.pkg).make(*self.install_targets) pkg.module.make(*self.install_targets)
elif self.generator == "Ninja": 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) spack.builder.run_after("build")(execute_build_time_tests)

View File

@ -3,8 +3,6 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
import llnl.util.filesystem as fs import llnl.util.filesystem as fs
import spack.builder import spack.builder
@ -82,7 +80,7 @@ def check_args(self):
def build(self, pkg, spec, prefix): def build(self, pkg, spec, prefix):
"""Runs ``go build`` in the source directory""" """Runs ``go build`` in the source directory"""
with fs.working_dir(self.build_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): def install(self, pkg, spec, prefix):
"""Install built binaries into prefix bin.""" """Install built binaries into prefix bin."""
@ -95,4 +93,4 @@ def install(self, pkg, spec, prefix):
def check(self): def check(self):
"""Run ``go test .`` in the source directory""" """Run ``go test .`` in the source directory"""
with fs.working_dir(self.build_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)

View File

@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
from typing import List from typing import List
import llnl.util.filesystem as fs import llnl.util.filesystem as fs
@ -103,12 +102,12 @@ def edit(self, pkg, spec, prefix):
def build(self, pkg, spec, prefix): def build(self, pkg, spec, prefix):
"""Run "make" on the build targets specified by the builder.""" """Run "make" on the build targets specified by the builder."""
with fs.working_dir(self.build_directory): 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): def install(self, pkg, spec, prefix):
"""Run "make" on the install targets specified by the builder.""" """Run "make" on the install targets specified by the builder."""
with fs.working_dir(self.build_directory): 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) spack.builder.run_after("build")(execute_build_time_tests)

View File

@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
import os import os
from typing import List from typing import List
@ -195,19 +194,19 @@ def meson(self, pkg, spec, prefix):
options += self.std_meson_args options += self.std_meson_args
options += self.meson_args() options += self.meson_args()
with fs.working_dir(self.build_directory, create=True): 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): def build(self, pkg, spec, prefix):
"""Make the build targets""" """Make the build targets"""
options = ["-v"] options = ["-v"]
options += self.build_targets options += self.build_targets
with fs.working_dir(self.build_directory): with fs.working_dir(self.build_directory):
inspect.getmodule(self.pkg).ninja(*options) pkg.module.ninja(*options)
def install(self, pkg, spec, prefix): def install(self, pkg, spec, prefix):
"""Make the install targets""" """Make the install targets"""
with fs.working_dir(self.build_directory): 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) spack.builder.run_after("build")(execute_build_time_tests)

View File

@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
from typing import List # novm from typing import List # novm
import llnl.util.filesystem as fs import llnl.util.filesystem as fs
@ -104,7 +103,7 @@ def msbuild_install_args(self):
def build(self, pkg, spec, prefix): def build(self, pkg, spec, prefix):
"""Run "msbuild" on the build targets specified by the builder.""" """Run "msbuild" on the build targets specified by the builder."""
with fs.working_dir(self.build_directory): with fs.working_dir(self.build_directory):
inspect.getmodule(self.pkg).msbuild( pkg.module.msbuild(
*self.std_msbuild_args, *self.std_msbuild_args,
*self.msbuild_args(), *self.msbuild_args(),
self.define_targets(*self.build_targets), self.define_targets(*self.build_targets),
@ -114,6 +113,6 @@ def install(self, pkg, spec, prefix):
"""Run "msbuild" on the install targets specified by the builder. """Run "msbuild" on the install targets specified by the builder.
This is INSTALL by default""" This is INSTALL by default"""
with fs.working_dir(self.build_directory): 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) *self.msbuild_install_args(), self.define_targets(*self.install_targets)
) )

View File

@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
from typing import List # novm from typing import List # novm
import llnl.util.filesystem as fs import llnl.util.filesystem as fs
@ -132,9 +131,7 @@ def build(self, pkg, spec, prefix):
if self.makefile_name: if self.makefile_name:
opts.append("/F{}".format(self.makefile_name)) opts.append("/F{}".format(self.makefile_name))
with fs.working_dir(self.build_directory): with fs.working_dir(self.build_directory):
inspect.getmodule(self.pkg).nmake( pkg.module.nmake(*opts, *self.build_targets, ignore_quotes=self.ignore_quotes)
*opts, *self.build_targets, ignore_quotes=self.ignore_quotes
)
def install(self, pkg, spec, prefix): def install(self, pkg, spec, prefix):
"""Run "nmake" on the install targets specified by the builder. """Run "nmake" on the install targets specified by the builder.
@ -146,6 +143,4 @@ def install(self, pkg, spec, prefix):
opts.append("/F{}".format(self.makefile_name)) opts.append("/F{}".format(self.makefile_name))
opts.append(self.define("PREFIX", fs.windows_sfn(prefix))) opts.append(self.define("PREFIX", fs.windows_sfn(prefix)))
with fs.working_dir(self.build_directory): with fs.working_dir(self.build_directory):
inspect.getmodule(self.pkg).nmake( pkg.module.nmake(*opts, *self.install_targets, ignore_quotes=self.ignore_quotes)
*opts, *self.install_targets, ignore_quotes=self.ignore_quotes
)

View File

@ -2,8 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
import spack.builder import spack.builder
import spack.package_base import spack.package_base
from spack.directives import build_system, extends from spack.directives import build_system, extends
@ -47,7 +45,7 @@ class OctaveBuilder(BaseBuilder):
def install(self, pkg, spec, prefix): def install(self, pkg, spec, prefix):
"""Install the package from the archive file""" """Install the package from the archive file"""
inspect.getmodule(self.pkg).octave( pkg.module.octave(
"--quiet", "--quiet",
"--norc", "--norc",
"--built-in-docstrings-file=/dev/null", "--built-in-docstrings-file=/dev/null",

View File

@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
import os import os
from typing import Iterable from typing import Iterable
@ -134,7 +133,7 @@ def build_method(self):
def build_executable(self): def build_executable(self):
"""Returns the executable method to build the perl package""" """Returns the executable method to build the perl package"""
if self.build_method == "Makefile.PL": 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": elif self.build_method == "Build.PL":
build_executable = Executable(os.path.join(self.pkg.stage.source_path, "Build")) build_executable = Executable(os.path.join(self.pkg.stage.source_path, "Build"))
return build_executable return build_executable
@ -158,7 +157,7 @@ def configure(self, pkg, spec, prefix):
options = ["Build.PL", "--install_base", prefix] options = ["Build.PL", "--install_base", prefix]
options += self.configure_args() 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 # 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 # Build.PL may be too long causing the build to fail. Patching the shebang

View File

@ -4,7 +4,6 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import functools import functools
import inspect
import operator import operator
import os import os
import re import re
@ -228,7 +227,7 @@ def test_imports(self) -> None:
# Make sure we are importing the installed modules, # Make sure we are importing the installed modules,
# not the ones in the source directory # 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: for module in self.import_modules:
with test_part( with test_part(
self, self,

View File

@ -2,8 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
from llnl.util.filesystem import working_dir from llnl.util.filesystem import working_dir
import spack.builder import spack.builder
@ -66,17 +64,17 @@ def qmake_args(self):
def qmake(self, pkg, spec, prefix): def qmake(self, pkg, spec, prefix):
"""Run ``qmake`` to configure the project and generate a Makefile.""" """Run ``qmake`` to configure the project and generate a Makefile."""
with working_dir(self.build_directory): 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): def build(self, pkg, spec, prefix):
"""Make the build targets""" """Make the build targets"""
with working_dir(self.build_directory): with working_dir(self.build_directory):
inspect.getmodule(self.pkg).make() pkg.module.make()
def install(self, pkg, spec, prefix): def install(self, pkg, spec, prefix):
"""Make the install targets""" """Make the install targets"""
with working_dir(self.build_directory): with working_dir(self.build_directory):
inspect.getmodule(self.pkg).make("install") pkg.module.make("install")
def check(self): def check(self):
"""Search the Makefile for a ``check:`` target and runs it if found.""" """Search the Makefile for a ``check:`` target and runs it if found."""

View File

@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
from typing import Optional, Tuple from typing import Optional, Tuple
import llnl.util.lang as lang import llnl.util.lang as lang
@ -51,7 +50,7 @@ def install(self, pkg, spec, prefix):
args.extend(["--library={0}".format(self.pkg.module.r_lib_dir), self.stage.source_path]) 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): class RPackage(Package):

View File

@ -3,7 +3,6 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import glob import glob
import inspect
import spack.builder import spack.builder
import spack.package_base import spack.package_base
@ -52,10 +51,10 @@ def build(self, pkg, spec, prefix):
gemspecs = glob.glob("*.gemspec") gemspecs = glob.glob("*.gemspec")
rakefiles = glob.glob("Rakefile") rakefiles = glob.glob("Rakefile")
if gemspecs: if gemspecs:
inspect.getmodule(self.pkg).gem("build", "--norc", gemspecs[0]) pkg.module.gem("build", "--norc", gemspecs[0])
elif rakefiles: elif rakefiles:
jobs = inspect.getmodule(self.pkg).make_jobs jobs = pkg.module.make_jobs
inspect.getmodule(self.pkg).rake("package", "-j{0}".format(jobs)) pkg.module.rake("package", "-j{0}".format(jobs))
else: else:
# Some Ruby packages only ship `*.gem` files, so nothing to build # Some Ruby packages only ship `*.gem` files, so nothing to build
pass pass
@ -70,6 +69,6 @@ def install(self, pkg, spec, prefix):
# if --install-dir is not used, GEM_PATH is deleted from the # if --install-dir is not used, GEM_PATH is deleted from the
# environement, and Gems required to build native extensions will # environement, and Gems required to build native extensions will
# not be found. Those extensions are built during `gem install`. # 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] "install", "--norc", "--ignore-dependencies", "--install-dir", prefix, gems[0]
) )

View File

@ -2,8 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
import spack.builder import spack.builder
import spack.package_base import spack.package_base
from spack.directives import build_system, depends_on from spack.directives import build_system, depends_on
@ -63,8 +61,7 @@ def build_args(self, spec, prefix):
def build(self, pkg, spec, prefix): def build(self, pkg, spec, prefix):
"""Build the package.""" """Build the package."""
args = self.build_args(spec, prefix) pkg.module.scons(*self.build_args(spec, prefix))
inspect.getmodule(self.pkg).scons(*args)
def install_args(self, spec, prefix): def install_args(self, spec, prefix):
"""Arguments to pass to install.""" """Arguments to pass to install."""
@ -72,9 +69,7 @@ def install_args(self, spec, prefix):
def install(self, pkg, spec, prefix): def install(self, pkg, spec, prefix):
"""Install the package.""" """Install the package."""
args = self.install_args(spec, prefix) pkg.module.scons("install", *self.install_args(spec, prefix))
inspect.getmodule(self.pkg).scons("install", *args)
def build_test(self): def build_test(self):
"""Run unit tests after build. """Run unit tests after build.

View File

@ -2,7 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
import os import os
import re import re
@ -86,14 +85,13 @@ def import_modules(self):
def python(self, *args, **kwargs): def python(self, *args, **kwargs):
"""The python ``Executable``.""" """The python ``Executable``."""
inspect.getmodule(self).python(*args, **kwargs) self.pkg.module.python(*args, **kwargs)
def test_imports(self): def test_imports(self):
"""Attempts to import modules of the installed package.""" """Attempts to import modules of the installed package."""
# Make sure we are importing the installed modules, # Make sure we are importing the installed modules,
# not the ones in the source directory # not the ones in the source directory
python = inspect.getmodule(self).python
for module in self.import_modules: for module in self.import_modules:
with spack.install_test.test_part( with spack.install_test.test_part(
self, self,
@ -101,7 +99,7 @@ def test_imports(self):
purpose="checking import of {0}".format(module), purpose="checking import of {0}".format(module),
work_dir="spack-test", work_dir="spack-test",
): ):
python("-c", "import {0}".format(module)) self.python("-c", "import {0}".format(module))
@spack.builder.builder("sip") @spack.builder.builder("sip")
@ -136,7 +134,7 @@ def configure(self, pkg, spec, prefix):
"""Configure the package.""" """Configure the package."""
# https://www.riverbankcomputing.com/static/Docs/sip/command_line_tools.html # 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()) args.extend(self.configure_args())
# https://github.com/Python-SIP/sip/commit/cb0be6cb6e9b756b8b0db3136efb014f6fb9b766 # https://github.com/Python-SIP/sip/commit/cb0be6cb6e9b756b8b0db3136efb014f6fb9b766
@ -155,7 +153,7 @@ def build(self, pkg, spec, prefix):
args = self.build_args() args = self.build_args()
with working_dir(self.build_directory): with working_dir(self.build_directory):
inspect.getmodule(self.pkg).make(*args) pkg.module.make(*args)
def build_args(self): def build_args(self):
"""Arguments to pass to build.""" """Arguments to pass to build."""
@ -166,7 +164,7 @@ def install(self, pkg, spec, prefix):
args = self.install_args() args = self.install_args()
with working_dir(self.build_directory): with working_dir(self.build_directory):
inspect.getmodule(self.pkg).make("install", *args) pkg.module.make("install", *args)
def install_args(self): def install_args(self):
"""Arguments to pass to install.""" """Arguments to pass to install."""

View File

@ -2,8 +2,6 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details. # Spack Project Developers. See the top-level COPYRIGHT file for details.
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
from llnl.util.filesystem import working_dir from llnl.util.filesystem import working_dir
import spack.builder import spack.builder
@ -90,11 +88,11 @@ def build_directory(self):
def python(self, *args, **kwargs): def python(self, *args, **kwargs):
"""The python ``Executable``.""" """The python ``Executable``."""
inspect.getmodule(self.pkg).python(*args, **kwargs) self.pkg.module.python(*args, **kwargs)
def waf(self, *args, **kwargs): def waf(self, *args, **kwargs):
"""Runs the waf ``Executable``.""" """Runs the waf ``Executable``."""
jobs = inspect.getmodule(self.pkg).make_jobs jobs = self.pkg.module.make_jobs
with working_dir(self.build_directory): with working_dir(self.build_directory):
self.python("waf", "-j{0}".format(jobs), *args, **kwargs) self.python("waf", "-j{0}".format(jobs), *args, **kwargs)

View File

@ -6,7 +6,6 @@
import collections.abc import collections.abc
import copy import copy
import functools import functools
import inspect
from typing import List, Optional, Tuple from typing import List, Optional, Tuple
from llnl.util import lang from llnl.util import lang
@ -97,11 +96,10 @@ class hierarchy (look at AspellDictPackage for an example of that)
Args: Args:
pkg (spack.package_base.PackageBase): package object for which we need a builder pkg (spack.package_base.PackageBase): package object for which we need a builder
""" """
package_module = inspect.getmodule(pkg)
package_buildsystem = buildsystem_name(pkg) package_buildsystem = buildsystem_name(pkg)
default_builder_cls = BUILDER_CLS[package_buildsystem] default_builder_cls = BUILDER_CLS[package_buildsystem]
builder_cls_name = default_builder_cls.__name__ 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: if builder_cls:
return builder_cls(pkg) return builder_cls(pkg)

View File

@ -16,7 +16,6 @@
import glob import glob
import hashlib import hashlib
import importlib import importlib
import inspect
import io import io
import os import os
import re import re
@ -1743,7 +1742,7 @@ def _has_make_target(self, target):
bool: True if 'target' is found, else False bool: True if 'target' is found, else False
""" """
# Prevent altering LC_ALL for 'make' outside this function # 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 # Use English locale for missing target message comparison
make.add_default_env("LC_ALL", "C") make.add_default_env("LC_ALL", "C")
@ -1793,7 +1792,7 @@ def _if_make_target_execute(self, target, *args, **kwargs):
""" """
if self._has_make_target(target): if self._has_make_target(target):
# Execute target # Execute target
inspect.getmodule(self).make(target, *args, **kwargs) self.module.make(target, *args, **kwargs)
def _has_ninja_target(self, target): def _has_ninja_target(self, target):
"""Checks to see if 'target' is a valid target in a Ninja build script. """Checks to see if 'target' is a valid target in a Ninja build script.
@ -1804,7 +1803,7 @@ def _has_ninja_target(self, target):
Returns: Returns:
bool: True if 'target' is found, else False 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 # Check if we have a Ninja build script
if not os.path.exists("build.ninja"): if not os.path.exists("build.ninja"):
@ -1833,7 +1832,7 @@ def _if_ninja_target_execute(self, target, *args, **kwargs):
""" """
if self._has_ninja_target(target): if self._has_ninja_target(target):
# Execute target # Execute target
inspect.getmodule(self).ninja(target, *args, **kwargs) self.module.ninja(target, *args, **kwargs)
def _get_needed_resources(self): def _get_needed_resources(self):
# We use intersects here cause it would also work if self.spec is abstract # We use intersects here cause it would also work if self.spec is abstract

View File

@ -575,28 +575,26 @@ def test_build_jobs_defaults():
) )
class TestModuleMonkeyPatcher: class TestSetPackageGlobals:
def test_getting_attributes(self, default_mock_concretization): def test_getting_attributes(self, default_mock_concretization):
s = default_mock_concretization("libelf") s = default_mock_concretization("libelf")
module_wrapper = spack.build_environment.ModuleChangePropagator(s.package) module_wrapper = spack.build_environment.SetPackageGlobals(s.package)
assert module_wrapper.Libelf == s.package.module.Libelf assert module_wrapper.Libelf == s.package.module.Libelf
def test_setting_attributes(self, default_mock_concretization): def test_setting_attributes(self, default_mock_concretization):
s = default_mock_concretization("libelf") s = default_mock_concretization("libelf")
module = s.package.module module = s.package.module
module_wrapper = spack.build_environment.ModuleChangePropagator(s.package) module_wrapper = spack.build_environment.SetPackageGlobals(s.package)
# Setting an attribute has an immediate effect # Setting an attribute has an immediate effect
module_wrapper.SOME_ATTRIBUTE = 1 module_wrapper.SOME_ATTRIBUTE = 1
assert module.SOME_ATTRIBUTE == 1 assert module.SOME_ATTRIBUTE == 1
# We can also propagate the settings to classes in the MRO # We can also propagate the settings to classes in the MRO
module_wrapper.propagate_changes_to_mro() for cls in s.package.__class__.__mro__:
for cls in type(s.package).__mro__: if cls.module == spack.package_base:
current_module = cls.module
if current_module == spack.package_base:
break break
assert current_module.SOME_ATTRIBUTE == 1 assert cls.module.SOME_ATTRIBUTE == 1
def test_effective_deptype_build_environment(default_mock_concretization): def test_effective_deptype_build_environment(default_mock_concretization):

View File

@ -775,15 +775,15 @@ def test_regression_issue_7239(self):
s = Spec("mpileaks") s = Spec("mpileaks")
s.concretize() 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 # Spec wrapped in a build interface
build_interface = s["mpileaks"] 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 # Mimics asking the build interface from a build interface
build_interface = s["mpileaks"]["mpileaks"] 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") @pytest.mark.regression("7705")
def test_regression_issue_7705(self): def test_regression_issue_7705(self):

View File

@ -97,7 +97,7 @@ def configure(self, spec, prefix):
options += self.configure_args() options += self.configure_args()
with working_dir(self.build_directory, create=True): with working_dir(self.build_directory, create=True):
inspect.getmodule(self).configure(*options) configure(*options)
@when("@:01") @when("@:01")
def configure_args(self): def configure_args(self):

View File

@ -3,8 +3,6 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
from spack.package import * from spack.package import *
@ -87,9 +85,9 @@ def configure_args(self):
def build(self, spec, prefix): def build(self, spec, prefix):
with working_dir(self.build_directory): with working_dir(self.build_directory):
for target in self.build_targets: for target in self.build_targets:
inspect.getmodule(self).make(target) make(target)
def install(self, spec, prefix): def install(self, spec, prefix):
with working_dir(self.build_directory): with working_dir(self.build_directory):
for target in self.install_targets: for target in self.install_targets:
inspect.getmodule(self).make(target) make(target)

View File

@ -3,7 +3,6 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
import os.path import os.path
from spack.package import * from spack.package import *
@ -51,9 +50,7 @@ def install(self, spec, prefix):
"@LINK_VARIABLES_DEFINITION": link_variables, "@LINK_VARIABLES_DEFINITION": link_variables,
} }
template = join_path( template = join_path(os.path.dirname(__file__), "Make.mach.template")
os.path.dirname(inspect.getmodule(self).__file__), "Make.mach.template"
)
makefile = join_path( makefile = join_path(
self.stage.source_path, "src", "clib", "Make.mach.{0}".format(grackle_architecture) self.stage.source_path, "src", "clib", "Make.mach.{0}".format(grackle_architecture)
) )

View File

@ -4,7 +4,6 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import glob import glob
import inspect
import platform import platform
import sys import sys
@ -316,14 +315,13 @@ def install(self, pkg, spec, prefix):
if spec.satisfies("@2017.8,2018.1:"): if spec.satisfies("@2017.8,2018.1:"):
# Generate and install the CMake Config file. # 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")): 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") @run_after("install")
def darwin_fix(self): def darwin_fix(self):

View File

@ -3,7 +3,6 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
import os import os
from spack.package import * from spack.package import *
@ -80,9 +79,7 @@ def edit(self, spec, prefix):
("@LIB_LAPACK@", lapack_libs + " " + blas_libs), ("@LIB_LAPACK@", lapack_libs + " " + blas_libs),
("@LIB_PGPLOT@", pgplot_libdirs + " " + pgplot_libs), ("@LIB_PGPLOT@", pgplot_libdirs + " " + pgplot_libs),
] ]
local_settings_template = join_path( local_settings_template = join_path(os.path.dirname(__file__), "local_settings.template")
os.path.dirname(inspect.getmodule(self).__file__), "local_settings.template"
)
local_settings = join_path(self.stage.source_path, "local_settings") local_settings = join_path(self.stage.source_path, "local_settings")
copy(local_settings_template, local_settings) copy(local_settings_template, local_settings)
for key, value in substitutions: for key, value in substitutions:

View File

@ -49,9 +49,5 @@ def generate_args(self):
def generate(self, pkg, spec, prefix): def generate(self, pkg, spec, prefix):
"""Runs ``go generate`` in the source directory""" """Runs ``go generate`` in the source directory"""
import inspect with working_dir(self.build_directory):
go("generate", *self.generate_args)
import llnl.util.filesystem as fs
with fs.working_dir(self.build_directory):
inspect.getmodule(pkg).go("generate", *self.generate_args)

View File

@ -3,8 +3,6 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
from spack.package import * from spack.package import *
@ -105,7 +103,7 @@ def configure(self, spec, prefix):
f.writelines(config_answers) f.writelines(config_answers)
with open(config_answers_filename, "r") as f: 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 # 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 # Build script is run through perl and not use the shebang, as it might be
@ -113,8 +111,8 @@ def configure(self, spec, prefix):
# `@run_after(configure)` step defined in `PerlPackage`. # `@run_after(configure)` step defined in `PerlPackage`.
@when("@1.007002") @when("@1.007002")
def build(self, spec, prefix): def build(self, spec, prefix):
inspect.getmodule(self).perl("Build") perl("Build")
@when("@1.007002") @when("@1.007002")
def install(self, spec, prefix): def install(self, spec, prefix):
inspect.getmodule(self).perl("Build", "install") perl("Build", "install")

View File

@ -3,8 +3,6 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
from spack.package import * from spack.package import *
@ -23,7 +21,7 @@ class PerlIoSocketSsl(PerlPackage):
def configure(self, spec, prefix): def configure(self, spec, prefix):
self.build_method = "Makefile.PL" self.build_method = "Makefile.PL"
self.build_executable = inspect.getmodule(self).make self.build_executable = make
# Should I do external tests? # Should I do external tests?
config_answers = ["n\n"] config_answers = ["n\n"]
config_answers_filename = "spack-config.in" config_answers_filename = "spack-config.in"
@ -32,4 +30,4 @@ def configure(self, spec, prefix):
f.writelines(config_answers) f.writelines(config_answers)
with open(config_answers_filename, "r") as f: 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)

View File

@ -3,8 +3,6 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
from spack.package import * from spack.package import *
@ -25,7 +23,7 @@ class PerlNetSsleay(PerlPackage):
def configure(self, spec, prefix): def configure(self, spec, prefix):
self.build_method = "Makefile.PL" self.build_method = "Makefile.PL"
self.build_executable = inspect.getmodule(self).make self.build_executable = make
# Do you want to run external tests? # Do you want to run external tests?
config_answers = ["\n"] config_answers = ["\n"]
config_answers_filename = "spack-config.in" config_answers_filename = "spack-config.in"
@ -35,4 +33,4 @@ def configure(self, spec, prefix):
with open(config_answers_filename, "r") as f: with open(config_answers_filename, "r") as f:
env["OPENSSL_PREFIX"] = self.spec["openssl"].prefix 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)

View File

@ -3,9 +3,6 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
import os.path
import spack.build_systems.cmake import spack.build_systems.cmake
import spack.build_systems.makefile import spack.build_systems.makefile
from spack.package import * from spack.package import *
@ -94,7 +91,7 @@ def edit(self, pkg, spec, prefix):
substitutions.append(("@FLDFLAGS", fldflags.lstrip())) substitutions.append(("@FLDFLAGS", fldflags.lstrip()))
template = join_path(os.path.dirname(inspect.getmodule(self).__file__), "make.inc") template = join_path(__file__, "make.inc")
makefile = join_path(pkg.stage.source_path, "make.inc") makefile = join_path(pkg.stage.source_path, "make.inc")
copy(template, makefile) copy(template, makefile)
for key, value in substitutions: for key, value in substitutions:

View File

@ -3,7 +3,6 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import inspect
import os.path import os.path
from spack.package import * from spack.package import *
@ -80,7 +79,7 @@ def edit(self, spec, prefix):
"@LIBS": (lapack + blas + mpi).joined(), "@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) copy(template, self.makefile_name)
for key, value in substitutions.items(): for key, value in substitutions.items():