0

I'm building a CLI in python using poetry and have used vimspector separately in the past for python debugging.

When I test a normal python file, I can set up my vimspector.json like

{
  "configurations": {
    "run": {
      "adapter": "debugpy",
      "configuration": {
        "request": "launch",
        "protocol": "auto",
        "stopOnEntry": true,
        "console": "integratedTerminal",
        "program": "${workspaceRoot}/gzrparse.py",
        "cwd": "${workspaceRoot}"
      }
    },
    "parse": {
      "adapter": "debugpy",
      "configuration": {
        "request": "launch",
        "protocol": "auto",
        "stopOnEntry": true,
        "console": "integratedTerminal",
        "program": "${workspaceRoot}/test/parse.py",
        "cwd": "${workspaceRoot}"
      }
    }
  }
}

Which works fine for those purposes, I would love to debug my CLI with vimspector as well, but i'm struggling to find the correct configurations in my .json file. When on the CLI I can poetry run packagename which works fine, so i'm trying to get vimspector to replicate that command.

Does anyone know if that's possible? Or how to do it? I've been trying to adapt from this answer but I'm a little out of my depth on what i'm doing.

hselbie
  • 1,749
  • 9
  • 24
  • 40

1 Answers1

1

First you have to execute poetry install to create virtualenv and install your module in it.

Then you can start debugging a file you are editing using the configuration:

        "run-current-file": {
        "adapter": "debugpy",
        "variables": {
            "venv": {
                "shell": ["poetry", "env", "info", "-p"]
            }
        },

        "configuration": {
            "request": "launch",
            "protocol": "auto",
            "stopOnEntry": true,
            "console": "integratedTerminal",
            "python": "${venv}/bin/python",
            "program": "${file}",
            "cwd": "${workspaceRoot}"
        }
    },

This will start debugging the currently open file using python from poetry virtual environment found by executing command poetry env info -p

Of course you can leave the "program" setting to always debug the same file:

"program": "${workspaceRoot}/test/parse.py"

To debug a module (provided your module has __main__.py file) you need configuration:

"runmodule": {
    "adapter": "debugpy",
    "variables": {
        "venv": {
            "shell": ["poetry", "env", "info", "-p"]
        }
    },

    "configuration": {
        "request": "launch",
        "protocol": "auto",
        "stopOnEntry": true,
        "console": "integratedTerminal",
        "python": "${venv}/bin/python",
        "module": "<mymodule>",
        "cwd": "${workspaceRoot}"
    }
},

Where have to replace <mymodule> with your module name.

zrf
  • 88
  • 6