Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

218
Vistas
how to debug python click cli application?

I have built a cli application using the click library in python. There is no documentation on how to debug commands.

Without click, its easy to just debug python files in IDE, but when we use click, the commands need to be run through console_scripts setup in setup.py.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

This is not well documented, but you can call your command functions directly, and thus can run the code in a debugger:

Sample Code:

import click

@click.command()
@click.option('--my_arg', default=1, help='a number')
def my_command(my_arg):
    click.echo("my_arg='%d'" % my_arg)

if __name__ == '__main__':
    my_command(['--my_arg', '3'])

Result:

my_arg='3'
over 4 years ago · Santiago Trujillo Denunciar

0

I'm a couple years late to the party, but in case anyone else comes here looking for an answer like I just did:

Calling your function with CliRunner.invoke() will return a "Result" object with an "exc_info" attribute. You can feed that to traceback.print_exception() like so:

runner = CliRunner()
result = runner.invoke(my_command)
traceback.print_exception(*result.exc_info)
over 4 years ago · Santiago Trujillo Denunciar

0

The setup.py generates:

  • console_script.exe
  • console_script-script.py

from cmdline:

console_app --help

expands out to the IDE configuration cmd:

python <absolute path to>\console_app-script.py --help

Tested in PyCharm 2018.2 - you can set and hit breakpoints and preserve the expected cmdline/arg paradigm.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda