def test_load_config_file_with_schema_validation( self, hydra_restore_singletons: Any, path: str) -> None: with ConfigStoreWithProvider("this_test") as cs: cs.store(name="config", node=TopLevelConfig) cs.store(group="db", name="mysql", node=MySQLConfig, package="db") config_loader = ConfigLoaderImpl( config_search_path=create_config_search_path(path)) cfg = config_loader.load_configuration( config_name="config", overrides=["+db=mysql"], strict=False, run_mode=RunMode.RUN, ) with open_dict(cfg): del cfg["hydra"] assert cfg == { "normal_yaml_config": True, "db": { "driver": "mysql", "host": "???", "port": "???", "user": "******", "password": "******", }, } expected = hydra_load_list.copy() expected.append(LoadTrace("config", path, "main", "this_test")) expected.append(LoadTrace("db/mysql", path, "main", "this_test")) assert config_loader.get_load_history() == expected
def test_load_config_file_with_schema_validation(self, restore_singletons: Any, path: str) -> None: with ConfigStoreWithProvider("test_provider") as config_store: config_store.store(group="db", name="mysql", node=MySQLConfig, package="db") config_loader = ConfigLoaderImpl( config_search_path=create_config_search_path(path)) cfg = config_loader.load_configuration(config_name="db/mysql", overrides=[], strict=False) with open_dict(cfg): del cfg["hydra"] assert cfg == { "db": { "driver": "mysql", "host": "???", "port": "???", "user": "******", "password": "******", } } expected = hydra_load_list.copy() expected.append(LoadTrace("db/mysql", path, "main", "test_provider")) assert config_loader.get_load_history() == expected
def test_load_config_file_with_schema_validation( self, hydra_restore_singletons: Any, path: str) -> None: with ConfigStoreWithProvider("this_test") as cs: cs.store(name="config", node=TopLevelConfig) cs.store(group="db", name="mysql", node=MySQLConfig, package="db") config_loader = ConfigLoaderImpl( config_search_path=create_config_search_path(path)) msg = dedent("""\ 'config' is validated against ConfigStore schema with the same name. This behavior is deprecated in Hydra 1.1 and will be removed in Hydra 1.2. See https://hydra.cc/docs/next/upgrades/1.0_to_1.1/automatic_schema_matching for migration instructions.""" ) with pytest.warns(UserWarning, match=re.escape(msg)): cfg = config_loader.load_configuration( config_name="config", overrides=["+db=mysql"], run_mode=RunMode.RUN, ) with open_dict(cfg): del cfg["hydra"] assert cfg == { "normal_yaml_config": True, "db": { "driver": "mysql", "host": "???", "port": "???", "user": "******", "password": "******", }, }
def test_load_config_file_with_schema_validation( self, hydra_restore_singletons: Any, path: str ) -> None: with ConfigStoreWithProvider("this_test") as cs: cs.store(name="config", node=TopLevelConfig) cs.store(group="db", name="mysql", node=MySQLConfig, package="db") config_loader = ConfigLoaderImpl( config_search_path=create_config_search_path(path) ) cfg = config_loader.load_configuration( config_name="config", overrides=["+db=mysql"], strict=False, run_mode=RunMode.RUN, ) expected = deepcopy(hydra_load_list) expected.extend( [ LoadTrace( config_path="config", package="", parent="<root>", search_path=path, provider="main", ), LoadTrace( config_path="db/mysql", package="db", parent="<root>", search_path=path, provider="main", ), ] ) assert_same_composition_trace(cfg.hydra.composition_trace, expected) with open_dict(cfg): del cfg["hydra"] assert cfg == { "normal_yaml_config": True, "db": { "driver": "mysql", "host": "???", "port": "???", "user": "******", "password": "******", }, }
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from hydra.core.config_store import ConfigStoreWithProvider from mephisto.data_model.blueprint import BlueprintArgs from mephisto.data_model.architect import ArchitectArgs from mephisto.data_model.crowd_provider import ProviderArgs from mephisto.data_model.task_config import TaskConfigArgs from dataclasses import dataclass, field from omegaconf import MISSING from typing import List, Any config = ConfigStoreWithProvider("mephisto") @dataclass class MephistoConfig: blueprint: BlueprintArgs = BlueprintArgs() provider: ProviderArgs = ProviderArgs() architect: ArchitectArgs = ArchitectArgs() task: TaskConfigArgs = TaskConfigArgs() @dataclass class RunScriptConfig: mephisto: MephistoConfig = MephistoConfig()