Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging for Entry Points / console_scripts #1416

Closed
rigelifland opened this issue Nov 4, 2023 · 3 comments
Closed

Debugging for Entry Points / console_scripts #1416

rigelifland opened this issue Nov 4, 2023 · 3 comments

Comments

@rigelifland
Copy link

I'm not sure if this belongs in microsoft/debugpy or microsoft/vscode-python, but it would be nice to be able to debug entry points for a module/package. I found this SO question describing this issue: https://stackoverflow.com/questions/61693769/vs-code-run-debug-configuration-for-a-console-script-in-module-mode

The syntax mentioned in the SO question seems reasonable, but I don't know enough about how launch.json works to know if it's appropriate.

"module": "my_package.my_module:my_entry_point"
@joshbode
Copy link

joshbode commented Nov 5, 2023

My solution to this is to add a __main__.py file to my_package to make it runnable, something like this:

import sys

from my_package.my_module import my_entry_point

if __name__ == "__main__":
    sys.exit(my_entry_point(sys.argv[1:]))

and then you should be able to use "module": "my_package" to launch the debugger.
You'll also be able to "run" the module via python -m my_package ... as a bonus :)

@int19h
Copy link
Contributor

int19h commented Nov 8, 2023

Note that there's also "code", which lets you write the same thing directly in your launch.json, e.g.:

"code": "import sys; from my_package.my_module import my_entry_point; sys.exit(my_entry_point(sys.argv[1:]))"

@int19h
Copy link
Contributor

int19h commented Nov 8, 2023

That aside, the feature request to support it directly is tracked at #1311

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants