From e573ea771ac2ff7088b333384c6a873d730b73fd Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Thu, 10 Dec 2020 10:19:12 -0300 Subject: [PATCH] Support having no sys.argv in debugger. Fixes #473 --- .../pydevd_process_net_command_json.py | 5 +++-- .../_vendored/pydevd/pydev_ipython/inputhook.py | 14 +++++++++----- .../resources/_debugger_case_remote.py | 7 ++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command_json.py b/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command_json.py index 67841257..d1827d5c 100644 --- a/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command_json.py +++ b/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command_json.py @@ -400,8 +400,9 @@ class PyDevJsonCommandProcessor(object): self.api.stop_on_entry() def _send_process_event(self, py_db, start_method): - if len(sys.argv) > 0: - name = sys.argv[0] + argv = getattr(sys, 'argv', []) + if len(argv) > 0: + name = argv[0] else: name = '' diff --git a/src/debugpy/_vendored/pydevd/pydev_ipython/inputhook.py b/src/debugpy/_vendored/pydevd/pydev_ipython/inputhook.py index f12b7f73..4494da9d 100644 --- a/src/debugpy/_vendored/pydevd/pydev_ipython/inputhook.py +++ b/src/debugpy/_vendored/pydevd/pydev_ipython/inputhook.py @@ -38,10 +38,12 @@ GUI_NONE = 'none' # i.e. disable # Utilities #----------------------------------------------------------------------------- + def ignore_CTRL_C(): """Ignore CTRL+C (not implemented).""" pass + def allow_CTRL_C(): """Take CTRL+C into account (not implemented).""" pass @@ -297,7 +299,6 @@ class InputHookManager(object): """ self.clear_inputhook() - def enable_glut(self, app=None): """ Enable event loop integration with GLUT. @@ -329,13 +330,14 @@ class InputHookManager(object): glut_idle, inputhook_glut if GUI_GLUT not in self._apps: - glut.glutInit(sys.argv) + argv = getattr(sys, 'argv', []) + glut.glutInit(argv) glut.glutInitDisplayMode(glut_display_mode) # This is specific to freeglut if bool(glut.glutSetOption): glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS) - glut.glutCreateWindow(sys.argv[0]) + glut.glutCreateWindow(argv[0] if len(argv) > 0 else '') glut.glutReshapeWindow(1, 1) glut.glutHideWindow() glut.glutWMCloseFunc(glut_close) @@ -349,7 +351,6 @@ class InputHookManager(object): self._current_gui = GUI_GLUT self._apps[GUI_GLUT] = True - def disable_glut(self): """Disable event loop integration with glut. @@ -430,6 +431,7 @@ class InputHookManager(object): possible to choose backend before importing pyplot for the first time only. """ + def inputhook_mac(app=None): if self.pyplot_imported: pyplot = sys.modules['matplotlib.pyplot'] @@ -451,6 +453,7 @@ class InputHookManager(object): """Return a string indicating the currently active GUI or None.""" return self._current_gui + inputhook_manager = InputHookManager() enable_wx = inputhook_manager.enable_wx @@ -484,6 +487,7 @@ set_return_control_callback = inputhook_manager.set_return_control_callback get_return_control_callback = inputhook_manager.get_return_control_callback get_inputhook = inputhook_manager.get_inputhook + # Convenience function to switch amongst them def enable_gui(gui=None, app=None): """Switch amongst GUI input hooks by name. @@ -535,6 +539,7 @@ def enable_gui(gui=None, app=None): raise ValueError(e) return gui_hook(app) + __all__ = [ "GUI_WX", "GUI_QT", @@ -548,7 +553,6 @@ __all__ = [ "GUI_GTK3", "GUI_NONE", - "ignore_CTRL_C", "allow_CTRL_C", diff --git a/src/debugpy/_vendored/pydevd/tests_python/resources/_debugger_case_remote.py b/src/debugpy/_vendored/pydevd/tests_python/resources/_debugger_case_remote.py index f1aab4e4..82deefa0 100644 --- a/src/debugpy/_vendored/pydevd/tests_python/resources/_debugger_case_remote.py +++ b/src/debugpy/_vendored/pydevd/tests_python/resources/_debugger_case_remote.py @@ -3,13 +3,14 @@ if __name__ == '__main__': import sys port = int(sys.argv[1]) root_dirname = os.path.dirname(os.path.dirname(__file__)) - + if root_dirname not in sys.path: sys.path.append(root_dirname) - + + del sys.argv + import pydevd print('before pydevd.settrace') pydevd.settrace(port=port) print('after pydevd.settrace') print('TEST SUCEEDED!') - \ No newline at end of file