Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better config parsing #37

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Conversation

phijor
Copy link
Collaborator

@phijor phijor commented Jun 22, 2021

No description provided.

@phijor phijor force-pushed the feature-better-config-parsing branch from 1beaf7e to 2cfd4d7 Compare June 24, 2021 13:38
@phijor phijor force-pushed the feature-better-config-parsing branch from 2cfd4d7 to 734cf04 Compare July 21, 2021 08:43
@phijor phijor force-pushed the feature-better-config-parsing branch from 734cf04 to 3a425af Compare July 21, 2021 15:02
@bmario
Copy link
Member

bmario commented Oct 21, 2021

@phijor Do you remember what's the current state of this?

@phijor
Copy link
Collaborator Author

phijor commented Oct 22, 2021

Yes, the goals here were:

  1. Modularize parsing of the configuration sent to the sink.
    In particular, objects are now initialized recursively from the configuration:

    class Foo:
        def __init__(self, bar: Bar):
            self.bar = bar
    
        @static_method
        def from_config(foo_config: dict) -> Foo:
            bar = some_processing(foo_config.get('bar', 'default'))
            returns Foo(bar=bar)
    
    class Quux:
        def __init__(self, foo: Foo):
            self.foo = foo
    
        @static_method
        def from_config(quux_config: dict) -> Quux:
            foo = some_more_processing(quux_config.get('foo', 42))
            returns Quux(foo=foo)

    This way, the constructors of Quux and Foo do not have to know about the particular format of the config, most importantly they don't care about how their fields get parsed from a constructors; they simply receive something that is already initialized.

  2. Make classes testable. With 1. in place, Check in particular now becomes testable: Check.__init__ is now much more simple and does not care about what the configuration looks like, so you can simply supply some mock objects. On the other hand Check.from_config becomes testable. This for example immediately cought the bug in f968e24.

  3. Have a uniform style of parsing the configuration at each level, in contrast to doing everything at once in Reporter._on_config().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants