python: remove self.spec["python"] from recipe (#49581)

Signed-off-by: Massimiliano Culpo <massimiliano.culpo@gmail.com>
This commit is contained in:
Massimiliano Culpo 2025-03-19 12:23:53 +01:00 committed by GitHub
parent 963519d2b2
commit 3a715c3e07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,16 +19,16 @@
from spack.package import * from spack.package import *
def make_pyvenv_cfg(python_spec: Spec, venv_prefix: str) -> str: def make_pyvenv_cfg(python_pkg: Package, venv_prefix: str) -> str:
"""Make a pyvenv_cfg file for a given (real) python command and venv prefix.""" """Make a pyvenv_cfg file for a given (real) python command and venv prefix."""
python_cmd = python_spec.command.path python_cmd = python_pkg.command.path
lines = [ lines = [
# directory containing python command # directory containing python command
f"home = {os.path.dirname(python_cmd)}", f"home = {os.path.dirname(python_cmd)}",
# venv should not allow site packages from the real python to be loaded # venv should not allow site packages from the real python to be loaded
"include-system-site-packages = false", "include-system-site-packages = false",
# version of the python command # version of the python command
f"version = {python_spec.version}", f"version = {python_pkg.spec.version}",
# the path to the python command # the path to the python command
f"executable = {python_cmd}", f"executable = {python_cmd}",
# command "used" to create the pyvenv.cfg # command "used" to create the pyvenv.cfg
@ -1369,19 +1369,15 @@ def add_files_to_view(self, view, merge_map, skip_if_exists=True):
return return
with open(pyvenv_cfg, "w") as cfg_file: with open(pyvenv_cfg, "w") as cfg_file:
cfg_file.write(make_pyvenv_cfg(self.spec["python"], projection)) cfg_file.write(make_pyvenv_cfg(self, projection))
def test_hello_world(self): def test_hello_world(self):
"""run simple hello world program""" """run simple hello world program"""
python = self.command out = self.command("-c", 'print("hello world!")', output=str.split, error=str.split)
assert "hello world!" in out
msg = "hello world!"
out = python("-c", f'print("{msg}")', output=str.split, error=str.split)
assert msg in out
def test_import_executable(self): def test_import_executable(self):
"""ensure import of installed executable works""" """ensure import of installed executable works"""
python = self.command python = self.command
out = python("-c", "import sys; print(sys.executable)", output=str.split, error=str.split) out = python("-c", "import sys; print(sys.executable)", output=str.split, error=str.split)
assert self.spec.prefix in out assert self.spec.prefix in out