Live data from Hacker News

Click – Python library for command-line interfaces

click.pocoo.org

41–50 of 105 posts

Re: Click – Python library for command-line interfaces

#41
post #34
post #17

The biggest gripe I have with using Python for rich command-line tool is the startup time. One of the first reason I like to write a nice command-line tool when I start a project, say foo, is to be able to do `foo --help` to quickly see and remember what the project can do (I have a very bad memory and doing this makes it possible for me to jump back faster to a project, even well documented. I can forget what I was…

> The biggest gripe I have with using Python for rich command-line tool is the startup time. What startup time? I even have a python script running on every shell prompt drawing (that checks mercurial on top of starting the python interpreter), and the latency is negligible.

I just tried on an app at work (Django app):

    > time python manage.py --help
    real	0m0.473s
    user	0m0.240s
    sys	0m0.148s
Half of a second is very noticeable (and annoying). I had similar perception in my previous work.

You can try to only load enough to display the help text without really loading everything, but that doesn't work that well (you have to organize things differently, and `--help` requires to load a lot of stuff. `subcommand --help` needs less but it still has to see if the subcommand exists).

As a reference:

    > time python -c 'print "hello"'
    hello

    real	0m0.041s
    user	0m0.024s
    sys	0m0.012s

    > time echo hello
    hello

    real	0m0.000s
    user	0m0.000s
    sys	0m0.000s
Actually even the first (0.041s) is not instant, while the second one does (I mean as I perceive it visually).

Re: Click – Python library for command-line interfaces

#42

Kudos again to the pocoo team for creating such a simple and useful library. It sure beats optparse :) On a side note, however, does anyone know why the team prefers to wrap functions in decorators? Flask also uses them, but what's the design decision behind them?

This is a valid question. When things become complex I found that decorator is a bit too magic, and should be used with moderation.

Re: Click – Python library for command-line interfaces

#43
post #17

The biggest gripe I have with using Python for rich command-line tool is the startup time. One of the first reason I like to write a nice command-line tool when I start a project, say foo, is to be able to do `foo --help` to quickly see and remember what the project can do (I have a very bad memory and doing this makes it possible for me to jump back faster to a project, even well documented. I can forget what I was…

Hm, it'd be pointless to argue this point (if you think it's slow then it's slow) but I've created many a Python CLI and have never noticed them being slow to start. Perhaps it's a case of importing certain modules globally instead of on a per-function basis?

See my answer to coldtea. Yes you can organize you're code to help making it load faster but I don't think it is fast enough. Maybe my terminal is slow, maybe my machine is slow (and maybe I'm overly sensitive to the problem) but the difference is telling.

Re: Click – Python library for command-line interfaces

#45
post #17

The biggest gripe I have with using Python for rich command-line tool is the startup time. One of the first reason I like to write a nice command-line tool when I start a project, say foo, is to be able to do `foo --help` to quickly see and remember what the project can do (I have a very bad memory and doing this makes it possible for me to jump back faster to a project, even well documented. I can forget what I was…

I'm completely clueless about this, but would it be possible to have a persistent python interpreter always running in the background somehow, and submit the commands to it?

Re: Click – Python library for command-line interfaces

#46
post #40
post #3

Gorgeous. This guy has a full time job, a wife, and wrote Flask and Werkzeug, ItsDangerous, Sphinx, Markupsafe, Jinja2 (and Jinja) and that's just some of the well known stuff. Handsome and young too. Bastard. He probably saves the world in a dinner jacket in his spare time.

To be fair he only got married this month, so the jury is still out on where his productivity goes from here ;)

Getting married didn't kill me it was having a kid. Now I get maybe four hours a week for hobby/OSS programming.

Re: Click – Python library for command-line interfaces

#47
post #41
post #34

Earlier quoted context omitted.

> The biggest gripe I have with using Python for rich command-line tool is the startup time. What startup time? I even have a python script running on every shell prompt drawing (that checks mercurial on top of starting the python interpreter), and the latency is negligible.

I just tried on an app at work (Django app): > time python manage.py --help real 0m0.473s user 0m0.240s sys 0m0.148s Half of a second is very noticeable (and annoying). I had similar perception in my previous work. You can try to only load enough to display the help text without really loading everything, but that doesn't work that well (you have to organize things differently, and `--help` requires to load a lot of…

This is why I use Lua for command-line tools. Here's one such program that makes no attempt to organize code to make --help load faster:

  real  	0m0.006s
  user  	0m0.000s
  sys   	0m0.004s

Re: Click – Python library for command-line interfaces

#48
post #33

>You can get the library directly from PyPI: >pip install click Well... no you cannot. See the page: https://pypi.python.org/pypi/click The package hasn't been uploaded yet. However one can install it straight from the git repo: > pip install git+ssh://git@github.com:mitsuhiko/click.git

> pip install git+ssh://git@github.com:mitsuhiko/click.git

Can someone comment regarding using pip like that? Is it fine to put this on req.txt? Any best practices somewhere?

Re: Click – Python library for command-line interfaces

#49
post #17

The biggest gripe I have with using Python for rich command-line tool is the startup time. One of the first reason I like to write a nice command-line tool when I start a project, say foo, is to be able to do `foo --help` to quickly see and remember what the project can do (I have a very bad memory and doing this makes it possible for me to jump back faster to a project, even well documented. I can forget what I was…

I'm completely clueless about this, but would it be possible to have a persistent python interpreter always running in the background somehow, and submit the commands to it?

If loading the rest of the code and initialization time really matters, yes. But then you're back to square one: you now have to create a CLI to access the server and that new CLI must load quickly. Which would also be the case if you just wrote it that way first, then loading the rest of the code once the command is determined.

And if you're in some project similar to Django, you would have first to query the server to know the possible subcommands...

So what you say makes sense when other parts of the code are slow to initialize and must be accessed frequently, not for the CLI itself.

Re: Click – Python library for command-line interfaces

#50
post #3

Gorgeous. This guy has a full time job, a wife, and wrote Flask and Werkzeug, ItsDangerous, Sphinx, Markupsafe, Jinja2 (and Jinja) and that's just some of the well known stuff. Handsome and young too. Bastard. He probably saves the world in a dinner jacket in his spare time.

Armin Ronacher is absolutely amazing at python. If you want to learn some things dive into his source code and dig away. He really thinks through code architecture.
Post reply on HN