nmu
nmu

Reputation: 1519

Is debugging possible with python-click using intellij?

This seems like a general problem with python-click, however there is no mention of it anywhere on google.

If I try run even the simplest of python click scripts, like the following from realpython

import click

@click.group()
def greet():
    pass


@greet.command()
def hello(**kwargs):
    pass


@greet.command()
def goodbye(**kwargs):
    pass

if __name__ == '__main__':
    greet()

The Intellij debugger completely bombs with the error message:

Error: no such option: --multiproc

I have tried this with multiple python-click scripts and debugging never works. Has anyone else noticed this and is there any way around this?

Upvotes: 11

Views: 4654

Answers (1)

David
David

Reputation: 9945

The problem arises when you do not pass any parameters to the click entry-point. In that situation, click asks a platform specific function to get it's args, get_os_args() which is unrelated to sys.argv.

The result effect is that debugger needed arguments are also passed to the click parser, effectively activating an error in click.

The solution is to explicitely pass sys.argv[1:] to the click entrypoint which will override the default get_os_args() behavior:

import sys
if __name__ == '__main__':
    greet(sys.argv[1:])

Upvotes: 26

Related Questions