forked from lmbelo/python4delphi
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuPSI_PythonVersions.pas
More file actions
276 lines (225 loc) · 13 KB
/
Copy pathuPSI_PythonVersions.pas
File metadata and controls
276 lines (225 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
unit uPSI_PythonVersions;
{
Tinherit from tobject convert from record to class
https://github.com/magicmonty/delphi-code-coverage/blob/master/3rdParty/JWAPI/jwapi2.2a/Win32API/JwaWinBase.pas
https://github.com/maxkleiner/python4delphi/blob/master/Source/PythonVersions.pas
use of rerecord to class - new py version
}
interface
uses
SysUtils
,Classes
,uPSComponent
,uPSRuntime
,uPSCompiler
;
type
(*----------------------------------------------------------------------------*)
TPSImport_PythonVersions = class(TPSPlugin)
public
procedure CompileImport1(CompExec: TPSScript); override;
procedure ExecImport1(CompExec: TPSScript; const ri: TPSRuntimeClassImporter); override;
end;
{ compile-time registration functions }
procedure SIRegister_TPythonVersion(CL: TPSPascalCompiler);
procedure SIRegister_PythonVersions(CL: TPSPascalCompiler);
{ run-time registration functions }
procedure RIRegister_PythonVersions_Routines(S: TPSExec);
procedure RIRegister_TPythonVersion(CL: TPSRuntimeClassImporter);
procedure RIRegister_PythonVersions(CL: TPSRuntimeClassImporter);
procedure Register;
implementation
uses
PythonVersions_class //, pythonversions
;
procedure Register;
begin
RegisterComponents('Pascal Script', [TPSImport_PythonVersions]);
end;
(* === compile-time registration functions === *)
(*----------------------------------------------------------------------------*)
procedure SIRegister_TPythonVersion(CL: TPSPascalCompiler);
begin
//with RegClassS(CL,'TOBJECT', 'TPythonVersion') do
with CL.AddClassN(CL.FindClass('TOBJECT'),'TPythonVersion') do
begin
RegisterMethod('Constructor Create');
RegisterMethod('Procedure Free;');
RegisterProperty('IsRegistered', 'Boolean', iptrw);
RegisterProperty('IsAllUsers', 'Boolean', iptrw);
RegisterProperty('SysVersion', 'string', iptrw);
RegisterProperty('Version', 'string', iptrw);
RegisterProperty('DLLPath', 'string', iptrw);
RegisterProperty('InstallPath', 'string', iptrw);
RegisterProperty('PythonPath', 'string', iptrw);
RegisterMethod('Function Is_venv : Boolean');
RegisterMethod('Function Is_virtualenv : Boolean');
RegisterMethod('Function Is_conda : Boolean');
RegisterMethod('Procedure AssignTo( PythonEngine : TPersistent)');
RegisterProperty('PythonExecutable', 'string', iptr);
RegisterProperty('DLLName', 'string', iptr);
RegisterProperty('SysArchitecture', 'string', iptr);
RegisterProperty('IsPython3K', 'Boolean', iptr);
RegisterProperty('HelpFile', 'string', iptrw);
RegisterProperty('HelpFile2', 'string', iptrw);
RegisterProperty('DisplayName', 'string', iptrw);
RegisterProperty('ApiVersion', 'integer', iptr);
end;
end;
(*----------------------------------------------------------------------------*)
procedure SIRegister_PythonVersions(CL: TPSPascalCompiler);
begin
SIRegister_TPythonVersion(CL);
CL.AddTypeS('TPythonVersions', 'array of TPythonVersion');
CL.AddDelphiFunction('Function CompareVersions( A, B : string) : Integer');
CL.AddDelphiFunction('Function IsEXEx64( const EXEName : string) : Boolean');
CL.AddDelphiFunction('Function Isx64( const FileName : string) : Boolean');
CL.AddDelphiFunction('Function GetRegisteredPythonVersion( SysVersion : string; out PythonVersion : TPythonVersion) : Boolean');
CL.AddDelphiFunction('Function GetRegisteredPythonVersions : TPythonVersions');
CL.AddDelphiFunction('Function GetLatestRegisteredPythonVersion( out PythonVersion : TPythonVersion) : Boolean');
CL.AddDelphiFunction('Function PythonVersionFromPath( const Path : string; out PythonVersion : TPythonVersion; AcceptVirtualEnvs : Boolean) : Boolean');
CL.AddDelphiFunction('function GetRegisteredPythonVersion2(SysVersion: string;out PythonVersion: TPythonVersion): Boolean;');
CL.AddDelphiFunction('function GetRegisteredPythonVersions2(const MinVersion:string;const MaxVersion:string): TPythonVersions;');
CL.AddDelphiFunction('function GetPythonVersions :string;');
CL.AddDelphiFunction('function GetPyVers: string;'); //alias
CL.AddDelphiFunction('function GetServices:string;');
//function GetRegisteredPythonVersions2(const MinVersion:string;const MaxVersion:string): TPythonVersions;
//function GetRegisteredPythonVersion2(SysVersion: string;out PythonVersion: TPythonVersion): Boolean;
end;
(* === run-time registration functions === *)
(*----------------------------------------------------------------------------*)
procedure TPythonVersionApiVersion_R(Self: TPythonVersion; var T: integer);
begin T := Self.ApiVersion; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionDisplayName_W(Self: TPythonVersion; const T: string);
begin Self.DisplayName := T; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionDisplayName_R(Self: TPythonVersion; var T: string);
begin T := Self.DisplayName; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionHelpFile_W(Self: TPythonVersion; const T: string);
begin Self.HelpFile := T; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionHelpFile_R(Self: TPythonVersion; var T: string);
begin T := Self.HelpFile; end;
procedure TPythonVersionHelpFile_W2(Self: TPythonVersion; const T: string);
begin Self.HelpFile2 := T; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionHelpFile_R2(Self: TPythonVersion; var T: string);
begin T := Self.HelpFile2; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionIsPython3K_R(Self: TPythonVersion; var T: Boolean);
begin T := Self.IsPython3K; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionSysArchitecture_R(Self: TPythonVersion; var T: string);
begin T := Self.SysArchitecture; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionDLLName_R(Self: TPythonVersion; var T: string);
begin T := Self.DLLName; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionPythonExecutable_R(Self: TPythonVersion; var T: string);
begin T := Self.PythonExecutable; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionPythonPath_W(Self: TPythonVersion; const T: string);
Begin Self.PythonPath := T; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionPythonPath_R(Self: TPythonVersion; var T: string);
Begin T := Self.PythonPath; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionInstallPath_W(Self: TPythonVersion; const T: string);
Begin Self.InstallPath := T; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionInstallPath_R(Self: TPythonVersion; var T: string);
Begin T := Self.InstallPath; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionDLLPath_W(Self: TPythonVersion; const T: string);
Begin Self.DLLPath := T; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionDLLPath_R(Self: TPythonVersion; var T: string);
Begin T := Self.DLLPath; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionVersion_W(Self: TPythonVersion; const T: string);
Begin Self.Version := T; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionVersion_R(Self: TPythonVersion; var T: string);
Begin T := Self.Version; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionSysVersion_W(Self: TPythonVersion; const T: string);
Begin Self.SysVersion := T; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionSysVersion_R(Self: TPythonVersion; var T: string);
Begin T := Self.SysVersion; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionIsAllUsers_W(Self: TPythonVersion; const T: Boolean);
Begin Self.IsAllUsers := T; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionIsAllUsers_R(Self: TPythonVersion; var T: Boolean);
Begin T := Self.IsAllUsers; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionIsRegistered_W(Self: TPythonVersion; const T: Boolean);
Begin Self.IsRegistered := T; end;
(*----------------------------------------------------------------------------*)
procedure TPythonVersionIsRegistered_R(Self: TPythonVersion; var T: Boolean);
Begin T := Self.IsRegistered; end;
(*----------------------------------------------------------------------------*)
procedure RIRegister_PythonVersions_Routines(S: TPSExec);
begin
S.RegisterDelphiFunction(@CompareVersions, 'CompareVersions', cdRegister);
S.RegisterDelphiFunction(@IsEXEx64, 'IsEXEx64', cdRegister);
S.RegisterDelphiFunction(@Isx64, 'Isx64', cdRegister);
S.RegisterDelphiFunction(@GetRegisteredPythonVersion, 'GetRegisteredPythonVersion', cdRegister);
S.RegisterDelphiFunction(@GetRegisteredPythonVersions, 'GetRegisteredPythonVersions', cdRegister);
S.RegisterDelphiFunction(@GetLatestRegisteredPythonVersion, 'GetLatestRegisteredPythonVersion', cdRegister);
S.RegisterDelphiFunction(@PythonVersionFromPath, 'PythonVersionFromPath', cdRegister);
S.RegisterDelphiFunction(@GetRegisteredPythonVersion2, 'GetRegisteredPythonVersion2', cdRegister);
S.RegisterDelphiFunction(@GetRegisteredPythonVersions2, 'GetRegisteredPythonVersions2', cdRegister);
S.RegisterDelphiFunction(@GetPythonVersions, 'GetPythonVersions', cdRegister);
S.RegisterDelphiFunction(@GetPythonVersions, 'GetPyVers', cdRegister); //alias
S.RegisterDelphiFunction(@Getservices, 'GetServices', cdRegister);
end;
(*----------------------------------------------------------------------------*)
procedure RIRegister_TPythonVersion(CL: TPSRuntimeClassImporter);
begin
with CL.Add(TPythonVersion) do begin
RegisterConstructor(@TPythonVersion.Create, 'Create');
RegisterMethod(@TPythonVersion.Free, 'Free');
RegisterPropertyHelper(@TPythonVersionIsRegistered_R,@TPythonVersionIsRegistered_W,'IsRegistered');
RegisterPropertyHelper(@TPythonVersionIsAllUsers_R,@TPythonVersionIsAllUsers_W,'IsAllUsers');
RegisterPropertyHelper(@TPythonVersionSysVersion_R,@TPythonVersionSysVersion_W,'SysVersion');
RegisterPropertyHelper(@TPythonVersionVersion_R,@TPythonVersionVersion_W,'Version');
RegisterPropertyHelper(@TPythonVersionDLLPath_R,@TPythonVersionDLLPath_W,'DLLPath');
RegisterPropertyHelper(@TPythonVersionInstallPath_R,@TPythonVersionInstallPath_W,'InstallPath');
RegisterPropertyHelper(@TPythonVersionPythonPath_R,@TPythonVersionPythonPath_W,'PythonPath');
RegisterMethod(@TPythonVersion.Is_venv, 'Is_venv');
RegisterMethod(@TPythonVersion.Is_virtualenv, 'Is_virtualenv');
RegisterMethod(@TPythonVersion.Is_conda, 'Is_conda');
RegisterMethod(@TPythonVersion.AssignTo, 'AssignTo');
RegisterPropertyHelper(@TPythonVersionPythonExecutable_R,nil,'PythonExecutable');
RegisterPropertyHelper(@TPythonVersionDLLName_R,nil,'DLLName');
RegisterPropertyHelper(@TPythonVersionSysArchitecture_R,nil,'SysArchitecture');
RegisterPropertyHelper(@TPythonVersionIsPython3K_R,nil,'IsPython3K');
RegisterPropertyHelper(@TPythonVersionHelpFile_R,@TPythonVersionHelpFile_W,'HelpFile');
RegisterPropertyHelper(@TPythonVersionHelpFile_R2,@TPythonVersionHelpFile_W2,'HelpFile2');
RegisterPropertyHelper(@TPythonVersionDisplayName_R,@TPythonVersionDisplayName_W,'DisplayName');
RegisterPropertyHelper(@TPythonVersionApiVersion_R,nil,'ApiVersion');
end; //}
end;
(*----------------------------------------------------------------------------*)
procedure RIRegister_PythonVersions(CL: TPSRuntimeClassImporter);
begin
RIRegister_TPythonVersion(CL);
end;
{ TPSImport_PythonVersions }
(*----------------------------------------------------------------------------*)
procedure TPSImport_PythonVersions.CompileImport1(CompExec: TPSScript);
begin
SIRegister_PythonVersions(CompExec.Comp);
end;
(*----------------------------------------------------------------------------*)
procedure TPSImport_PythonVersions.ExecImport1(CompExec: TPSScript; const ri: TPSRuntimeClassImporter);
begin
RIRegister_PythonVersions(ri);
RIRegister_PythonVersions_Routines(CompExec.Exec); // comment it if no routines
end;
(*----------------------------------------------------------------------------*)
end.