Auto schema
Scripts that creates Schemas for hydra config files.
This is very helpful when using Hydra! It shows the user what options are available, along with their description and default values, and displays errors if you have config files with invalid values.
todos#
- [ ] Support '???' as a value for any property.
- [ ] Modify the schema to support omegaconf directives like ${oc.env:VAR_NAME} and our custom directives like ${instance_attr} and so on.
- [ ] todo: Make a hydra plugin that creates the schemas for configs when hydra is loading stuff.
Schema #
create_schema_for_config #
create_schema_for_config(
config: dict | DictConfig,
config_file: Path,
configs_dir: Path | None,
) -> Schema | ObjectSchema
IDEA: Create a schema for the given config.
- If you encounter a key, add it to the schema.
- If you encounter a value with a target, use a dedicated function to get the schema for that target, and merge it into the current schema.
- Only the top-level config (
config
) can have adefaults: list[str]
key.- Should ideally load the defaults and merge this schema on top of them.
add_schema_header #
Add a comment in the yaml config file to tell yaml language server where to look for the schema.
Importantly in the context of Hydra, this comment line should be added after any #
@package: <xyz>
directives of Hydra, otherwise Hydra doesn't use those directives properly
anymore.