You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Investigate useful integration with command line option tools #57
Maybe target builtin argument parsers (argparse, optparse seems to be have been deprecated) first, making sure to not bite the likes of docopt / click. Also important:
load config before defining arguments or after?
what to do with the likes of NAME_CONFIG_FILE envvars?
what to do with things like --config path/to/conf.yaml?
Configuration.include(namespace_object) or include 'something' in the load order?
defaults=load_name('name')
parser=ArgumentParser()
parser.add_argument('-t', '--thing', type=int, help='value for the thing')
parser.set_defaults(**defaults)
arguments=parser.parse_args()
main(arguments.thing)
the unrelated key should get ignored by argparse
value for thing would be 42 in this case, but --thing 5 would override it to 5
argparse is now the 'owner' of the configuration values, maybe confidence could have a way of including the resulting namespace back into the configuration
there might be better ways to do this
Rationale behind the issue was two somewhat common use cases, as configuration and command line arguments often go hand in hand:
overriding a configuration file from the command line (e.g. a --config option, often overriding a default location, in the case of confidence this could maybe be a precedence, )
every configuration option having a command line option equivalent, where in practice the command line option often has higher precedence than something like an environment variable (confidence currently reads envvars, but as a user has (and should have) full control over the command line argument parsing, there's no simple way of just adding a function to the default load order)
Sort of, I'd think. I don't think confidence should extend argparse or take control over these things for these kinds of use cases. Come to think of it, this type of integration should maybe just get documented decently, giving users the hints on what is going to work and what might bite them.
I was planning to get a head start on some decent docs in the coming weeks, so this might need to become a section somewhere.
Activity
akaIDIOT commentedon Aug 13, 2020
parser.set_default might be a good shout, automatically enabling overrides from command line args.
HHoofs commentedon Aug 13, 2020
Can you given an example?
akaIDIOT commentedon Aug 13, 2020
thingwould be 42 in this case, but--thing 5would override it to 5Rationale behind the issue was two somewhat common use cases, as configuration and command line arguments often go hand in hand:
--configoption, often overriding a default location, in the case of confidence this could maybe be a precedence, )HHoofs commentedon Aug 13, 2020
Ok so, the argsparse 'makes' a configuration object that has highest precedence?
akaIDIOT commentedon Aug 13, 2020
Sort of, I'd think. I don't think confidence should extend argparse or take control over these things for these kinds of use cases. Come to think of it, this type of integration should maybe just get documented decently, giving users the hints on what is going to work and what might bite them.
I was planning to get a head start on some decent docs in the coming weeks, so this might need to become a section somewhere.