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

Passing config object itself to registered functions #380

Open
DragonDuck opened this issue Aug 14, 2020 · 0 comments
Open

Passing config object itself to registered functions #380

DragonDuck opened this issue Aug 14, 2020 · 0 comments
Labels
feat / config Configuration system and config files

Comments

@DragonDuck
Copy link

DragonDuck commented Aug 14, 2020

Configuration entries marked with a @ are treated as calls to function registries and the other entries within that dictionary are treated as function arguments. Is there a way to pass the configuration file itself as a function parameter? For example, let's say I have a registered function defined as:

@registry.visualizer("v1")
def my_visualizer_v1(a, b):
    # do stuff

And a configuration file:

[Global]
var1 = 123
var2 = "foo"
[Visualizer]
@visualizer = "v1"
a = ${Global:var1}
b = ${Global:var2}

Is there a way to pass the configuration object itself to my_visualizer_v1 and let it retrieve the values it needs, e.g.

@registry.visualizer("v1")
def my_visualizer_v1(cfg):
    a = cfg.Global.var1
    b = cfg.Global.var2
    # do stuff

My use case is that the parameters defined in the config file are used throughout the library; only a few of them are actually unique to the visualizer function(s). I don't want users to have to remember which of the parameters a certain version of a function needs (for example, another version of the function may require additional or fewer parameters than v1 does) and would rather have the functions themselves extract what they need from the config file.

@svlandeg svlandeg added the feat / config Configuration system and config files label Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat / config Configuration system and config files
Projects
None yet
Development

No branches or pull requests

2 participants