Filter ptvsd files while tracing (#408)

* Implement tracing filter for ptvsd files

* Tests for ptvsd file tracing

* Clean up regex

* Linter fixes

* Addressing comments.
This commit is contained in:
Karthik Nadig 2018-05-04 14:38:46 -07:00 committed by GitHub
parent 8a8ba9f449
commit 36b5bdfc51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 0 deletions

View file

@ -36,6 +36,7 @@ pydevd_constants.MAXIMUM_VARIABLE_REPRESENTATION_SIZE = 2**32
import _pydevd_bundle.pydevd_comm as pydevd_comm # noqa
import _pydevd_bundle.pydevd_extension_api as pydevd_extapi # noqa
import _pydevd_bundle.pydevd_extension_utils as pydevd_extutil # noqa
import _pydevd_bundle.pydevd_frame as pydevd_frame # noqa
#from _pydevd_bundle.pydevd_comm import pydevd_log
import ptvsd.ipcjson as ipcjson # noqa
@ -129,6 +130,43 @@ SafeReprPresentationProvider._instance = SafeReprPresentationProvider()
str_handlers = pydevd_extutil.EXTENSION_MANAGER_INSTANCE.type_to_instance.setdefault(pydevd_extapi.StrPresentationProvider, []) # noqa
str_handlers.insert(0, SafeReprPresentationProvider._instance)
DONT_TRACE_FILES = set((os.path.join(*elem) for elem in [
('ptvsd', 'attach_server.py'),
('ptvsd', 'daemon.py'),
('ptvsd', 'debugger.py'),
('ptvsd', 'futures.py'),
('ptvsd', 'ipcjson.py'),
('ptvsd', 'pathutils.py'),
('ptvsd', 'pydevd_hooks.py'),
('ptvsd', 'reraise.py'),
('ptvsd', 'reraise2.py'),
('ptvsd', 'reraise3.py'),
('ptvsd', 'runner.py'),
('ptvsd', 'safe_repr.py'),
('ptvsd', 'socket.py'),
('ptvsd', 'untangle.py'),
('ptvsd', 'version.py'),
('ptvsd', 'wrapper.py'),
('ptvsd', '_main.py'),
('ptvsd', '_version.py'),
('ptvsd', '__init__.py'),
('ptvsd', '__main__.py'),
]))
def filter_ptvsd_files(file_path):
"""
Returns true if the file should not be traced.
"""
ptvsd_path_re = r"(ptvsd[\\\/].*\.py)"
matches = re.finditer(ptvsd_path_re, file_path)
return any((g in DONT_TRACE_FILES
for m in matches
for g in m.groups()))
pydevd_frame.file_tracing_filter = filter_ptvsd_files
class UnsupportedPyDevdCommandError(Exception):

View file

@ -3,6 +3,7 @@ import unittest
import ptvsd.untangle
from ptvsd.wrapper import InternalsFilter
from ptvsd.wrapper import filter_ptvsd_files
class InternalsFilterTests(unittest.TestCase):
@ -29,3 +30,22 @@ class InternalsFilterTests(unittest.TestCase):
]
for fp in files:
self.assertFalse(int_filter.is_internal_path(fp))
class PtvsdFileTraceFilter(unittest.TestCase):
def test_basic(self):
test_paths = {
os.path.join('C:', 'ptvsd', 'wrapper.py'): True,
os.path.join('C:', 'abcd', 'ptvsd', 'wrapper.py'): True,
os.path.join('usr', 'ptvsd', 'wrapper.py'): True,
os.path.join('ptvsd', 'wrapper.py'): True,
os.path.join('usr', 'abcd', 'ptvsd', 'wrapper.py'): True,
os.path.join('C:', 'ptvsd', 'wrapper1.py'): False,
os.path.join('C:', 'abcd', 'ptvsd', 'ptvsd.py'): False,
os.path.join('usr', 'ptvsd', 'w.py'): False,
os.path.join('ptvsd', 'w.py'): False,
os.path.join('usr', 'abcd', 'ptvsd', 'tangle.py'): False,
}
for path, val in test_paths.items():
self.assertTrue(val == filter_ptvsd_files(path))