diff -r 4370a8b30648 -r 554fdb07c856 eric6/DebugClients/Python/DebugClientBase.py --- a/eric6/DebugClients/Python/DebugClientBase.py Fri Dec 18 12:44:31 2020 +0100 +++ b/eric6/DebugClients/Python/DebugClientBase.py Fri Dec 18 16:48:14 2020 +0100 @@ -2035,7 +2035,8 @@ def startProgInDebugger(self, progargs, wd='', host=None, port=None, exceptions=True, tracePython=False, redirect=True, passive=True, - multiprocessSupport=False, codeStr=""): + multiprocessSupport=False, codeStr="", + scriptModule=""): """ Public method used to start the remote debugger. @@ -2057,6 +2058,8 @@ @type bool @param codeStr string containing Python code to execute @type str + @param scriptModule name of a module to be executed as a script + @type str @return exit code of the debugged program @rtype int """ @@ -2111,6 +2114,19 @@ sys.modules['__main__'] = self.debugMod if codeStr: code = self.__compileCommand(codeStr) + elif scriptModule: + import runpy + modName, modSpec, code = runpy._get_module_details(scriptModule) + self.running = code.co_filename + self.debugMod.__dict__.clear() + self.debugMod.__dict__.update({ + "__name__": "__main__", + "__file__": self.running, + "__package__": modSpec.parent, + "__loader__": modSpec.loader, + "__spec__": modSpec, + "__builtins__": __builtins__, + }) else: code = self.__compileFileSource(self.running) if code: @@ -2160,7 +2176,6 @@ time.sleep(3) return None - # TODO: add support for the '-m' python invocation => '--module' def main(self): """ Public method implementing the main method. @@ -2175,7 +2190,8 @@ redirect = True passive = True multiprocess = False - hasCode = False + codeStr = "" + scriptModule = "" while args[0]: if args[0] == '-h': host = args[1] @@ -2207,8 +2223,13 @@ elif args[0] == '--multiprocess': multiprocess = True del args[0] - elif args[0] == '--code': - hasCode = True + elif args[0] in ('-c', '--code'): + codeStr = args[1] + del args[0] + del args[0] + elif args[0] in ('-m', '--module'): + scriptModule = args[1] + del args[0] del args[0] elif args[0] == '--': del args[0] @@ -2230,15 +2251,11 @@ if not self.noencoding: self.__coding = self.defaultCoding patchNewProcessFunctions(multiprocess, self) - if hasCode: - codeStr = args.pop(0) - else: - codeStr = "" res = self.startProgInDebugger( args, wd, host, port, exceptions=exceptions, tracePython=tracePython, redirect=redirect, passive=passive, multiprocessSupport=multiprocess, - codeStr=codeStr + codeStr=codeStr, scriptModule=scriptModule, ) sys.exit(res) else: