VS Code - Run Debug Configuration for a console_script in module mode

Viewed 726

My setup.py has the following console_scripts as entry points:

entry_points={
        'console_scripts': ['script=myapp.app:do_something',
                            'script2=myapp.app:do_something2'],
    },

with the following structure

.
├── myapp
│   ├── __init__.py
│   ├── app.py
│   ├── mod.py
│   ├── mod2.py
│   └── submodules
│   ├── __init__.py
│   └── mod3.py
├── requirements.txt
└── setup.py

and app looking like

##my_app.app

def do_something():
  #do stuff
def do_something2():
  #do other stuff

How can I get VS code debug configuration to enter at these module attributes. I have this that can run the module if I use if __name__ == "__main__": do_something() but want seperate launch.json files depending on the console_scripts

##launch.json
{
  "configurations": [
    {
      "name": "Python: Module",
      "type": "python",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "module": "myapp.app",
      "args": ["--hello world"]
    }
  ]
}

Thought you might be able to do simlar with:

  "module": "myapp.app:do_something",

but alas:

No module named myapp.app:do_something
2 Answers

There currently isn't a way to make this work. At minimum you need a separate module per entry point or have a single module that took a command-line argument that then chose which function to call.

Here is a launch.json that worked for me to debug mkdocs plugins:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            "console": "integratedTerminal",
            "module": "mkdocs",
            "args": ["serve"]
        }
    ]
}

It uses "console": "integratedTerminal",.

mkdocs provides the mkdocs entry point that accepts several arguments such as build and serve. This launch.json allowed me to set a breakpoint in a mkdocs plugin python file and stop at that breakpoing after running the mkdocs build/serve process.

Related