lmotta / debug_vs_plugin

Plugin to Enable Debug for Visual Studio( tested in Visual Studio Code)
GNU General Public License v2.0
20 stars 8 forks source link

More OSX issues on 0.8 with debugpy #16

Open MattReimer opened 6 months ago

MattReimer commented 6 months ago

This is tangential to #12 and #13 but not entirely the same.

Details:

The problems:

My workarounds:

  1. Make sure debugpy is installed using /Applications/QGIS-LTR.app/Contents/MacOS/bin/pip3 install debugpy
  2. uninstall ptvsd completely using /Applications/QGIS-LTR.app/Contents/MacOS/bin/pip3 uninstall ptvsd

Here's what I baked into my plugin to get it working again. I'm triggering the debugger on an environment variable called RS_DEBUG being set to True.

    def _enable_debug(self):
        debug_port = 5678
        debug_host = "localhost"
        DEBUG_ON = os.environ.get("RS_DEBUG", "False").lower() == "true"
        if not DEBUG_ON:
            return

        if self.debugpy is None:
            try:
                import debugpy
                self.debugpy = debugpy
            except:
                pass

        if self.debugpy is None:
            return
        else:
            try:
                python_path = os.path.join(Path(os.__file__).parents[2], 'bin', Path(os.__file__).parent.name)
                # NOTICE THAT I NEED TO CONFIGURE IT HERE!!!!!
                debugpy.configure(python=python_path) 
            except Exception as e:
                raise e

        msgPort = f'"request": "attach", "Port": {debug_port}, "host": "{debug_host}"'
        if self.debugpy.is_client_connected():
            return
        else:
            t_, new_port = self.debugpy.listen((debug_host, debug_port))

then using the following in my launch.json file inside vscode I was able to get a client connecting and breakpoints firing again.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "QGIS Debug",
      "type": "debugpy",
      "request": "attach",
      "connect": {
        "host": "localhost",
        "port": 5678
      },
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}",
          "remoteRoot": "${workspaceFolder}",
        }
      ],
      "justMyCode": true
    },
  ]
}