Giter Club home page Giter Club logo

Comments (7)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 9, 2024
I like the idea in general. I'm mildly concerned about adding a ton of new 
attributes
to action objects, but it's probably worth it.

I'm still debating how much it makes sense to commit to ConfigParser as the one 
and
only configuration file format. I would be nice if the API was designed in such 
a way
that if someone wanted to add support for, say, configobj files [1], it 
wouldn't be
too difficult to do. Maybe if the API were something like::

    parser.add_argument(..., cfg_name=['Properties', 'author'], ...)

and then within argparse we do something like::

    _cfg.get(*cfg_name)

then all you have to supply as a configuration object is something with a .get()
method...? To support configobj, then you'd have to write a wrapper something 
like
(untested)::

    class ConfigObjWrapper(object):
        def __init__(self, configobj):
            self.configobj = configobj
        def get(self, *names):
            value = self.configobj
            for name in names:
                value = value[name]
            return value

That may still be a little verbose... I'll have to think about it.

[1] http://www.voidspace.org.uk/python/configobj.html#the-config-file-format

Original comment by [email protected] on 29 Sep 2009 at 6:58

  • Changed state: Accepted
  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 9, 2024
Thanks for your response.

I think cfg_name being a list is a little less intuitive/discoverable.  But I 
could 
live with it.

(Note that your wrapper idea would probably work for people who like xml..., 
they 
could write a wrapper around an xpath query)

Re: configobj, perhaps we should ask Michael if he would be willing to add a 
.get 
method to configobj.

Original comment by [email protected] on 29 Sep 2009 at 1:56

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 9, 2024
updated patch.  refactored 2 methods:

  * _get_from_env
  * _get_from_config_file

Also fixed a bug with test_no_help (__main__.TestOptionalsHelpVersionActions)

Users who want to support non ConfigParsers can override the 
_get_from_config_file
method 

Original comment by [email protected] on 29 Sep 2009 at 6:38

Attachments:

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 9, 2024
Updated patch. 

  * Removed cfg_section, and made cfg_name a list as suggested
  * Updated some docstrings
  * make get_from_config_file public (so people will subclass it for other config
file types)

Original comment by [email protected] on 30 Sep 2009 at 8:09

Attachments:

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 9, 2024
Is this really the correct approach for argparse? My gut instinct is that 
argparse 
should provide one additional method, something like load_from_dict() which 
external 
applications will provide data to.

Argparse should absolutely not be involved in calculating these kind of 
env/config 
hierarchies itself, in my opinion.

I would like to do something like this with sanescript [1], for which I already 
use 
argparse, but am having some problems, because even while overriding 
error()/exit() 
control flow is broken, and so I can't then update information from.

I am nto sure if that is the same bug, or a different one

[1] http://bitbucket.org/aafshar/sanescript-main/overview/

Original comment by [email protected] on 4 Feb 2010 at 11:28

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 9, 2024
I'm closing this as WontFix because of the lack of consensus. Basically the 
proposals were:

* Have add_argument accept some additional parameters to indicate corresponding 
config file names and environment variables.

* Add a method like "load_from_dict" that would allow such loading to be done 
explicitly.

The former will complicate the already complicated add_argument parameters, 
while the latter probably isn't much better than calling set_defaults before 
parsing.

Despite the fact that I'm closing this issue, in general I'd like to make it 
easier to support something like this. If anyone here would like to make 
another suggested API, please file a new bug at bugs.python.org (where argparse 
development has moved).

Original comment by [email protected] on 23 Jul 2010 at 11:44

  • Changed state: WontFix

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 9, 2024
The configargparse module (now live on PyPI) extends argparse and adds support 
for config files and environment vars using approach #1 in steven.b's comment.

Original comment by [email protected] on 25 Aug 2014 at 1:05

from argparse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.