tools: support for embedded python

This commit is contained in:
Juraj Michálek
2020-12-16 17:40:13 +01:00
parent c535d569aa
commit 1427b3a6d8
29 changed files with 556 additions and 161 deletions
+27 -32
View File
@@ -1,4 +1,4 @@
{ Copyright 2019-2020 Espressif Systems (Shanghai) CO LTD
{ Copyright 2019-2021 Espressif Systems (Shanghai) CO LTD
SPDX-License-Identifier: Apache-2.0 }
{ ------------------------------ Page to select Python interpreter ------------------------------ }
@@ -8,7 +8,6 @@
var
PythonPage: TInputOptionWizardPage;
PythonVersion, PythonPath, PythonExecutablePath: String;
PythonUseExisting: Boolean;
function GetPythonPath(Unused: String): String;
@@ -16,11 +15,6 @@ begin
Result := PythonPath;
end;
function PythonInstallRequired(): Boolean;
begin
Result := not PythonUseExisting;
end;
function PythonVersionSupported(Version: String): Boolean;
var
Major, Minor: Integer;
@@ -93,40 +87,26 @@ begin
Log('OnPythonSelectionChange index=' + IntToStr(Page.SelectedValueIndex));
end;
procedure ApplyPythonConfigurationByIndex(Index:Integer);
begin
Log('ApplyPythonConfigurationByIndex index=' + IntToStr(Index));
PythonExecutablePath := InstalledPythonExecutables[Index];
PythonPath := ExtractFilePath(PythonExecutablePath);
PythonVersion := InstalledPythonVersions[Index];
Log('ApplyPythonConfigurationByIndex: PythonPath='+PythonPath+' PythonExecutablePath='+PythonExecutablePath);
end;
function OnPythonPageValidate(Sender: TWizardPage): Boolean;
var
Page: TInputOptionWizardPage;
begin
Page := TInputOptionWizardPage(Sender);
Log('OnPythonPageValidate index=' + IntToStr(Page.SelectedValueIndex));
if Page.SelectedValueIndex < InstalledPythonExecutables.Count then
begin
PythonUseExisting := True;
PythonExecutablePath := InstalledPythonExecutables[Page.SelectedValueIndex];
PythonPath := ExtractFilePath(PythonExecutablePath);
PythonVersion := InstalledPythonVersions[Page.SelectedValueIndex];
end else begin
PythonUseExisting := False;
PythonExecutablePath := '';
PythonPath := '';
PythonVersion := '{#PythonVersion}';
end;
Log('OnPythonPageValidate: PythonPath='+PythonPath+' PythonExecutablePath='+PythonExecutablePath);
ApplyPythonConfigurationByIndex(Page.SelectedValueIndex);
Result := True;
end;
procedure PythonExecutablePathUpdateAfterInstall();
var
Version, DisplayName, ExecutablePath, BaseDir: String;
procedure UpdatePythonVariables(ExecutablePath: String);
begin
if not GetPythonVersionInfoFromKey(
HKEY_CURRENT_USER, 'Software\Python', 'PythonCore', '{#PythonVersion}',
Version, DisplayName, ExecutablePath, BaseDir) then
begin
Log('Failed to find ExecutablePath for the installed copy of Python');
exit;
end;
Log('Found ExecutablePath for ' + DisplayName + ': ' + ExecutablePath);
PythonExecutablePath := ExecutablePath;
PythonPath := ExtractFilePath(PythonExecutablePath);
Log('PythonExecutablePathUpdateAfterInstall: PythonPath='+PythonPath+' PythonExecutablePath='+PythonExecutablePath);
@@ -145,3 +125,18 @@ begin
@OnPythonSelectionChange,
@OnPythonPageValidate);
end;
<event('ShouldSkipPage')>
function ShouldSkipPythonPage(PageID: Integer): Boolean;
var
UseEmbeddedPythonParam: String;
begin
if (PageID = PythonPage.ID) then begin
{ Skip in case of embedded Python. }
UseEmbeddedPythonParam := ExpandConstant('{param:USEEMBEDDEDPYTHON|yes}');
if (UseEmbeddedPythonParam = 'yes') then begin
ApplyPythonConfigurationByIndex(0);
Result := True;
end;
end;
end;