-
Notifications
You must be signed in to change notification settings - Fork 52
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
adding yaml config interpolation #294
Comments
Hello there @stas00 , thanks for posting! :) I'm familiar with Hydra/OmegaConf, and this feature is very powerful. I agree that it would be great to also have this in Simple-Parsing. One way to do this could be to add omegaconf as an optional extra dependency, and reuse as much of their interpolation code as possible, with some custom logic as needed. I'm assuming we'd want to use this only when parsing config files, correct? from dataclasses import dataclass
from simple_parsing import interpolated_field, parse
@dataclass
class Server:
host: str
port: int
@dataclass
class Client
url: str = interpolated_field("https://${server.host}:${server.port}/")
server_port: int = interpolated_field("${server.port}")
#relative interpolation
description: str = interpolated_field("Client of ${.url}")
@dataclass
class Config:
server: Server
client: Client
config = parse(Config) Note: For the last kind of (relative) interpolation, I made this little gist for what I call I think that adding interpolation in just yaml files first would be a (challenging) good start. It shouldn't be much more work to later add a helper function to also make this possible in the dataclasses, if we think this is useful. Thanks again for posting, let me know what you think! :) |
Hi Fabrice, I agree that starting with interpolation support in just the yaml file would be great! For the dataclasses python code one could already use the |
|
Indeed, the top dataclass class will receive access to all parsed configs, so that's where we currently manipulate things. |
+1 to adding suport for Omega-conf style interpolation! |
Is your feature request related to a problem? Please describe.
Could SimpleParsing add support for interpolation? here is an example of how omegaconf does it:
https://omegaconf.readthedocs.io/en/2.3_branch/usage.html#config-node-interpolation
Describe the solution you'd like
So that we could do something like this:
Input YAML file:
Thank you!
The text was updated successfully, but these errors were encountered: