builtin: self.spec[self.name].command -> self.command (#49582)

* builtin: self.spec[self.name].command -> self.command

* python-venv: ensure return type is Executable instead of Executable | None
This commit is contained in:
Harmen Stoppels 2025-03-19 11:37:01 +01:00 committed by GitHub
parent 34efcb686c
commit 963519d2b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 11 additions and 12 deletions

View File

@ -319,7 +319,7 @@ def install_test(self):
)
# Spack's logs don't handle colored output well
bazel = Executable(self.spec["bazel"].command.path)
bazel = Executable(self.command.path)
bazel(
"--output_user_root=/tmp/spack/bazel/spack-test",
"build",
@ -332,7 +332,7 @@ def install_test(self):
assert exe(output=str) == "Hi!\n"
def setup_dependent_package(self, module, dependent_spec):
module.bazel = Executable(self.spec["bazel"].command.path)
module.bazel = Executable(self.command.path)
@property
def parallel(self):

View File

@ -169,7 +169,7 @@ def check_install(self):
os.environ.pop("CLIKPATH", "")
os.environ.pop("PLANCKLIKE", "")
exe = spec["cosmomc"].command.path
exe = self.command.path
args = []
if spec.satisfies("+mpi"):
# Add mpirun prefix

View File

@ -1005,7 +1005,7 @@ def write_specs_file(self):
specs_file = join_path(self.spec_dir, "specs")
with open(specs_file, "w") as f:
# can't extend the builtins without dumping them first
f.write(self.spec["gcc"].command("-dumpspecs", output=str, error=os.devnull).strip())
f.write(self.command("-dumpspecs", output=str, error=os.devnull).strip())
f.write("\n\n# Generated by Spack\n\n")
@ -1179,7 +1179,7 @@ def _post_buildcache_install_hook(self):
# Setting up the runtime environment shouldn't be necessary here.
relocation_args = []
gcc = self.spec["gcc"].command
gcc = self.command
specs_file = os.path.join(self.spec_dir, "specs")
dryrun = gcc("test.c", "-###", output=os.devnull, error=str).strip()
if not dryrun:

View File

@ -120,4 +120,4 @@ def setup_dependent_package(self, module, dependent_spec):
install_tree('bin', prefix.bin)
"""
# Add a go command/compiler for extensions
module.go = self.spec["go"].command
module.go = self.command

View File

@ -36,7 +36,7 @@ def configure_args(self):
@run_after("install")
@on_package_attributes(run_tests=True)
def install_test(self):
jq = self.spec["jq"].command
jq = self.command
f = os.path.join(os.path.dirname(__file__), "input.json")
assert jq(".bar", input=f, output=str) == "2\n"

View File

@ -244,7 +244,7 @@ def apply_patch(self, other):
def setup_dependent_package(self, module, dependent_spec):
# Make plumed visible from dependent packages
module.plumed = dependent_spec["plumed"].command
module.plumed = self.command
@property
def plumed_inc(self):

View File

@ -54,7 +54,7 @@ def bindir(self):
def command(self):
"""Returns a python Executable instance"""
python_name = "python" if self.spec.satisfies("platform=windows") else "python3"
return which(python_name, path=self.bindir)
return which(python_name, path=self.bindir, required=True)
def _get_path(self, name) -> str:
return self.command(

View File

@ -1373,8 +1373,7 @@ def add_files_to_view(self, view, merge_map, skip_if_exists=True):
def test_hello_world(self):
"""run simple hello world program"""
# do not use self.command because we are also testing the run env
python = self.spec["python"].command
python = self.command
msg = "hello world!"
out = python("-c", f'print("{msg}")', output=str.split, error=str.split)
@ -1382,7 +1381,7 @@ def test_hello_world(self):
def test_import_executable(self):
"""ensure import of installed executable works"""
python = self.spec["python"].command
python = self.command
out = python("-c", "import sys; print(sys.executable)", output=str.split, error=str.split)
assert self.spec.prefix in out