msvc: fix imports (#50543)

This commit is contained in:
Harmen Stoppels 2025-05-20 12:19:55 +02:00 committed by GitHub
parent f07789febf
commit ef2b596e3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,7 +12,6 @@
import archspec.cpu import archspec.cpu
import spack.platforms import spack.platforms
import spack.version
from spack.package import * from spack.package import *
FC_PATH: Dict[str, str] = dict() FC_PATH: Dict[str, str] = dict()
@ -154,9 +153,7 @@ def init_msvc(self):
if str(archspec.cpu.host().family) == "x86_64": if str(archspec.cpu.host().family) == "x86_64":
arch = "amd64" arch = "amd64"
msvc_version = spack.version.Version( msvc_version = Version(re.search(Msvc.compiler_version_regex, self.cc).group(1))
re.search(Msvc.compiler_version_regex, self.cc).group(1)
)
self.vcvars_call = VCVarsInvocation(vcvars_script_path, arch, msvc_version) self.vcvars_call = VCVarsInvocation(vcvars_script_path, arch, msvc_version)
env_cmds.append(self.vcvars_call) env_cmds.append(self.vcvars_call)
@ -237,7 +234,7 @@ def vc_toolset_ver(self):
@property @property
def msvc_version(self): def msvc_version(self):
"""This is the VCToolset version *NOT* the actual version of the cl compiler""" """This is the VCToolset version *NOT* the actual version of the cl compiler"""
return spack.version.Version(re.search(Msvc.compiler_version_regex, self.cc).group(1)) return Version(re.search(Msvc.compiler_version_regex, self.cc).group(1))
@property @property
def vs_root(self): def vs_root(self):
@ -267,7 +264,7 @@ def platform_toolset_ver(self):
# TODO: (johnwparent) Update this logic for the next platform toolset # TODO: (johnwparent) Update this logic for the next platform toolset
# or VC toolset version update # or VC toolset version update
toolset_ver = self.vc_toolset_ver toolset_ver = self.vc_toolset_ver
vs22_toolset = spack.version.Version(toolset_ver) > Version("142") vs22_toolset = Version(toolset_ver) > Version("142")
return toolset_ver if not vs22_toolset else "143" return toolset_ver if not vs22_toolset else "143"
@ -362,6 +359,6 @@ def get_valid_fortran_pth():
"""Assign maximum available fortran compiler version""" """Assign maximum available fortran compiler version"""
# TODO (johnwparent): validate compatibility w/ try compiler # TODO (johnwparent): validate compatibility w/ try compiler
# functionality when added # functionality when added
sort_fn = lambda fc_ver: spack.version.Version(fc_ver) sort_fn = lambda fc_ver: Version(fc_ver)
sort_fc_ver = sorted(list(FC_PATH.keys()), key=sort_fn) sort_fc_ver = sorted(list(FC_PATH.keys()), key=sort_fn)
return FC_PATH[sort_fc_ver[-1]] if sort_fc_ver else None return FC_PATH[sort_fc_ver[-1]] if sort_fc_ver else None