Skip to content

Commit e660759

Browse files
committed
Is_conda and Is_virtualenv added.
1 parent 670fe32 commit e660759

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

PythonForDelphi/Components/Sources/Core/PythonVersions.pas

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ TPythonVersion = record
3838
InstallPath: string;
3939
PythonPath: string;
4040
function Is_venv: Boolean;
41+
function Is_virtualenv: Boolean;
42+
function Is_conda: Boolean;
4143
procedure AssignTo(PythonEngine: TPersistent);
4244
property PythonExecutable: string read GetPythonExecutable;
4345
property DLLName: string read GetDLLName;
@@ -132,10 +134,23 @@ function TPythonVersion.GetApiVersion: integer;
132134
end;
133135

134136
function TPythonVersion.GetDisplayName: string;
137+
Var
138+
FormatStr: string;
135139
begin
140+
if FDisplayName = '' then
141+
begin
142+
if Is_conda then
143+
FormatStr := 'Conda %s (%s)'
144+
else
145+
FormatStr := 'Python %s (%s)';
146+
if Is_venv then
147+
FormatStr := FormatStr + ' -venv'
148+
else if Is_virtualenv then
149+
FormatStr := FormatStr + ' -virtualenv';
150+
151+
FDisplayName := Format(FormatStr, [SysVersion, SysArchitecture]);
152+
end;
136153
Result := FDisplayName;
137-
if Result = '' then
138-
Result := Format('Python %s (%s)', [SysVersion, SysArchitecture]);
139154
end;
140155

141156
function TPythonVersion.GetHelpFile: string;
@@ -178,7 +193,12 @@ function TPythonVersion.GetSysArchitecture: string;
178193
begin
179194
Result := fSysArchitecture;
180195
if Result = '' then
181-
Result := 'Unknown';
196+
Result := 'Unknown platform';
197+
end;
198+
199+
function TPythonVersion.Is_conda: Boolean;
200+
begin
201+
Result := FileExists(IncludeTrailingPathDelimiter(InstallPath) + 'scripts\conda.exe');
182202
end;
183203

184204
function TPythonVersion.Is_venv: Boolean;
@@ -191,6 +211,12 @@ function TPythonVersion.Is_venv: Boolean;
191211
FileExists(IncludeTrailingPathDelimiter(InstallPath) + 'pyvenv.cfg');
192212
end;
193213

214+
function TPythonVersion.Is_virtualenv: Boolean;
215+
begin
216+
Result := not IsRegistered and (InstallPath <> DLLPath) and
217+
not FileExists(IncludeTrailingPathDelimiter(InstallPath) + 'pyvenv.cfg');
218+
end;
219+
194220
function CompareVersions(A, B : String) : Integer;
195221

196222
function GetNextNumber(var Version: string): Integer;

0 commit comments

Comments
 (0)