mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
parent
c68cd7be64
commit
ea24922b71
4 changed files with 59 additions and 20 deletions
|
|
@ -1018,6 +1018,7 @@ class PyDB:
|
|||
if os.path.isfile(new_target):
|
||||
file = new_target
|
||||
|
||||
m = None
|
||||
if globals is None:
|
||||
m = save_main_module(file, 'pydevd')
|
||||
globals = m.__dict__
|
||||
|
|
@ -1029,27 +1030,28 @@ class PyDB:
|
|||
if locals is None:
|
||||
locals = globals
|
||||
|
||||
# Predefined (writable) attributes: __name__ is the module's name;
|
||||
# __doc__ is the module's documentation string, or None if unavailable;
|
||||
# __file__ is the pathname of the file from which the module was loaded,
|
||||
# if it was loaded from a file. The __file__ attribute is not present for
|
||||
# C modules that are statically linked into the interpreter; for extension modules
|
||||
# loaded dynamically from a shared library, it is the pathname of the shared library file.
|
||||
|
||||
|
||||
# I think this is an ugly hack, bug it works (seems to) for the bug that says that sys.path should be the same in
|
||||
# debug and run.
|
||||
if sys.path[0] != '' and m is not None and m.__file__.startswith(sys.path[0]):
|
||||
# print >> sys.stderr, 'Deleting: ', sys.path[0]
|
||||
del sys.path[0]
|
||||
|
||||
if not is_module:
|
||||
# now, the local directory has to be added to the pythonpath
|
||||
# sys.path.insert(0, os.getcwd())
|
||||
# Changed: it's not the local directory, but the directory of the file launched
|
||||
# The file being run must be in the pythonpath (even if it was not before)
|
||||
sys.path.insert(0, os.path.split(rPath(file))[0])
|
||||
|
||||
if set_trace:
|
||||
# Predefined (writable) attributes: __name__ is the module's name;
|
||||
# __doc__ is the module's documentation string, or None if unavailable;
|
||||
# __file__ is the pathname of the file from which the module was loaded,
|
||||
# if it was loaded from a file. The __file__ attribute is not present for
|
||||
# C modules that are statically linked into the interpreter; for extension modules
|
||||
# loaded dynamically from a shared library, it is the pathname of the shared library file.
|
||||
|
||||
|
||||
# I think this is an ugly hack, bug it works (seems to) for the bug that says that sys.path should be the same in
|
||||
# debug and run.
|
||||
if sys.path[0] != '' and m.__file__.startswith(sys.path[0]):
|
||||
# print >> sys.stderr, 'Deleting: ', sys.path[0]
|
||||
del sys.path[0]
|
||||
|
||||
if not is_module:
|
||||
# now, the local directory has to be added to the pythonpath
|
||||
# sys.path.insert(0, os.getcwd())
|
||||
# Changed: it's not the local directory, but the directory of the file launched
|
||||
# The file being run must be in the pythonpath (even if it was not before)
|
||||
sys.path.insert(0, os.path.split(rPath(file))[0])
|
||||
|
||||
while not self.ready_to_run:
|
||||
time.sleep(0.1) # busy wait until we receive run command
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
import bar
|
||||
print('Worked')
|
||||
35
ptvsd/_vendored/pydevd/tests_python/test_run.py
Normal file
35
ptvsd/_vendored/pydevd/tests_python/test_run.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
pytest_plugins = [
|
||||
str('_pytest.pytester'),
|
||||
]
|
||||
|
||||
def _run_and_check(testdir, path):
|
||||
result = testdir.runpython(path)
|
||||
result.stdout.fnmatch_lines([
|
||||
'Worked'
|
||||
])
|
||||
|
||||
def test_run(testdir):
|
||||
from tests_python import debugger_unittest
|
||||
from os.path import os
|
||||
|
||||
foo_dir = debugger_unittest._get_debugger_test_file(os.path.join('resources', 'launch', 'foo'))
|
||||
pydevd_dir = os.path.dirname(os.path.dirname(__file__))
|
||||
assert os.path.exists(os.path.join(pydevd_dir, 'pydevd.py'))
|
||||
|
||||
_run_and_check(testdir, testdir.makepyfile('''
|
||||
import sys
|
||||
sys.path.append(%(pydevd_dir)r)
|
||||
import pydevd
|
||||
py_db = pydevd.PyDB()
|
||||
py_db.ready_to_run = True
|
||||
py_db.run(%(foo_dir)r)
|
||||
''' % locals()))
|
||||
|
||||
_run_and_check(testdir, testdir.makepyfile('''
|
||||
import sys
|
||||
sys.path.append(%(pydevd_dir)r)
|
||||
import pydevd
|
||||
py_db = pydevd.PyDB()
|
||||
py_db.run(%(foo_dir)r, set_trace=False)
|
||||
''' % locals()))
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue