Remove sys.path entry for vendored pydevd after loading it.

Improve error reporting when pydevd is imported before ptvsd.
This commit is contained in:
Pavel Minaev 2018-02-21 13:18:08 -08:00
parent 688f7e970d
commit 4d4fc58fce
2 changed files with 26 additions and 5 deletions

View file

@ -5,10 +5,32 @@
__author__ = "Microsoft Corporation <ptvshelp@microsoft.com>"
__version__ = "4.0.0a1"
# ptvsd must always be imported before pydevd
import sys
assert 'pydevd' not in sys.modules
import os.path
# ptvsd must always be imported before pydevd
if 'pydevd' in sys.modules:
raise ImportError('ptvsd must be imported before pydevd')
# Add our vendored pydevd directory to path, so that it gets found first.
import os.path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'pydevd'))
# Load our wrapper module, which will detour various functionality inside pydevd.
# This must be done before the imports below, otherwise some modules will end up
# with local copies of pre-detour functions.
import ptvsd.wrapper
# Now make sure all the top-level modules and packages in pydevd are loaded.
import _pydev_bundle
import _pydev_imps
import _pydev_runfiles
import _pydevd_bundle
import _pydevd_frame_eval
import pydev_ipython
import pydevd_concurrency_analyser
import pydevd_plugins
import pydevd
# Remove sys.path entry added above - any pydevd modules that aren't loaded at
# this point, will be loaded using their parent package's __path__.
del sys.path[0]

View file

@ -2,8 +2,7 @@
# Licensed under the MIT License. See LICENSE in the project root
# for license information.
# TODO: with_statement is not needed
from __future__ import print_function, with_statement, absolute_import
from __future__ import print_function, absolute_import
import atexit
import os