Skip to content

Commit 6cb0619

Browse files
authored
Merge pull request #43 from pyscripter/master
Upstream merge
2 parents 1a114a2 + 615522f commit 6cb0619

File tree

2 files changed

+67
-16
lines changed

2 files changed

+67
-16
lines changed

Source/PythonEngine.pas

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,9 @@ TPythonVersionProp = record
760760
cf_feature_version : integer; //added in Python 3.8
761761
end;
762762

763+
const
764+
PyCF_ONLY_AST = $0400;
765+
763766
// from datetime.h
764767

765768

@@ -1061,6 +1064,8 @@ EPySyntaxError = class (EPyStandardError)
10611064
ELineStr: UnicodeString;
10621065
ELineNumber: Integer;
10631066
EOffset: Integer;
1067+
EEndLineNumber: Integer;
1068+
EEndOffset: Integer;
10641069
end;
10651070
EPyIndentationError = class (EPySyntaxError);
10661071
EPyTabError = class (EPyIndentationError);
@@ -4469,6 +4474,7 @@ procedure TPythonEngine.Initialize;
44694474

44704475
var
44714476
i : Integer;
4477+
WorkAround: AnsiString;
44724478
begin
44734479
if Assigned(gPythonEngine) then
44744480
raise Exception.Create('There is already one instance of TPythonEngine running' );
@@ -4506,8 +4512,27 @@ procedure TPythonEngine.Initialize;
45064512
with Clients[i] do
45074513
if not Initialized then
45084514
Initialize;
4515+
4516+
// WorkAround for https://github.com/python/cpython/issues/100171
4517+
if (MajorVersion = 3) and (MinorVersion >= 11) then
4518+
begin
4519+
WorkAround :=
4520+
'import sys'#13#10 + //0
4521+
'if sys.version_info > (3,11,0):'#13#10 + //1
4522+
' import os'#13#10 + //2
4523+
''#13#10 + //3
4524+
' dllpath = os.path.join(sys.base_prefix, ''DLLs'')'#13#10 + //4
4525+
' if dllpath not in sys.path:'#13#10 + //5
4526+
' sys.path.insert(3, dllpath)'#13#10 + //6
4527+
''#13#10 + //7
4528+
' del dllpath'#13#10 + //8
4529+
' del os'#13#10 + //9
4530+
'del sys'#13#10; //10
4531+
ExecString(WorkAround);
4532+
end;
4533+
45094534
if InitScript.Count > 0 then
4510-
ExecStrings( InitScript );
4535+
ExecStrings(InitScript);
45114536
if Assigned(FOnAfterInit) then
45124537
FOnAfterInit(Self);
45134538
end;
@@ -5005,12 +5030,14 @@ procedure TPythonEngine.RaiseError;
50055030

50065031
function DefineSyntaxError( E : EPySyntaxError; const sType, sValue : UnicodeString; err_type, err_value : PPyObject ) : EPySyntaxError;
50075032
var
5008-
s_value : UnicodeString;
5009-
s_line : UnicodeString;
5010-
s_filename : UnicodeString;
5011-
i_line_number : Integer;
5012-
i_offset : Integer;
5013-
tmp : PPyObject;
5033+
s_value : UnicodeString;
5034+
s_line : UnicodeString;
5035+
s_filename : UnicodeString;
5036+
i_line_number : Integer;
5037+
i_offset : Integer;
5038+
i_end_line_number : Integer;
5039+
i_end_offset : Integer;
5040+
tmp : PPyObject;
50145041
begin
50155042
Result := E;
50165043
Result.EName := sType;
@@ -5020,8 +5047,10 @@ procedure TPythonEngine.RaiseError;
50205047
s_filename := '';
50215048
i_line_number := 0;
50225049
i_offset := 0;
5050+
i_end_line_number := 0;
5051+
i_end_offset := 0;
50235052
// Sometimes there's a tuple instead of instance...
5024-
if PyTuple_Check( err_value ) and (PyTuple_Size( err_value) >= 2) then
5053+
if PyTuple_Check(err_value) and (PyTuple_Size( err_value) >= 2) then
50255054
begin
50265055
s_value := PyObjectAsString(PyTuple_GetItem( err_value, 0));
50275056
err_value := PyTuple_GetItem( err_value, 1);
@@ -5066,19 +5095,34 @@ procedure TPythonEngine.RaiseError;
50665095
if Assigned(tmp) and PyUnicode_Check(tmp) then
50675096
s_value := PyUnicodeAsString(tmp);
50685097
Py_XDECREF(tmp);
5098+
if MajorVersion >= 10 then
5099+
begin
5100+
// Get the end offset of the error
5101+
tmp := PyObject_GetAttrString(err_value, 'end_offset' );
5102+
if Assigned(tmp) and PyLong_Check(tmp) then
5103+
i_end_offset := PyLong_AsLong(tmp);
5104+
Py_XDECREF(tmp);
5105+
// Get the end line number of the error
5106+
tmp := PyObject_GetAttrString(err_value, 'end_lineno' );
5107+
if Assigned(tmp) and PyLong_Check(tmp) then
5108+
i_end_line_number := PyLong_AsLong(tmp);
5109+
Py_XDECREF(tmp);
5110+
end;
50695111
end;
50705112
// If all is ok
50715113
if s_value <> '' then
50725114
begin
50735115
with Result do
50745116
begin
5075-
Message := Format('%s: %s (line %d, offset %d): ''%s''', [sType,s_value,i_line_number, i_offset,s_line]);
5076-
EName := sType;
5077-
EValue := s_value;
5078-
EFileName := s_filename;
5079-
ELineNumber := i_line_number;
5080-
EOffset := i_offset;
5081-
ELineStr := s_line;
5117+
Message := Format('%s: %s (line %d, offset %d): ''%s''', [sType,s_value,i_line_number, i_offset,s_line]);
5118+
EName := sType;
5119+
EValue := s_value;
5120+
EFileName := s_filename;
5121+
ELineNumber := i_line_number;
5122+
EOffset := i_offset;
5123+
EEndLineNumber := i_end_line_number;
5124+
EEndOffset := i_end_offset;
5125+
ELineStr := s_line;
50825126
end;
50835127
end
50845128
else

Source/PythonVersions.pas

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ function TPythonVersion.GetDisplayName: string;
166166
function TPythonVersion.GetHelpFile: string;
167167
var
168168
PythonHelpFilePath: string;
169+
HtmlIndex: string;
169170
Res: Integer;
170171
SR: TSearchRec;
171172
begin
@@ -176,7 +177,13 @@ function TPythonVersion.GetHelpFile: string;
176177
PythonHelpFilePath := IncludeTrailingPathDelimiter(InstallPath) + 'Doc\python*.chm';
177178
Res := FindFirst(PythonHelpFilePath, faAnyFile, SR);
178179
if Res = 0 then
179-
Result := IncludeTrailingPathDelimiter(InstallPath) + 'Doc\' + SR.Name;
180+
Result := IncludeTrailingPathDelimiter(InstallPath) + 'Doc\' + SR.Name
181+
else if Result = '' then
182+
begin
183+
HtmlIndex := IncludeTrailingPathDelimiter(InstallPath) + 'Doc\html\index.html';
184+
if FileExists(HtmlIndex) then
185+
Result := HtmlIndex;
186+
end;
180187
FindClose(SR);
181188
end;
182189
end;

0 commit comments

Comments
 (0)