Skip to content

Dynamic module path in launch.json config #21449

@alecglen

Description

@alecglen

Cross-post from microsoft/vscode#180005...

I'm working in a Python project organized as a module hierarchy. To execute a file path/to/file.py, I run it as python -m path.to.file in order to resolve relative imports correctly.

To debug this file, my launch.json config currently looks like this:

{
      "name": "Python: Hardcoded Module",
      "type": "python",
      "request": "launch",
      "python": "${command:python.interpreterPath}",
      "cwd": "${workspaceFolder}",
      "module": "path.to.file",
      "args": []
    }

...plus another config for every new file I want to debug.

I would love to make a dynamic "Current file run as module from project root" launch config, and it seems to be very nearly possible, but not quite. The missing link is that I need a way to specify ${relativeFileDirname} using a period as the seperator instead of the normal path separator. If that could be achieved through either a new variable or some sort of modifier, it would improve the debugger a ton for projects structured this way!

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestRequest for new features or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions