0

I have a method cli in mymodule which is the entrypoint for my programm. cli takes several keyword arguments. The module mymodule does not contain something like

if __name__ == "__main__":
    cli(...)

How do i specify a run-configuration for this?

I tried

{
        "name": "myentrypoint",
        "type": "debugpy",
        "request": "launch",
        "module": "mymodule.cli",
        "console": "integratedTerminal",
        "args": [
            "--arg1", "value1",
            "--arg2", "value2"
            ],
        "justMyCode": true
}

(as suggested in How to make VScode launch.json for a Python module)

This gives me

/home/xxxxxx/projects/myproject/.venv/bin/python: Error while finding module specification for 'mymodule.cli' (ModuleNotFoundError: __path__ attribute not found on 'mymodule' while trying to find 'mymodule.cli')

Normally I use this entrypoint using poetry like

[tool.poetry.scripts]
myentrypoint= 'mymodule:cli'

And then from the terminal poetry run myentrypoint --arg1 "value1" --arg2 "value2

But now I need to debug the program

2
  • 1
    why would vscode support some custom capability like that? if you don't want to add the main support into your module, then create a main.py and use that as your entrypoint. Commented Sep 23, 2024 at 10:08
  • @toppk because poetry supports it? Commented Sep 24, 2024 at 6:24

1 Answer 1

0

You could try to set cli in args. It looks like:

{
        "name": "myentrypoint",
        "type": "debugpy",
        "request": "launch",
        "module": "mymodule",
        "console": "integratedTerminal",
        "args": [
            "cli",
            "--arg1", "value1",
            "--arg2", "value2"
            ],
        "justMyCode": true
}
Sign up to request clarification or add additional context in comments.

4 Comments

this is not working
Are there any error messages or logs when you try to run or debug your Python CLI method in VS Code?
It's doing the imports in the file (initialization code), but the method "cli" is not entered... die program just ends without doing anything
I suggest you create main.py as entrypoint which include from mymodule import cli if __name__ == "__main__":    import sys    cli(*sys.argv[1:])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.