-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
[feature request] nested config option for inheritance #117
Comments
Thanks for the kind words! I've made an app with a nested config before I made this library. I think that would be a great feature to add to this. I'm thinking it would look something like this: @app.command()
@nested_config # uses function name
@use_yaml_config()
def generate_data(label_names: ..., input_data: ...):
...
@app.command()
@nested_config(name="label-data") # optionally change the name
@use_yaml_config()
def label_data(label_names: ..., input_data: ...):
... Where the nested config just subsets the data (and would really just be a wrapper for |
@maxb2 yea this is perfect, exactly what i was thinking. Can I help you at all in implementation? I'd love to use this for a current project |
@maxb2 in fact I'm not sure if you even need another decorator. I think this itself would be ideal
|
I was thinking the same thing, but it doesn't solve the shared variables section. However, you could use yaml anchors to solve this in your config rather than in this library. For example: label_names: &label_names
- label1
- label2
generate_data:
input_data: generator.csv
label_names: *label_names
label_data:
input_data: generator_output.csv
label_names: *label_names I will implement the On a separate note, I was working on a minimal example for you and found that setting the list argument in the config does not work with |
I've implemented a simple version of this (but specifically for yaml only, so not worth PRing since it's not global), but it should be pretty easily portable to your code. Here's the way I did it.
and I simply pass it in like so
It's not clever, and doesn't read the function name by default. But I think this would be the simplest implementation. Because you can pass this all the way to the top, since you just have a dictionary, and can check for an override key. i'm using it like this
Wdyt? |
I'm actually doing something similar with @use_ini_config() since INI requires a top level section. I'll just make an optional |
@Ben-Epstein see 1.3.0 for this feature! On a related note, if you would like to write an example for the docs using yaml anchors for shared variables once you figure out your project, please do and open a PR! |
@maxb2 this is great, thanks! I checked out your PR, but it doesn't quite enable overrides. It looks like it will only look at the section that you specify. So if I have a function like so
and my config is
this will fail, and say |
Yes, you should use yaml anchors to do that (works out of the box): a: &a
5
foo:
a: *a
b: 6
bar:
a: *a
b: 7 Or, write a transformer and create a decorator: def your_config_transformer(config: ConfigDict) -> ConfigDict:
# does whatever it needs to the whole dictionary
...
callback = conf_callback_factory(
loader_transformer(
yaml_loader,
loader_conditional=lambda param_value: param_value,
config_transformer=your_config_transformer,
)
)
your_decorator = use_config(callback)
@app.command()
@your_decorator
def command(...):
... I tried to write this library in a way that you can build whatever you need with functional composition. |
Really amazing tool, thanks for building it! I'm leveraging the
yaml_config
, and i'm wondering if there's support for having nested values in a config for overriding purposes.Imagine, for example, you have multiple typer apps (say,
generate_data
, andlabel_data
), with some shared variables, (sayinput_file_name
,label_names
), for example.I could imagine a yaml file like so
Such that a single config can be shared, and you can have overrides for specific typer apps. Curious your thoughts!
The text was updated successfully, but these errors were encountered: