Live data from Hacker News

Easy Python CLI with Click

codingwithricky.com

51–60 of 64 posts

Re: Easy Python CLI with Click

#52

Earlier quoted context omitted.

Perhaps a non-starter for you if you don't want to involve Docker but I have had good experiences wrapping a docker invocation in a shell script shim with the same name as the program and forwarding everything I need into the container. Then folks just grab the shell script and they're off... added bonus it's really easy to add update functionality to your tools.

So you're replacing a single executable Python script with a dependency that requires four additional separate artefacts (Dockerfile, image, container and the shell script) to be executed...

It's like you conveniently missed the first sentence.

1. Nothing stays a simple as time happens. New shit gets added.

2. Eventually people do want to use libraries so you're back to square 1.

3. It's "cross-platform" runnable now so those annoying macOS and Windows users can suddenly use it. Though depending on how you do the shim it might be tricky. I've taken to writing the shim in Go lately so I can poop out a static binary that does the rest of the work.

4. It's really easy to keep stuff up to date if your users are non-technical... simply have the shim docker pull a new version on startup.

To the end user it requires just a single artifact. For the developer there's a bit more stuff to manage but it's not exactly like any of this is hard stuff to figure out.

Re: Easy Python CLI with Click

#54

Earlier quoted context omitted.

> Most people first decide whether or not they want to use pypi packages, and then start evaluating which ones are appropriate. I don't think it's as binary as this. There should be, at least intuitively, a mild negative bias to adding a marginal dependency, even once you're dependent on pypi. We're lucky enough to not be dealing with a dumpster fire ecosystem like nodejs, but it's still a good habit. For me, writing…

Click is multiple order of magnitude better than argparse. I don't even start a CLI app with argparse anymore, because even with very simple interfaces you will hit it's limitations. You should try click.

Interesting, thanks, I had just skimmed the posted article and it looked substantially similar to argparse, but I guess I'll take a closer look.

Re: Easy Python CLI with Click

#55
post #53

Earlier quoted context omitted.

When you do things you like, how does it impact others?

You mean things as trivial as string format methods ? No impact. This is not subject to discussion either, we avoid bikeshedding.

So there are topics that are "not subject to discussion" and they're also the decisions you get to unilaterally make based on your preference, with no explanation needed.

Sounds fun, great coworking environment.

Re: Easy Python CLI with Click

#56
post #53

Earlier quoted context omitted.

You mean things as trivial as string format methods ? No impact. This is not subject to discussion either, we avoid bikeshedding.

So there are topics that are "not subject to discussion" and they're also the decisions you get to unilaterally make based on your preference, with no explanation needed. Sounds fun, great coworking environment.

Not sure what's going on, but you've posted so many low-quality comments and broken the site guidelines so many times in the last several hours that I'm rate-limiting your account again, until we get a commitment that this will stop and not recur.

Re: Easy Python CLI with Click

#57
post #56

Earlier quoted context omitted.

So there are topics that are "not subject to discussion" and they're also the decisions you get to unilaterally make based on your preference, with no explanation needed. Sounds fun, great coworking environment.

Not sure what's going on, but you've posted so many low-quality comments and broken the site guidelines so many times in the last several hours that I'm rate-limiting your account again, until we get a commitment that this will stop and not recur.

No. Please. Don't.

Re: Easy Python CLI with Click

#58
Click unfortunately doesn't pass the smell test of a non-awkward implementation of 'sudo'. It gets some partial credit because an implementation is possible but only because you can subclass the click.Command object and change the parsing behavior arbitrarily.

So many of these parsing libraries seem to forget that any positional parameter can stop options parsing not just '--' and that that parameter might appear arbitrarily deep in subcommands.

This is not only needed for commands like sudo and ssh but BSD style CLIs as well which all OSX users are probably intimately familiar and annoyed with.

Re: Easy Python CLI with Click

#59
Click and argparse end up with a lot of boilerplate. `defopt` (https://defopt.readthedocs.io/en/stable/) reduces it to almost nothing (granted only in Python 3), is only a single file and even turns your function docstring into command help text.

With every other tool I’ve tried, I end up writing a python API and a CLI and documenting it twice.

Defopt eliminates that almost completely (but with *args still allows for elegant interfaces)

Re: Easy Python CLI with Click

#60
post #4

I've used Fire[0] for a few projects and have been meaning to give Click a try, but I'm not sure I like the syntax after reading through the article (holy moly decorators). Seems unwieldy to me, but does anyone have experience with both? [0] https://github.com/google/python-fire

I liked fire a lot, gets kinda goofy sometimes (and it looks abnormal in exceptions). If you can use python 3 - defopt is simpler and less visually noisy on errors https://defopt.readthedocs.io/en/stable/
Post reply on HN