Skip to content

Commit

Permalink
Support having no sys.argv in debugger. Fixes #473
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Dec 12, 2020
1 parent 9351639 commit e573ea7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,9 @@ def get_variable_presentation(setting, default):
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 = ''

Expand Down
14 changes: 9 additions & 5 deletions src/debugpy/_vendored/pydevd/pydev_ipython/inputhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
# Utilities
#-----------------------------------------------------------------------------


def ignore_CTRL_C():
"""Ignore CTRL+C (not implemented)."""
pass


def allow_CTRL_C():
"""Take CTRL+C into account (not implemented)."""
pass
Expand Down Expand Up @@ -297,7 +299,6 @@ def disable_tk(self):
"""
self.clear_inputhook()


def enable_glut(self, app=None):
""" Enable event loop integration with GLUT.
Expand Down Expand Up @@ -329,13 +330,14 @@ def enable_glut(self, app=None):
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)
Expand All @@ -349,7 +351,6 @@ def enable_glut(self, app=None):
self._current_gui = GUI_GLUT
self._apps[GUI_GLUT] = True


def disable_glut(self):
"""Disable event loop integration with glut.
Expand Down Expand Up @@ -430,6 +431,7 @@ def enable_mac(self, app=None):
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']
Expand All @@ -451,6 +453,7 @@ def current_gui(self):
"""Return a string indicating the currently active GUI or None."""
return self._current_gui


inputhook_manager = InputHookManager()

enable_wx = inputhook_manager.enable_wx
Expand Down Expand Up @@ -484,6 +487,7 @@ def current_gui(self):
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.
Expand Down Expand Up @@ -535,6 +539,7 @@ def enable_gui(gui=None, app=None):
raise ValueError(e)
return gui_hook(app)


__all__ = [
"GUI_WX",
"GUI_QT",
Expand All @@ -548,7 +553,6 @@ def enable_gui(gui=None, app=None):
"GUI_GTK3",
"GUI_NONE",


"ignore_CTRL_C",
"allow_CTRL_C",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
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!')

0 comments on commit e573ea7

Please sign in to comment.