@@ -127,7 +127,7 @@ TScanner = class(TPersistent)
127127 FEnvironmentPath: string;
128128 FDeleteEmbeddable: boolean;
129129 public
130- procedure Scan (ACallback: TProc<TPythonVersionProp, string>);
130+ procedure Scan (const AEmbedabblesPath: string; ACallback: TProc<TPythonVersionProp, string>);
131131 published
132132 property AutoScan: boolean read FAutoScan write FAutoScan default false;
133133 property ScanRule: TScanRule read FScanRule write FScanRule;
@@ -207,6 +207,7 @@ function TPyCustomEmbeddableDistribution.FileIsExecutable(
207207 const AFilePath: string): boolean;
208208begin
209209 { $WARN SYMBOL_PLATFORM OFF}
210+ // Avoiding symlinks
210211 Result := (TFileAttribute.faOwnerExecute in TFile.GetAttributes(AFilePath))
211212 or (TFileAttribute.faGroupExecute in TFile.GetAttributes(AFilePath))
212213 or (TFileAttribute.faOthersExecute in TFile.GetAttributes(AFilePath));
@@ -233,15 +234,6 @@ function TPyCustomEmbeddableDistribution.FindExecutable: string;
233234 if (TPath.GetFileName(LFile) = ' python' + PythonVersion) and (FileIsExecutable(LFile)) then
234235 Exit(TArray<string>.Create(LFile));
235236 end ;
236-
237- { $WARN SYMBOL_PLATFORM OFF}
238- LFile := Result[High(Result)];
239- if (TFileAttribute.faOwnerExecute in TFile.GetAttributes(LFile))
240- or (TFileAttribute.faGroupExecute in TFile.GetAttributes(LFile))
241- or (TFileAttribute.faOthersExecute in TFile.GetAttributes(LFile)) then // Avoiding symlinks
242- Exit(TArray<string>.Create(LFile));
243- { $WARN SYMBOL_PLATFORM ON}
244-
245237 { $ENDIF POSIX}
246238 end ;
247239{ $IFNDEF MSWINDOWS}
@@ -252,25 +244,25 @@ function TPyCustomEmbeddableDistribution.FindExecutable: string;
252244 { $IFDEF MSWINDOWS}
253245 Result := TPath.Combine(GetEnvironmentPath(), ' python.exe' );
254246 if not TFile.Exists(Result) then
255- Result := String.Empty;
247+ Exit( String.Empty) ;
256248 { $ELSEIF DEFINED(ANDROID)}
249+ // Let's try it in the library path first - we should place it in the library path in Android
257250 Result := TPath.GetLibraryPath();
258251 LFiles := DoSearch(Result);
259252 if LFiles <> nil then
260253 Exit(LFiles[Low(LFiles)]);
261254 Result := TPath.Combine(GetEnvironmentPath(), ' bin' );
262255 { $ELSE}
263256 Result := TPath.Combine(GetEnvironmentPath(), ' bin' );
257+ { $ENDIF}
264258
265259 LFiles := DoSearch(Result);
266-
267260 if Length(LFiles) > 0 then begin
268261 Result := LFiles[Low(LFiles)];
269262 if not TFile.Exists(Result) then
270263 Result := String.Empty;
271264 end else
272265 Result := String.Empty;
273- { $ENDIF}
274266end ;
275267
276268function TPyCustomEmbeddableDistribution.FindSharedLibrary : string;
@@ -306,11 +298,13 @@ function TPyCustomEmbeddableDistribution.FindSharedLibrary: string;
306298 { $IFDEF MSWINDOWS}
307299 LPath := GetEnvironmentPath();
308300 { $ELSEIF DEFINED(ANDROID)}
301+ // Let's try it in the library path first - we should place it in the library path in Android
309302 LPath := TPath.GetLibraryPath();
310303 LFiles := DoSearch(LLibName, LPath);
311304 if LFiles <> nil then
312305 Exit(LFiles[Low(LFiles)]);
313- LPath := GetEnvironmentPath();
306+ // Try to find it in the environments path
307+ LPath := TPath.Combine(GetEnvironmentPath(), ' lib' );
314308 { $ELSE}
315309 LPath := TPath.Combine(GetEnvironmentPath(), ' lib' );
316310 { $ENDIF}
@@ -406,12 +400,13 @@ procedure TPyEmbeddedEnvironment.Prepare;
406400 if FScanner.AutoScan then begin
407401 if PythonProject.Enabled then
408402 if FScanner.EmbeddablesPath.IsEmpty() then begin
409- FScanner.EmbeddablesPath := TPyEnvironmentPath.ResolvePath(TPyEnvironmentPath. DEPLOY_PATH) ;
403+ FScanner.EmbeddablesPath := TPyEnvironmentPath.DEPLOY_PATH;
410404 FScanner.ScanRule := TScanRule.srFileName;
411405 FScanner.DeleteEmbeddable := true;
412406 end ;
413407
414408 FScanner.Scan(
409+ TPyEnvironmentPath.ResolvePath(FScanner.EmbeddablesPath),
415410 procedure(APyVersionInfo: TPythonVersionProp; AEmbeddablePackage: string) begin
416411 if Assigned(Distributions.LocateEnvironment(APyVersionInfo.RegVersion)) then
417412 Exit;
@@ -441,7 +436,7 @@ procedure TPyEmbeddedEnvironment.SetScanner(const Value: TScanner);
441436
442437{ TPyEmbeddedEnvironment.TScanner }
443438
444- procedure TPyEmbeddedEnvironment.TScanner .Scan(
439+ procedure TPyEmbeddedEnvironment.TScanner .Scan(const AEmbedabblesPath: string;
445440 ACallback: TProc<TPythonVersionProp, string>);
446441var
447442 I: Integer;
@@ -453,14 +448,14 @@ procedure TPyEmbeddedEnvironment.TScanner.Scan(
453448 if not Assigned(ACallback) then
454449 Exit;
455450
456- if not TDirectory.Exists(FEmbeddablesPath ) then
451+ if not TDirectory.Exists(AEmbedabblesPath ) then
457452 raise Exception.Create(' Directory not found.' );
458453
459454 // Look for version named subfolders
460455 if (FScanRule = TScanRule.srFolder) then begin
461456 LSearchPatter := ' *.zip' ;
462457 for I := Low(PYTHON_KNOWN_VERSIONS) to High(PYTHON_KNOWN_VERSIONS) do begin
463- LPath := TPath.Combine(FEmbeddablesPath , PYTHON_KNOWN_VERSIONS[I].RegVersion);
458+ LPath := TPath.Combine(AEmbedabblesPath , PYTHON_KNOWN_VERSIONS[I].RegVersion);
464459 if not TDirectory.Exists(LPath) then
465460 Continue;
466461
@@ -475,7 +470,7 @@ procedure TPyEmbeddedEnvironment.TScanner.Scan(
475470 for I := Low(PYTHON_KNOWN_VERSIONS) to High(PYTHON_KNOWN_VERSIONS) do begin
476471 LPythonVersion := PYTHON_KNOWN_VERSIONS[I].RegVersion;
477472 LSearchPatter := Format(' python3-*-%s*.zip' , [LPythonVersion]);
478- LFiles := TDirectory.GetFiles(FEmbeddablesPath , LSearchPatter, TSearchOption.soTopDirectoryOnly);
473+ LFiles := TDirectory.GetFiles(AEmbedabblesPath , LSearchPatter, TSearchOption.soTopDirectoryOnly);
479474 if (Length(LFiles) = 0 ) then
480475 Continue;
481476
0 commit comments