Comments (7)
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.
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.
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.
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.
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.
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.
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)
- argparse 1.2 incompatible with Python 3.1 HOT 10
- When -h is used, default values that fail should not matter HOT 2
- positional arguments before options cause all options to be in REMAINDER HOT 1
- Argparse is not testable with nosetest HOT 1
- `choices=[...]` overrides `nargs='*'` HOT 1
- Serious issues with nested mutex groups in help output HOT 2
- Bug with negative numbers in scientific notation HOT 1
- pypi version does not handle empty arguments when fromfile_prefix_chars set (python issue 12353) HOT 1
- .add_mutually_exclusive_group() only works when child of parser but not when a child of argument group HOT 1
- Argparse 1.4.0 doesn't have a wheel on PyPI: causes get-pip.py failures. HOT 2
- Is " if option_string.startswith(option_prefix): " a special design in _get_option_tuples()? HOT 3
- Issue with argument_group and required add_mutually_exclusive_group HOT 2
- AssertionError: assert ' '.join(pos_parts) == pos_usage HOT 3
- argparse WBN if default values displayed in -h message HOT 1
- argparse ArgumentParser(allow_abbrev=True) not documented on web HOT 1
- Poll: why are you using argparse from pypi (or from here) these days? HOT 3
- How to filepath location as command line argument HOT 1
- What does the comments "We have to allow for ..." means? HOT 3
- parsing only a subset and leave all other checks undone HOT 3
- The description of optional arguments which takes values is not same as the (true/false) based ones since it's name is appearing twice. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from argparse.