Skip to content

Commit

Permalink
Issue 543
Browse files Browse the repository at this point in the history
  • Loading branch information
pyscripter committed Mar 11, 2012
1 parent 20f47d3 commit b32f952
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 20 deletions.
22 changes: 21 additions & 1 deletion cPyBaseDebugger.pas
Expand Up @@ -9,7 +9,8 @@

interface
uses
Windows, SysUtils, Classes, uEditAppIntfs, PythonEngine, Forms, Contnrs, cTools;
Windows, SysUtils, Classes, uEditAppIntfs, PythonEngine, Forms,
Contnrs, cTools, cRefactoring;

type
TPythonEngineType = (peInternal, peRemote, peRemoteTk, peRemoteWx);
Expand Down Expand Up @@ -125,10 +126,15 @@ TBaseNameSpaceItem = class(TObject)

TPyBaseInterpreter = class(TObject)
// Base (abstract) class for implementing Python Interpreters
private
function GetMainModule: TModuleProxy;
protected
fInterpreterCapabilities : TInterpreterCapabilities;
fEngineType : TPythonEngineType;
fMainModule : TModuleProxy;
procedure CreateMainModule; virtual; abstract;
public
destructor Destroy; override;
procedure Initialize; virtual;
// Python Path
function SysPathAdd(const Path : string) : boolean; virtual; abstract;
Expand Down Expand Up @@ -157,6 +163,7 @@ TPyBaseInterpreter = class(TObject)
function UnitTestResult : Variant; virtual; abstract;
property EngineType : TPythonEngineType read fEngineType;
property InterpreterCapabilities : TInterpreterCapabilities read fInterpreterCapabilities;
property MainModule : TModuleProxy read GetMainModule;
end;

