Re:Python Fire – Generates CLIs from any Python object
by noobermin on Friday August 17, 2018 @06:03PM
(#17785785)
Allow me to fan the flames. I find for simple scripts, docopt[0] is more than enough. It looks like the click's docs has a discussion of the differences.
Re:Python Fire – Generates CLIs from any Python object
by devxpy on Saturday August 18, 2018 @03:38AM
(#17787347)
I don't know man. Have used docopt, but click just feels right to me.
I never have to think about the "CLI" when using click, everything "just works"...
Re:Python Fire – Generates CLIs from any Python object
by mlrhazi on Saturday August 18, 2018 @12:10AM
(#17786813)
Thank you for this! Wow! Just Wow!
Re:Python Fire – Generates CLIs from any Python object
by ramses0 on Friday August 17, 2018 @05:28PM
(#17785658)
Click makes python attractive for CLI's. It is far better than bash and perl for simple stuff. Fire looks useful for hacks but Click has been excellently intuitive for me.
Re:Python Fire – Generates CLIs from any Python object
by slobotron on Saturday August 18, 2018 @01:32AM
(#17787021)
Perl6 has nice builtin cli construction from method definitions and doc comments
cat > cli.pl6
#| Duplicates without frobnication
multi sub MAIN( 'duplicate', Int $times, Str $text ) {
say $text x $times;
}
#| Frobnicates up to a limit
multi sub MAIN('frobnicate', Int :$length = 24, Bool :v(:$verbose))
{
say 'Verbosity ', ($verbose ?? 'on' !! 'off');
}
perl6 cli.pl
Usage:
cli.pl6 duplicate <times> <text> -- Duplicates without frobnication
cli.pl6 [--length=<Int>] [-v|--verbose] frobnicate -- Frobnicates up to a limit
perl6 cli.pl6 duplicate 3 blah...
blah...blah...blah...
Re:Python Fire – Generates CLIs from any Python object
by vultour on Friday August 17, 2018 @05:40PM
(#17785699)
The builtin argparse module is also really easy to use for simple stuff.
Re:Python Fire – Generates CLIs from any Python object
by m_ke on Friday August 17, 2018 @05:52PM
(#17785740)
It's ok but for some scripts it ends up being half of the code and you end up with a script that's dealing with an opaque args object.
Here's a decent example of this https://github.com/pytorch/examples/blob/master/imagenet/mai...
Re:Python Fire – Generates CLIs from any Python object
by heavenlyblue on Friday August 17, 2018 @06:06PM
(#17785795)
Could you solve ghat with click much easier? This seems mostly related to various flags set up, which would need to exist in the code anyway.
Re:Python Fire – Generates CLIs from any Python object
by m_ke on Friday August 17, 2018 @06:26PM
(#17785869)
I'm saying that this should really be a function like
def train(
data: File,
arch='resnet18',
workers=4,
epochs=90,
start_epoch=0,
batch_size=256,
learning_rate=0.9,
momentum=1e-4,
):
...
that could be exposed as a cli if __name__ is main but otherwise can be imported in a notebook or another script.
Re:Python Fire – Generates CLIs from any Python object
by bede on Saturday August 18, 2018 @04:19AM
(#17787459)
Fire is an interesting project that's great for testing and hacking. But for crafting Python CLIs from scratch, I fail to understand why Argh[0] doesn't receive more attention.
My only frustrations are a missing default handler for --version, and that I can't use argument names colliding with builtins such as 'input'. All the flexibility of argparse without boilerplate.
http://click.pocoo.org/5/