Coder Social home page Coder Social logo

Comments (3)

hazmat345 avatar hazmat345 commented on July 18, 2024

Possibly allowing an additional spec to be passed to brewtils.load_config that would be merged with brewtil's spec?

from brewtils.

hazmat345 avatar hazmat345 commented on July 18, 2024

May be better to just allow plugin authors to pass in their own argparser. That way they aren't required to learn / use yapconf.

EDIT: So this isn't as straightforward as I hoped. Passing in a custom parser to load_config is no problem, and that's good because it allows for successful parsing of 'extra' cli args (like any positional args). The issue is getting access to the results - load_config turns the results of the cli parsing into a dictionary and passes that to yapconf as a source. But because the 'extra' arguments aren't in the brewtils spec yapconf just drops them on the floor.

# cli args are ["arg value", "--bg-host", "localhost"]

def main():
    parser = ArgumentParser()
    parser.add_argument('some_arg')

    # yay, this works now (doesn't barf on the positional arg)
    config = brewtils.load_config(cli_args=sys.argv[1:], arg_parser=parser)

    # Let's assume the client needs the thing
    # This breaks because config.some_arg doesn't exist and there's no way to get it
    RemotePlugin(Client(config.some_arg),
                 name='complex', ...,
                 **brewtils.get_connection_info(cli_args=sys.argv[1:])

In order to make this work we'd need some way to return the results of the argparser in addition to the yapconf Box. If we go this route, I don't see any way to avoid having some sort of separate config object, and that may be more confusing than just asking people to write a spec.

Another option: we provide a way to get an argparser that's already loaded with the brewtils spec. That way they could parse cli args themselves and the --help would look as expected.

# cli args are ["arg value", "--bg-host", "localhost"]

def main():
    parser = brewtils.argument_parser()
    parser.add_argument('some_arg')

    parsed_args = parser.parse_args(cli_args)

    # sweet, now I can get to some_arg...
    RemotePlugin(Client(parsed_args.some_arg),
                 name='complex', ...,
                 # BUT you can't use the cli args here, we can't deal with the extras
                 **brewtils.get_connection_info(**vars(parsed_args)))

This is still not great - if you're actually using get_config instead of get_connection_info you'll have two different config objects and you'll just have to know which has which things.

I think just adding some spec is easier, as long as you're ok giving up positional args:

# cli args are ["--some-arg", "arg value", "--bg-host", "localhost"]

def main():
    extra_spec = {
        "some_arg": {
            "type": "str",
        }
    }

    config = brewtils.load_config(cli_args=sys.argv[1:], merge_specification=extra_spec)

    RemotePlugin(Client(config.some_arg),
                 name='complex', ...,
                 **brewtils.get_connection_info(cli_args=sys.argv[1:]))

from brewtils.

hazmat345 avatar hazmat345 commented on July 18, 2024

@loganasherjones ping

from brewtils.

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.