Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 515
nmu Avatar asked Sep 01 '16 19:09

nmu


People also ask

How to use IntelliJ IDEA debugger?

IntelliJ IDEA allows starting the debugger session in several ways. Let's choose one: click in the gutter, and then select the command Debug 'Solver' in the popup menu that opens: The debugger starts, shows the Console tab of the Debug tool window, and lets you enter the desired values:

What is the difference between breakpoint and debug in IntelliJ?

Debugger makes application debugging much easier. Using debugger, we can stop the execution of program at a certain point, inspect variables, step into function and do many things. IntelliJ provides inbuilt Java debugger. Breakpoint allows stopping program execution at certain point.

How to debug a Python program?

The debugger starts, shows the Console tab of the Debug tool window, and lets you enter the desired values: By the way, in the Debug Console, you can enter the Python commands: Then the debugger suspends the program at the first breakpoint. It means that the line with the breakpoint is not yet executed. The line becomes blue:

What is IntelliJ and how to use it?

IntelliJ allows creating breakpoints that pause the execution only if a user-defined condition is satisfied. Here's an example that uses the source code above: Now the debugger will stop on the breakpoint only if the given argument is greater than 3. 7. Object Marks This is the most powerful and the least known IntelliJ feature.


1 Answers

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:])
like image 179
David Avatar answered Oct 27 '22 09:10

David