Convert import side-effects into explicit calls.

This commit is contained in:
Eric Snow 2018-03-26 17:36:48 +00:00
parent 2ec1bc93db
commit e08feef596
4 changed files with 19 additions and 16 deletions

View file

@ -2,14 +2,13 @@
# Licensed under the MIT License. See LICENSE in the project root
# for license information.
import ptvsd.wrapper
__author__ = "Microsoft Corporation <ptvshelp@microsoft.com>"
__version__ = "4.0.0a5"
if __name__ == '__main__':
# import the wrapper first, so that it gets a chance
# to detour pydevd socket functionality.
import ptvsd.wrapper # noqa
import pydevd
pydevd = ptvsd.wrapper.install()
pydevd.main()

View file

@ -48,7 +48,7 @@ def _run_argv(address, filename):
def _run(argv):
import pydevd
pydevd = ptvsd.wrapper.install(argv)
sys.argv[1:0] = argv
try:
pydevd.main()

View file

@ -1783,6 +1783,13 @@ def start_client(host, port, addhandlers=True):
return pydevd
# These are the functions pydevd invokes to get a socket to the client.
pydevd_comm.start_server = start_server
pydevd_comm.start_client = start_client
def install(start_server=start_server, start_client=start_client):
"""Configure pydevd to use our wrapper."""
# These are the functions pydevd invokes to get a socket to the client.
pydevd_comm.start_server = start_server
pydevd_comm.start_client = start_client
# Force a fresh pydevd.
sys.modules.pop('pydevd', None)
import pydevd # noqa
return pydevd

View file

@ -1,12 +1,9 @@
import os
import os.path
import sys
import threading
import warnings
import _pydevd_bundle.pydevd_comm as pydevd_comm
from ptvsd import debugger
from ptvsd import debugger, wrapper
from tests.helpers import protocol
from ._binder import BinderBase
@ -24,10 +21,10 @@ class Binder(BinderBase):
def new_pydevd_sock(*args):
self._start_ptvsd()
return self.ptvsd.fakesock
pydevd_comm.start_server = new_pydevd_sock
pydevd_comm.start_client = new_pydevd_sock
# Force a fresh pydevd.
sys.modules.pop('pydevd', None)
wrapper.install(
start_server=new_pydevd_sock,
start_client=new_pydevd_sock,
)
if self.module is None:
debugger._run_file(self.address, self.filename)
else: