Skip to content

Commit

Permalink
Modify name of environment resolver from oc.env to env
Browse files Browse the repository at this point in the history
Signed-off-by: Jannic Holzer <jannic.holzer@quantumblack.com>
  • Loading branch information
jmholzer committed Jan 13, 2023
1 parent 7e6727f commit ab9784a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions kedro/config/omegaconf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ def _resolve_environment_variables(config: Dict[str, Any]) -> None:
Arguments:
config {Dict[str, Any]} -- The configuration dictionary to resolve.
"""
if not OmegaConf.has_resolver("oc.env"):
OmegaConf.register_new_resolver("oc.env", oc.env)
if not OmegaConf.has_resolver("env"):
OmegaConf.register_new_resolver("env", oc.env)
OmegaConf.resolve(config)
OmegaConf.clear_resolver("oc.env")
OmegaConf.clear_resolver("env")
else:
OmegaConf.resolve(config)

Expand Down
18 changes: 9 additions & 9 deletions tests/config/test_omegaconf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ def proj_catalog_nested(tmp_path):
@pytest.fixture
def proj_catalog_env_variable(tmp_path):
path = tmp_path / _BASE_ENV / "catalog" / "dir" / "nested.yml"
_write_yaml(path, {"test": {"file_path": "${oc.env:TEST_FILE_PATH}"}})
_write_yaml(path, {"test": {"file_path": "${env:TEST_FILE_PATH}"}})


@pytest.fixture
def proj_credentials_env_variable(tmp_path):
path = tmp_path / _DEFAULT_RUN_ENV / "credentials.yml"
_write_yaml(
path, {"user": {"name": "${oc.env:TEST_USERNAME}", "key": "${oc.env:TEST_KEY}"}}
path, {"user": {"name": "${env:TEST_USERNAME}", "key": "${env:TEST_KEY}"}}
)


Expand Down Expand Up @@ -456,7 +456,7 @@ def test_load_credentials_from_env_variables(self, tmp_path):
@use_config_dir
@use_catalog_env_variable_yml
def test_env_resolver_not_used_for_catalog(self, tmp_path):
"""Check that the oc.env resolver is not used for catalog loading"""
"""Check that the env resolver is not used for catalog loading"""
conf = OmegaConfLoader(str(tmp_path))
os.environ["TEST_DATASET"] = "test_dataset"
with pytest.raises(errors.UnsupportedInterpolationType):
Expand All @@ -465,23 +465,23 @@ def test_env_resolver_not_used_for_catalog(self, tmp_path):
@use_config_dir
@use_credentials_env_variable_yml
def test_env_resolver_is_cleared_after_loading(self, tmp_path):
"""Check that the ``oc.env`` resolver is cleared after loading credentials
"""Check that the env resolver is cleared after loading credentials
in the case that it was not registered beforehand."""
conf = OmegaConfLoader(str(tmp_path))
os.environ["TEST_USERNAME"] = "test_user"
os.environ["TEST_KEY"] = "test_key"
assert conf["credentials"]["user"]["name"] == "test_user"
assert not OmegaConf.has_resolver("oc.env")
assert not OmegaConf.has_resolver("env")

@use_config_dir
@use_credentials_env_variable_yml
def test_env_resolver_is_registered_after_loading(self, tmp_path):
"""Check that the ``oc.env`` resolver is registered after loading credentials
"""Check that the env resolver is registered after loading credentials
in the case that it was registered beforehand"""
conf = OmegaConfLoader(str(tmp_path))
OmegaConf.register_new_resolver("oc.env", oc.env)
OmegaConf.register_new_resolver("env", oc.env)
os.environ["TEST_USERNAME"] = "test_user"
os.environ["TEST_KEY"] = "test_key"
assert conf["credentials"]["user"]["name"] == "test_user"
assert OmegaConf.has_resolver("oc.env")
OmegaConf.clear_resolver("oc.env")
assert OmegaConf.has_resolver("env")
OmegaConf.clear_resolver("env")

0 comments on commit ab9784a

Please sign in to comment.