Created
October 29, 2020 19:55
-
-
Save omry/ccaad30a0e07da712148dcf0166d47d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defaults: | |
- db: mysql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @package _group_ | |
defaults: | |
- schema/db/mysql | |
- _self_ | |
host: localhost | |
port: 3306 | |
driver: mysql | |
user: omry | |
password: secret |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @package _group_ | |
defaults: | |
- schema/db/postgresql | |
- _self_ | |
host: localhost | |
port: 5432 | |
driver: postgresql | |
user: postgre_user | |
password: secret | |
timeout: 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved | |
from dataclasses import dataclass | |
from omegaconf import OmegaConf, DictConfig | |
import hydra | |
from hydra.core.config_store import ConfigStore | |
@dataclass | |
class MySQLConfig: | |
host: str | |
port: int | |
user: str | |
password: str | |
driver: str = "mysql" | |
@dataclass | |
class PostGreSQLConfig: | |
host: str | |
port: int | |
timeout: int | |
user: str | |
password: str | |
driver: str = "postgresql" | |
cs = ConfigStore.instance() | |
cs.store(group="schema/db", name="mysql", node=MySQLConfig, package="db") | |
cs.store(group="schema/db", name="postgresql", node=PostGreSQLConfig, package="db") | |
@hydra.main(config_path="conf", config_name="config") | |
def my_app(cfg: DictConfig) -> None: | |
print(OmegaConf.to_yaml(cfg)) | |
if __name__ == "__main__": | |
my_app() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Structure:
Example outputs: