python: rework how we compute the "command" property (#46850)
Some Windows Python installations may store the Python exe in Scripts/ rather than the base directory. Update `.command` to search in both locations on Windows. On all systems, the search is now done recursively from the search root: on Windows, that is the base install directory, and on other systems it is bin/.
This commit is contained in:
parent
6d67992191
commit
8e4e3c9060
@ -47,6 +47,7 @@
|
|||||||
"copy_mode",
|
"copy_mode",
|
||||||
"filter_file",
|
"filter_file",
|
||||||
"find",
|
"find",
|
||||||
|
"find_first",
|
||||||
"find_headers",
|
"find_headers",
|
||||||
"find_all_headers",
|
"find_all_headers",
|
||||||
"find_libraries",
|
"find_libraries",
|
||||||
|
@ -858,13 +858,13 @@ def command(self):
|
|||||||
# * python
|
# * python
|
||||||
#
|
#
|
||||||
# in that order if using python@3.11.0, for example.
|
# in that order if using python@3.11.0, for example.
|
||||||
version = self.spec.version
|
suffixes = [self.spec.version.up_to(2), self.spec.version.up_to(1), ""]
|
||||||
for ver in [version.up_to(2), version.up_to(1), ""]:
|
file_extension = "" if sys.platform != "win32" else ".exe"
|
||||||
if sys.platform != "win32":
|
patterns = [f"python{ver}{file_extension}" for ver in suffixes]
|
||||||
path = os.path.join(self.prefix.bin, "python{0}".format(ver))
|
root = self.prefix.bin if sys.platform != "win32" else self.prefix
|
||||||
else:
|
path = find_first(root, files=patterns)
|
||||||
path = os.path.join(self.prefix, "python{0}.exe".format(ver))
|
|
||||||
if os.path.exists(path):
|
if path is not None:
|
||||||
return Executable(path)
|
return Executable(path)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -874,8 +874,9 @@ def command(self):
|
|||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
return Executable(path)
|
return Executable(path)
|
||||||
|
|
||||||
msg = "Unable to locate {0} command in {1}"
|
raise RuntimeError(
|
||||||
raise RuntimeError(msg.format(self.name, self.prefix.bin))
|
f"cannot to locate the '{self.name}' command in {root} or its subdirectories"
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def config_vars(self):
|
def config_vars(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user