Skip to content

Commit 28a9e01

Browse files
committed
PythonVersions.pas - PythonVersionFromPath.FindPythonDLL improved - search from high to low instead of getting an arbitrary one
1 parent c51a13f commit 28a9e01

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

Source/PythonVersions.pas

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -435,21 +435,18 @@ function PythonVersionFromPath(const Path: string; out PythonVersion: TPythonVer
435435

436436
function FindPythonDLL(APath : string): string;
437437
Var
438-
FindFileData: TWIN32FindData;
439-
Handle : THandle;
440438
DLLFileName: string;
439+
I: integer;
441440
begin
442441
Result := '';
443-
Handle := FindFirstFile(PWideChar(APath+'\python??.dll'), FindFileData);
444-
if Handle = INVALID_HANDLE_VALUE then Exit; // not python dll
445-
DLLFileName:= FindFileData.cFileName;
446-
// skip if python3.dll was found
447-
if Length(DLLFileName) <> 12 then FindNextFile(Handle, FindFileData);
448-
if Handle = INVALID_HANDLE_VALUE then Exit;
449-
Windows.FindClose(Handle);
450-
DLLFileName:= FindFileData.cFileName;
451-
if Length(DLLFileName) = 12 then
452-
Result := DLLFileName;
442+
APath := IncludeTrailingPathDelimiter(APath);
443+
for I := High(PYTHON_KNOWN_VERSIONS) downto COMPILED_FOR_PYTHON_VERSION_INDEX do begin
444+
DLLFileName := PYTHON_KNOWN_VERSIONS[I].DLLName;
445+
if FileExists(APath+DLLFileName) then begin
446+
Result := DLLFileName;
447+
exit;
448+
end;
449+
end;
453450
end;
454451

455452
function GetVenvBasePrefix(InstallPath: string): string;

0 commit comments

Comments
 (0)