4

I'm building a package using poetry and have created my package name and venv. Using poetry new package-name

From the command line i can run poetry run package-name --flags and it will run my cli.py and references to appropriate imports etc.

My cli.py has from package-name import module. Everything works.

However in VS Code i'm trying to get it to run ^^ this command from the debugger interface declaring the appropriate parameters in the launch and settings json.

I had thought it would be something like

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${workspaceRoot}/package-name/cli.py",
            "args": [
                "removeuser",
                "--ini",
                "../../ini/test.ini"
            ],
            "console": "integratedTerminal"
        }
    ]
}

but this doesn't work. Any ideas on what the proper configuration is?

Thanks in advance.

hselbie
  • 1,749
  • 9
  • 24
  • 40

1 Answers1

0

I think you need something like this:

{
    "name": "Python: Poetry CLI application",
    "type": "python",
    "request": "launch",
    "module": "poetry",
    "args": [
        "run",
        "package-name",
        "removeuser",
        "--ini",
        "../../ini/test.ini"
    ],
    "console": "integratedTerminal"
}

I'm doing something similar and haven't found a better solution anywhere

upe
  • 1,862
  • 1
  • 19
  • 33
  • 2
    It sadly just says: `/bin/python: No module named poetry Running it with my module name instead says: `/bin/python: No module named mycli.__main__; 'mycli' is a package and cannot be directly executed` – Cirelli94 Nov 12 '21 at 09:24
  • Did you try `pip install poetry` in the environment you are debugging from? – BenCaldwell Aug 11 '23 at 05:42