question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

launch.json debug any file as module

See original GitHub issue

Environment data

  • VS Code version: 1.33.0
  • Extension version: 2019.3.6558
  • Python version: Python 3.6.7 (miniconda)

Feature Suggestion

It would be great to be able to debug arbitrary files as modules without having to hardcode their path in launch.json. The best I could find was the following which at least allows to debug any file in a given directory as module.

{
  "configurations": [
    {
      "name": "Python: Module",
      "type": "python",
      "request": "launch",
      "module": "src.nn.models.${fileBasenameNoExtension}"
    }
  ]
}

Not sure if this can be done by the Python extension or would have to be implemented by VS Code itself, but basically I’m suggesting something similar to ${fileBasenameNoExtension} that returns the full dotted “path” to a file from a project’s root?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:25
  • Comments:7

github_iconTop GitHub Comments

5reactions
StefanRicklicommented, Sep 18, 2020

I’d also like to see this as a native solution. Running the scripts as modules can help a lot with relative imports when I try to debug single files.

5reactions
jaklancommented, Jan 13, 2020

You can use “Command Variable” extension to debug current module: "module": "${command:extension.commandvariable.file.relativeDirDots}.${fileBasenameNoExtension}"

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to debug a Python module in Visual Studio Code's ...
Actually, there is a very simple option to do this I found by accident while trying to edit the launch.json file. "type": "python",...
Read more >
launch.json debug any file as module · Issue #5184 - GitHub
It would be great to be able to debug arbitrary files as modules without having to hardcode their path in launch.json .
Read more >
Debugging configurations for Python apps in Visual Studio Code
Select the create a launch.json file link (outlined in the image above) or use the Run > Open configurations menu command. A configuration...
Read more >
Develop and debug modules Azure IoT Edge modules using ...
Use Visual Studio Code to develop and debug modules for Azure IoT Edge ... A .vscode folder contains configuration file launch.json.
Read more >
Using Visual Studio Code to debug Jest based unit tests
Step 1 Enabling debugging in our project · We will click on the debug icon (left hand sidebar). · Click on the add...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found