forked from spack/spack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
python: rework how we compute the "command" property (spack#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/.
- Loading branch information
Showing
2 changed files
with
12 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -858,14 +858,14 @@ def command(self): | |
# * python | ||
# | ||
# in that order if using [email protected], for example. | ||
version = self.spec.version | ||
for ver in [version.up_to(2), version.up_to(1), ""]: | ||
if sys.platform != "win32": | ||
path = os.path.join(self.prefix.bin, "python{0}".format(ver)) | ||
else: | ||
path = os.path.join(self.prefix, "python{0}.exe".format(ver)) | ||
if os.path.exists(path): | ||
return Executable(path) | ||
suffixes = [self.spec.version.up_to(2), self.spec.version.up_to(1), ""] | ||
file_extension = "" if sys.platform != "win32" else ".exe" | ||
patterns = [f"python{ver}{file_extension}" for ver in suffixes] | ||
root = self.prefix.bin if sys.platform != "win32" else self.prefix | ||
path = find_first(root, files=patterns) | ||
|
||
if path is not None: | ||
return Executable(path) | ||
|
||
else: | ||
# Give a last try at rhel8 platform python | ||
|
@@ -874,8 +874,9 @@ def command(self): | |
if os.path.exists(path): | ||
return Executable(path) | ||
|
||
msg = "Unable to locate {0} command in {1}" | ||
raise RuntimeError(msg.format(self.name, self.prefix.bin)) | ||
raise RuntimeError( | ||
f"cannot to locate the '{self.name}' command in {root} or its subdirectories" | ||
) | ||
|
||
@property | ||
def config_vars(self): | ||
|