Skip to content

Commit 4cd0c50

Browse files
committed
Python setup and activate enhancements
Former-commit-id: 4e52141d773f122c59fc5b84d2c164c9b845120c [formerly afa544fbfa4fc8a23fc6562db8d58a7ba8f020ee] [formerly f6ec52401f49802f78be9ddbf41f93e5d4de256f [formerly 4a5514277a6f235e909b5a0557c6a851132bb5a9]] Former-commit-id: 2a6be6f53904762480986bb7d9489ee3b68caab0 [formerly 59ad6b5c40a21308761bd1155d8d84a43cf3458d] Former-commit-id: 7d6adba012f6988f6b118d64bea7930d356792c8 Former-commit-id: 7d16379
1 parent e1a77e9 commit 4cd0c50

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

src/AddOn/PyEnvironment.AddOn.EnsurePip.pas

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ procedure TPyEnvironmentAddOnEnsurePip.InternalExecute(
7777
LOutput: string;
7878
begin
7979
inherited;
80+
{ TODO : Check for valida executable and shared library files }
8081
if (TExecCmdService.Cmd(ADistribution.Executable,
8182
TExecCmdArgs.BuildArgv(
8283
ADistribution.Executable, ['-m', 'pip', '--version']),

src/Embeddable/PyEnvironment.Embeddable.pas

+14-19
Original file line numberDiff line numberDiff line change
@@ -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;
208208
begin
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}
274266
end;
275267

276268
function 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>);
446441
var
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

src/PyEnvironment.pas

+3-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ procedure TPyCustomEnvironment.Notification(AComponent: TComponent;
173173

174174
procedure TPyCustomEnvironment.Setup(APythonVersion: string);
175175
begin
176-
InternalSetup(
177-
IfThen(APythonVersion.IsEmpty(), PythonVersion, APythonVersion));
176+
InternalSetup(APythonVersion);
178177
end;
179178

180179
function TPyCustomEnvironment.SetupAsync(APythonVersion: string): ITask;
@@ -325,6 +324,8 @@ procedure TPyCustomEnvironment.InternalSetup(APythonVersion: string);
325324

326325
Prepare();
327326

327+
APythonVersion := IfThen(APythonVersion.IsEmpty(), PythonVersion, APythonVersion);
328+
328329
LDistribution := FDistributions.LocateEnvironment(APythonVersion);
329330
if not Assigned(LDistribution) then
330331
Exit();

0 commit comments

Comments
 (0)