Roger-luo / Configurations.jl

Options & Configurations made easy.
https://configurations.rogerluo.dev/stable
MIT License
80 stars 12 forks source link

Where does #metadata# go? #85

Open evetion opened 1 year ago

evetion commented 1 year ago

I'm using from_toml, and it would be nice to be able to override construction with the path of the toml file (e.g. when paths in the TOML are relative to the TOML itself). Could it be passed in a user defined from_dict() method?

Otherwise it's unclear to me where the #metadata# key ends up in from_dict.

Roger-luo commented 1 year ago

No, it only appears in from_toml, I haven't thought much how this information be propagated into from_dict, so if you need to preprocess something you should overload from_toml, could you elaborate on your use cases a bit more? for example by providing an example

evetion commented 1 year ago

So somewhere in from_dict the key #metadata# is ignored? I'd assumed it would throw InvalidKeyError?

could you elaborate on your use cases a bit more

An example would be a toml:

path = "relative.file"  # relative path

Such a path can be absolute or relative. In case it's relative, it can be assumed it's relative to the TOML file itself. However, this foldername is not accessible on construction (or when overloading from_dict(::Type{MyType}, ::Type{SystemPath}, s)), but is precisely what you pass in d["#metadata#"]["dir"] in from_toml.

Roger-luo commented 1 year ago

Yes, it's ignored by validation, this is a special field to give you access to that

https://github.com/Roger-luo/Configurations.jl/blob/0aa33c3e3eb1a1aaef1f8b8f542aa43bf5dd8cf0/src/from_dict.jl#L86

Roger-luo commented 1 year ago

I think this field should always be available if you construct using from_toml etc

evetion commented 1 year ago

Ok, but how would one access the #metadata# key? Naming such an field in my custom type is not directly possible.

Roger-luo commented 1 year ago

ah, you need to overload your custom from_dict, it will not appear in your custom type by default, it's a meta info only used by the parsers