Skip to content

Investigate useful integration with command line option tools #57

Closed

Description

@akaIDIOT

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?
  • ???
  • Profit!

Activity

  1. akaIDIOT commented on Aug 13, 2020

    @akaIDIOT
    MemberAuthor

    parser.set_default might be a good shout, automatically enabling overrides from command line args.

  2. HHoofs commented on Aug 13, 2020

    @HHoofs
    Collaborator

    Can you given an example?

  3. akaIDIOT commented on Aug 13, 2020

    @akaIDIOT
    MemberAuthor
    thing: 42
    unrelated.key: value
    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)
  4. HHoofs commented on Aug 13, 2020

    @HHoofs
    Collaborator

    Ok so, the argsparse 'makes' a configuration object that has highest precedence?

  5. akaIDIOT commented on Aug 13, 2020

    @akaIDIOT
    MemberAuthor

    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.

  6. locked and limited conversation to collaborators on May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions