Repository: microsoft/ptvsd

Issue:
Just-my-code: Anything not in site-packages should be treated as user code



Discussion:
Found an issue with Mac 3.7 specifically. Waiting for VSTS CI to be fixed to continue working on this.
@karthiknadig Please have a look at https://github.com/Microsoft/vscode-python/issues/2087#issuecomment-425528613 for future enhancements.

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -1410,8 +1410,6 @@ def _process_debug_options(self, opts):
             skip_print_breakpoint_exception=('NameError',),
         )))
 
-        self._apply_code_stepping_settings()
-
     def _is_just_my_code_stepping_enabled(self):
         """Returns true if just-me-code stepping is enabled.
 
@@ -1420,30 +1418,6 @@ def _is_just_my_code_stepping_enabled(self):
         dbg_stdlib = self.debug_options.get('DEBUG_STDLIB', False)
         return not dbg_stdlib
 
-    def _apply_code_stepping_settings(self):
-        if self._is_just_my_code_stepping_enabled():
-            vendored_pydevd = os.path.sep + \
-                              os.path.join('ptvsd', '_vendored', 'pydevd')
-            ptvsd_path = os.path.sep + 'ptvsd'
-            site_path = os.path.sep + 'site-packages'
-
-            project_dirs = []
-            for path in sys.path + [os.getcwd()]:
-                is_stdlib = False
-                norm_path = os.path.normcase(path)
-                if path.endswith((ptvsd_path, vendored_pydevd, site_path)):
-                    is_stdlib = True
-                else:
-                    for prefix in STDLIB_PATH_PREFIXES:
-                        if norm_path.startswith(prefix):
-                            is_stdlib = True
-                            break
-
-                if not is_stdlib and len(path) > 0:
-                    project_dirs.append(path)
-            self.pydevd_request(pydevd_comm.CMD_SET_PROJECT_ROOTS,
-                                '\t'.join(project_dirs))
-
     def _is_stdlib(self, filepath):
         filepath = os.path.normcase(os.path.normpath(filepath))
         for prefix in STDLIB_PATH_PREFIXES:
@@ -1493,7 +1467,6 @@ def _handle_detach(self):
         self._detached = True
 
         self._clear_output_redirection()
-        self._reset_project_roots()
         self._clear_breakpoints()
         self.exceptions_mgr.remove_all_exception_breaks()
         self._resume_all_threads()
@@ -1501,10 +1474,6 @@ def _handle_detach(self):
     def _clear_output_redirection(self):
         self.pydevd_request(pydevd_comm.CMD_REDIRECT_OUTPUT, '')
 
-    def _reset_project_roots(self):
-        # We leave the "project roots" alone (see CMD_SET_PROJECT_ROOTS).
-        pass
-
     def _clear_breakpoints(self):
         cmd = pydevd_comm.CMD_REMOVE_BREAK
         for pyd_bpid, vsc_bpid in self.bp_map.pairs():
@@ -2359,7 +2328,6 @@ def on_setDebuggerProperty(self, request, args):
         if 'JustMyCodeStepping' in args:
             jmc = int(args.get('JustMyCodeStepping', 0)) > 0
             self.debug_options['DEBUG_STDLIB'] = not jmc
-            self._apply_code_stepping_settings()
 
         self.send_response(request)
 


Test patch:
diff --git a/tests/highlevel/__init__.py b/tests/highlevel/__init__.py
--- a/tests/highlevel/__init__.py
+++ b/tests/highlevel/__init__.py
@@ -15,7 +15,6 @@
     CMD_STEP_CAUGHT_EXCEPTION,
     CMD_SEND_CURR_EXCEPTION_TRACE,
     CMD_THREAD_CREATE,
-    CMD_SET_PROJECT_ROOTS,
     CMD_GET_THREAD_STACK,
     CMD_GET_EXCEPTION_DETAILS,
     CMD_SUSPEND_ON_BREAKPOINT_EXCEPTION,
@@ -142,9 +141,8 @@ def __init__(self, fix):
     def _wait_for_initialized(self):
         with self._fix.wait_for_command(CMD_REDIRECT_OUTPUT):
             with self._fix.wait_for_command(CMD_SUSPEND_ON_BREAKPOINT_EXCEPTION):
-                with self._fix.wait_for_command(CMD_SET_PROJECT_ROOTS):
-                    with self._fix.wait_for_command(CMD_RUN):
-                        yield
+                with self._fix.wait_for_command(CMD_RUN):
+                    yield
 
     def _initialize(self):
         version = self._fix.fake.VERSION
diff --git a/tests/highlevel/test_lifecycle.py b/tests/highlevel/test_lifecycle.py
--- a/tests/highlevel/test_lifecycle.py
+++ b/tests/highlevel/test_lifecycle.py
@@ -8,7 +8,6 @@
     CMD_REDIRECT_OUTPUT,
     CMD_RUN,
     CMD_VERSION,
-    CMD_SET_PROJECT_ROOTS,
     CMD_SUSPEND_ON_BREAKPOINT_EXCEPTION,
 )
 
@@ -118,8 +117,6 @@ def attach(self, expected_os_id, attach_args):
                 skip_suspend_on_breakpoint_exception=('BaseException',),
                 skip_print_breakpoint_exception=('NameError',),
             ))),
-            self.debugger_msgs.new_request(CMD_SET_PROJECT_ROOTS,
-                                           _get_project_dirs()),
             self.debugger_msgs.new_request(CMD_RUN),
         ])
 
@@ -164,8 +161,7 @@ def test_launch(self):
             # configuration
             req_config = self.send_request('configurationDone')
             self.wait_for_pydevd('version', 'redirect-output',
-                                 'run', 'suspend_on_breakpoint_exception',
-                                 'set_project_roots')
+                                 'run', 'suspend_on_breakpoint_exception')
 
             # Normal ops would go here.
 
@@ -201,7 +197,5 @@ def test_launch(self):
                 skip_suspend_on_breakpoint_exception=('BaseException',),
                 skip_print_breakpoint_exception=('NameError',),
             ))),
-            self.debugger_msgs.new_request(CMD_SET_PROJECT_ROOTS,
-                                           _get_project_dirs()),
             self.debugger_msgs.new_request(CMD_RUN),
         ])