VS Code - 在模块模式下运行 console_script 的调试配置

jwi*_*720 10 python debugging visual-studio-code

我的setup.py has the following console_scripts as entry points:

\n\n
entry_points={\n        \'console_scripts\': [\'script=myapp.app:do_something\',\n                            \'script2=myapp.app:do_something2\'],\n    },\n\n
Run Code Online (Sandbox Code Playgroud)\n\n

具有以下结构

\n\n
.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 myapp\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 app.py\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 mod.py\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 mod2.py\n\xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 submodules\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 mod3.py\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 requirements.txt\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 setup.py\n
Run Code Online (Sandbox Code Playgroud)\n\n

和应用程序看起来像

\n\n
##my_app.app\n\ndef do_something():\n  #do stuff\ndef do_something2():\n  #do other stuff\n\n
Run Code Online (Sandbox Code Playgroud)\n\n

如何获取 VS 代码调试配置以输入这些模块属性。if __name__ == "__main__": do_something()如果我使用但想要根据 console_scripts 单独的 launch.json 文件,我可以运行该模块

\n\n
##launch.json\n{\n  "configurations": [\n    {\n      "name": "Python: Module",\n      "type": "python",\n      "request": "launch",\n      "cwd": "${workspaceFolder}",\n      "module": "myapp.app",\n      "args": ["--hello world"]\n    }\n  ]\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

认为你也许可以做类似的事情:

\n\n
  "module": "myapp.app:do_something",\n
Run Code Online (Sandbox Code Playgroud)\n\n

可惜:

\n\n
No module named myapp.app:do_something\n
Run Code Online (Sandbox Code Playgroud)\n

Bre*_*non 8

目前还没有办法让这项工作发挥作用。至少每个入口点需要一个单独的模块,或者有一个接受命令行参数的模块,然后选择要调用的函数。