[Mesa-dev] [PATCH 01/14] util/gen_xmlpool: use argparse for argument handling

Emil Velikov emil.l.velikov at gmail.com
Wed Oct 31 18:32:29 UTC 2018


On Wed, 31 Oct 2018 at 18:11, Dylan Baker <dylan at pnwbakers.com> wrote:
>
> Quoting Emil Velikov (2018-10-31 10:47:53)
> > On Fri, 26 Oct 2018 at 18:25, Dylan Baker <dylan at pnwbakers.com> wrote:
> > >
> > > This is a little cleaner than just looking at sys.argv, but it's also
> > > going to allow us to handle the differences in the way meson and
> > > autotools handle translations more cleanly.
> > >
> > > Reviewed-by: Eric Engestrom <eric.engestrom at intel.com>
> > > ---
> > >  src/util/xmlpool/gen_xmlpool.py | 20 +++++++++-----------
> > >  1 file changed, 9 insertions(+), 11 deletions(-)
> > >
> > > diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py
> > > index 56a67bcab55..b40f295738e 100644
> > > --- a/src/util/xmlpool/gen_xmlpool.py
> > > +++ b/src/util/xmlpool/gen_xmlpool.py
> > > @@ -9,25 +9,23 @@
> > >
> > >  from __future__ import print_function
> > >
> > > +import argparse
> > >  import io
> > >  import sys
> > >  import gettext
> > >  import re
> > >
> > > +parser = argparse.ArgumentParser()
> > > +parser.add_argument('template')
> > > +parser.add_argument('localedir')
> > > +parser.add_argument('languages', nargs='*')
> > > +args = parser.parse_args()
> >
> > Since other parts in mesa already have the "required=True" I'd do the same here.
> > Sure python will already know those are not optional (do not start
> > with -) yet I don't know how many devs will remember that X days down
> > the line.
>
> Actually, you can't add required to positional arguments, as it implies that
> you could set required=False, you get a TypeError if you do.
>
In that case, can we make those position independent?
It should be a matter of
'-t', '--template', type=str
'-l', ....

Plus it'll help demystify the whole thing (as mentioned in another patch)

-Emil


More information about the mesa-dev mailing list