Factor out helper functions for the debugger "main()".

This commit is contained in:
Eric Snow 2018-03-13 17:18:36 +00:00
parent 473c34771f
commit 0ca1429d78

View file

@ -4,6 +4,10 @@
import sys
# import the wrapper first, so that it gets a chance
# to detour pydevd socket functionality.
import ptvsd.wrapper
__author__ = "Microsoft Corporation <ptvshelp@microsoft.com>"
__version__ = "4.0.0a1"
@ -13,22 +17,39 @@ DONT_DEBUG = []
def debug(filename, port_num, debug_id, debug_options, run_as):
# TODO: docstring
# import the wrapper first, so that it gets a chance
# to detour pydevd socket functionality.
import ptvsd.wrapper
import pydevd
args = [
'--port', str(port_num),
'--client', '127.0.0.1',
]
address = (None, port_num)
if run_as == 'module':
args.append('--module')
args.extend(('--file', filename + ":"))
_run_module(address, filename)
else:
args.extend(('--file', filename))
sys.argv[1:0] = args
_run_file(address, filename)
def _run_module(address, modname):
filename = modname + ':'
argv = _run_argv(address, filename)
argv.append('--module')
_run(argv)
def _run_file(address, filename):
argv = _run_argv(address, filename)
_run(argv)
def _run_argv(address, filename):
host, port = address
if host is None:
host = '127.0.0.1'
return [
'--port', str(port),
'--client', host,
'--file', filename,
]
def _run(argv):
import pydevd
sys.argv[1:0] = argv
try:
pydevd.main()
except SystemExit as ex: