Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Fix issue launching with --nodebug. Fixes #745 (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz authored and karthiknadig committed Aug 27, 2018
1 parent c68cd7b commit ea24922
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 20 deletions.
42 changes: 22 additions & 20 deletions ptvsd/_vendored/pydevd/pydevd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,7 @@ def run(self, file, globals=None, locals=None, is_module=False, set_trace=True):
if os.path.isfile(new_target):
file = new_target

m = None
if globals is None:
m = save_main_module(file, 'pydevd')
globals = m.__dict__
Expand All @@ -1029,27 +1030,28 @@ def run(self, file, globals=None, locals=None, is_module=False, set_trace=True):
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import bar
print('Worked')
Empty file.
35 changes: 35 additions & 0 deletions ptvsd/_vendored/pydevd/tests_python/test_run.py
Original file line number Diff line number Diff line change
@@ -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()))

0 comments on commit ea24922

Please sign in to comment.