Skip to content

Dynamic module path in launch.json config #21449

Closed as not planned
Closed as not planned

Description

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!

Activity

  1. added
    feature-request
    on Jun 19, 2023
  2. added
    triage-needed
    on Jun 19, 2023
  3. added
    needs community feedback
    and removed
    triage-needed
    on Jun 20, 2023
  4. github-actions commented on Jun 20, 2023

    @github-actions

    Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 7 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue.

  5. brettcannon commented on Aug 24, 2023

    @brettcannon
    Member

    Thank you for submitting your feature request and everyone who considered it! Unfortunately, this issue did not receive enough votes over the allotted time, and so we are closing the issue.

  6. removed
    needs community feedback
    on Aug 24, 2023
  7. alecglen commented on Aug 24, 2023

    @alecglen
    Author

    All good, thanks Brett Cannon (@brettcannon). Do you happen to have advice/feedback on how other users with a similar project config work around this issue? There could totally be something solution I'm missing here.

  8. brettcannon commented on Aug 28, 2023

    @brettcannon
    Member

    Best I can think of is having a top-level __main__.py for the package where you can specify arguments to choose which script you're running. And then you can use dynamic command-line arguments to choose which submodule you want to run.

    Otherwise you could write a Python script to auto-generate an entry in launch.json for every submodule you have.

  9. locked as resolved and limited conversation to collaborators on Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions