Re: CLI parsing—with `--help` text—`--foo bar`, how to give additional parameters to `bar`?

Samuel Marks samuelmarks at gmail.com
Fri Oct 16 03:45:13 EDT 2020


Yeah, but the risk with config files is you need a website—and/or full JSON
schema output—to figure out what’s needed.

(Although I should mention that with my doctrans project you can generate a
config class—and class method—from/to your argparse parser; enabling the
config file scenario rather cleanly)

Also there is a project which takes your CLI and turns it into a GUI
(Gooey).

At some future point doctrans will be “complete”, and then you can provide
inputs via:
- CLI arguments
- Config file
- RPC*
- REST*

*TODO, will also optionally generate ORM classes for persistence

On Fri, 16 Oct 2020 at 6:08 pm, Karen Shaeffer <klsshaeffer at icloud.com>
wrote:

> Passing a lot of command line parameters is very error prone. Opening a
> file and specifying flags is much more user friendly, because you have any
> necessary help documented right there. In my eyes, the command line is only
> useful for simple scripts.
>
> Karen
>
> > On Oct 15, 2020, at 11:44 PM, Karen Shaeffer <klsshaeffer at icloud.com>
> wrote:
> >
> > In my work, for complex ML modeling code, I never pass anything through
> the command line. I implement absl.flags in each module, specifying all the
> defaults. At runtime I instantiate the flags as  class variables of a
> ModelConfiguration class that gets passed into the model class. Absl
> supports all I need for this scheme. Of course, for a package, I can have a
> configuration module for all these configuration classes.
> >
> > This scheme is easy to maintain. It can be dynamically customized at run
> time. It’s very easy to document and maintain and to use. In one project, I
> even supported console inputs that dynamically managed configurations of
> pipelines. Nothing was ever passed in on command lines. I wonder why you
> need to play on the command line.
> >
> > And yea, I’ve written a command line parsing function in C a long time
> ago. I thought that really cool at the time. I wouldn’t want to do it now.
> >
> > Karen.
> >
> >> On Oct 15, 2020, at 9:58 PM, Samuel Marks <samuelmarks at gmail.com>
> wrote:
> >>
> >> Yeah I've played with custom actions before
> >>
> https://github.com/offscale/argparse-utils/tree/master/argparse_utils/actions
> >>
> >> But this would only help in one phase, the important phase of
> >> providing help text will need to be provided out-of-argparse and
> >> thrown in
> >>
> >> (like my trivial absl alternative, exposing a function which takes an
> >> argparse instance and returns an argparse instance)
> >>
> >> The only hack remaining is that I have to pass through `sys.argv` at
> >> least once before giving it to argparse. I wonder if there's a way to
> >> not need to explicitly go through it at all…
> >>
> https://github.com/SamuelMarks/ml-params/blob/d1fb184/ml_params/__main__.py#L89
> >>
> >> [I didn't know `getopt` was exposed otherwise I'd use that <like I
> >> sometimes do in C>, but there has to be a solution just using
> >> argparse?]
> >>
> >> Samuel Marks
> >> Charity <https://sydneyscientific.org> | consultancy
> >> <https://offscale.io> | open-source <https://github.com/offscale> |
> >> LinkedIn <https://linkedin.com/in/samuelmarks>
> >>
> >>
> >> Samuel Marks
> >> Charity | consultancy | open-source | LinkedIn
> >>
> >>
> >> On Fri, Oct 16, 2020 at 3:47 PM Dieter Maurer <dieter at handshake.de>
> wrote:
> >>>
> >>> Samuel Marks wrote at 2020-10-16 10:09 +1100:
> >>>> Yes it’s my module, and I’ve been using argparse
> >>>> https://github.com/SamuelMarks/ml-params
> >>>>
> >>>> No library I’ve found provides a solution to CLI argument parsing for
> my
> >>>> use-case.
> >>>
> >>> Do you know that with `argparse` you can specify how many arguments an
> option
> >>> expects? Thus, it should be quite easily possible to
> >>> have --opt <o1> <o2> ...
> >>> Do you know that you can define new `Action`s for `argparse`?
> >>> This way, you could properly process `--opt <o1>,<o2>, ...`.
> >> --
> >> https://mail.python.org/mailman/listinfo/python-list
> >
>
> --
Samuel Marks
Charity <https://sydneyscientific.org> | consultancy
<https://offscale.io> | open-source
<https://github.com/offscale> | LinkedIn <
https://linkedin.com/in/samuelmarks>


More information about the Python-list mailing list