TPyBaseDebugger = class(TObject)
Expand Down Expand Up @@ -404,6 +411,19 @@ function TPyBaseInterpreter.AddPathToPythonPath(const Path: string;
Result := TPythonPathAdder.Create(SysPathAdd, SysPathRemove, Path, AutoRemove);
end;

destructor TPyBaseInterpreter.Destroy;
begin
FreeAndNil(fMainModule);
inherited;
end;

function TPyBaseInterpreter.GetMainModule: TModuleProxy;
begin
if not Assigned(fMainModule) then
CreateMainModule;
Result := fMainModule;
end;

procedure TPyBaseInterpreter.HandlePyException(E: EPythonError; SkipFrames : integer = 1);
Var
TI : TTracebackItem;
Expand Down
11 changes: 8 additions & 3 deletions cPyDebugger.pas
Expand Up @@ -77,6 +77,8 @@ TPyInternalInterpreter = class(TPyBaseInterpreter)
fII : Variant; // Python VarPyth wrapper to the interactive interpreter
fDebugger : Variant;
fOldargv : Variant;
protected
procedure CreateMainModule; override;
public
constructor Create(II : Variant);

Expand Down Expand Up @@ -164,7 +166,7 @@ implementation
uses dmCommands, frmPythonII, Variants, VarPyth, frmMessages, frmPyIDEMain,
MMSystem, Math, uCommonFunctions,
cParameters, StringResources, Dialogs, JvDSADialogs,
gnugettext;
gnugettext, cRefactoring;

{ TFrameInfo }

Expand Down Expand Up @@ -940,12 +942,15 @@ constructor TPyInternalInterpreter.Create(II: Variant);
fII := II;
fDebugger := II.debugger;

// Execute PyscripterSetup.py here

// sys.displayhook
fII.setupdisplayhook()
end;

procedure TPyInternalInterpreter.CreateMainModule;
begin
fMainModule := TModuleProxy.CreateFromModule(VarPyth.MainModule);
end;

function TPyInternalInterpreter.EvalCode(const Expr: string): Variant;
begin
// may raise exceptions
Expand Down
11 changes: 10 additions & 1 deletion cPyRemoteDebugger.pas
Expand Up @@ -34,6 +34,8 @@ TPyRemoteInterpreter = class(TPyBaseInterpreter)
fDebugger : Variant;
fSocketPort: integer;
fRpycPath : string;
protected
procedure CreateMainModule; override;
public
constructor Create(AEngineType : TPythonEngineType = peRemote);
destructor Destroy; override;
Expand Down Expand Up @@ -157,7 +159,8 @@ implementation
VarPyth, StringResources, frmPythonII, Dialogs, dmCommands,
cParameters, uCommonFunctions, frmMessages, frmPyIDEMain,
frmVariables, frmCallStack, frmUnitTests, JvDSADialogs,
gnugettext, JclStrings, JclSysUtils, cProjectClasses, JvJCLUtils;
gnugettext, JclStrings, JclSysUtils, cProjectClasses, JvJCLUtils,
cRefactoring;

{ TRemNameSpaceItem }
constructor TRemNameSpaceItem.Create(aName : string; aPyObject : Variant;
Expand Down Expand Up @@ -1069,6 +1072,11 @@ function TPyRemoteInterpreter.CreateAndConnectToServer : Boolean;
end;
end;

procedure TPyRemoteInterpreter.CreateMainModule;
begin
fMainModule := TModuleProxy.CreateFromModule(Conn.modules.__main__);
end;

procedure TPyRemoteInterpreter.ServeConnection;
begin
CheckConnected;
Expand Down Expand Up @@ -1127,6 +1135,7 @@ procedure TPyRemoteInterpreter.ShutDownServer;
// Do not destroy Remote Debugger
// PyControl.ActiveDebugger := nil;

FreeAndNil(fMainModule);
VarClear(fOldArgv);
VarClear(fDebugger);
VarClear(RPI);
Expand Down
30 changes: 17 additions & 13 deletions cRefactoring.pas
Expand Up @@ -145,7 +145,7 @@ implementation
frmPythonII, PythonEngine, VarPyth, dmCommands,
uEditAppIntfs,
uCommonFunctions, Math, StringResources,
cPyDebugger, gnugettext, StrUtils, JclStrings, DateUtils;
cPyDebugger, gnugettext, StrUtils, JclStrings, DateUtils, cPyBaseDebugger;

{ TPyScripterRefactor }

Expand Down Expand Up @@ -346,17 +346,21 @@ function TPyScripterRefactor.GetParsedModule(const ModuleName: string;
// Last effort. Search in sys.modules
// Special modules should already be there
if Result = nil then begin
InSysModules := SysModule.modules.__contains__(DottedModuleName);
if InSysModules and VarIsPythonModule(SysModule.modules.__getitem__(DottedModuleName)) then begin
// If the source file does not exist look at sys.modules to see whether it
// is available in the interpreter. If yes then create a proxy module
Index := fProxyModules.IndexOf(DottedModuleName);
if Index < 0 then begin
Index := fProxyModules.AddObject(DottedModuleName,
TModuleProxy.CreateFromModule(SysModule.modules.__getitem__(DottedModuleName)));
Result := fProxyModules.Objects[Index] as TParsedModule;
end else
Result := fProxyModules.Objects[Index] as TParsedModule;
if DottedModuleName = '__main__' then
Result := PyControl.ActiveInterpreter.MainModule
else begin
InSysModules := SysModule.modules.__contains__(DottedModuleName);
if InSysModules and VarIsPythonModule(SysModule.modules.__getitem__(DottedModuleName)) then begin
// If the source file does not exist look at sys.modules to see whether it
// is available in the interpreter. If yes then create a proxy module
Index := fProxyModules.IndexOf(DottedModuleName);
if Index < 0 then begin
Index := fProxyModules.AddObject(DottedModuleName,
TModuleProxy.CreateFromModule(SysModule.modules.__getitem__(DottedModuleName)));
Result := fProxyModules.Objects[Index] as TParsedModule;
end else
Result := fProxyModules.Objects[Index] as TParsedModule;
end;
end;
end;
end;
Expand Down Expand Up @@ -1103,7 +1107,7 @@ procedure TModuleProxy.Expand;
constructor TModuleProxy.CreateFromModule(AModule: Variant);
begin
inherited Create;
if not VarIsPythonModule(AModule) then
if not VarIsPython(AModule) or (AModule.__class__.__name__ <> 'module') then
Raise Exception.Create('TModuleProxy creation error');
Name := AModule.__name__;
fPyModule := AModule;
Expand Down
4 changes: 2 additions & 2 deletions frmPyIDEMain.pas
Expand Up @@ -370,8 +370,8 @@
New search option "Auto Case Sensitive" (case insensitive when search text is lower case)
The Abort command raises a KeyboardInterrupt at the Remote Engine (Issue 618)
Issues addressed
516, 549, 563, 564, 568, 576, 587, 591, 592, 594,
597, 598, 599, 612, 613, 615
516, 348, 549, 563, 564, 568, 576, 587, 591, 592,
594, 597, 598, 599, 612, 613, 615
-----------------------------------------------------------------------------}

// Bugs and minor features
Expand Down

0 comments on commit b32f952

Please sign in to comment.