-
Notifications
You must be signed in to change notification settings - Fork 904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moved the environment assumption from ConfigLoader
to _ProjectSettings
#3311
Conversation
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
fa67190
to
6a363cf
Compare
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
…om:kedro-org/kedro into noklam/remove-the-environment-default-2971 Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
bootstrap_project(tmp_path) | ||
|
||
session = KedroSession.create( | ||
project_path=tmp_path, env=env, extra_params=extra_params | ||
) | ||
context = session.load_context() | ||
config_loader = context.config_loader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test was never updated after session is created. This is causing fail test because settings will not propagate correctly if we try to construct KedroContext directly.
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirm that this works as expected from a usage point of view:
$ tree (kedro38-dev)
.
└── catalog.yml
1 directory, 1 file
$ ipython --no-banner
In [1]: from kedro.config import OmegaConfigLoader
In [2]: conf_loader = OmegaConfigLoader(conf_source=".")
In [3]: conf_loader["catalog"]
Out[3]: {'test_csv': {'type': 'pandas.CSVDataset', 'filepath': 'companies.csv'}}
Also did a quick check on an old spaceflights
starter and nothing broke 👍🏽
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Tried it locally. Do the docs need to be updated for this too?
def test_runtime_params_in_globals_not_allowed(self, tmp_path): | ||
base_globals = tmp_path / _BASE_ENV / "globals.yml" | ||
local_globals = tmp_path / _DEFAULT_RUN_ENV / "globals.yml" | ||
runtime_params = { | ||
"x": 45, | ||
} | ||
base_globals_config = { | ||
"my_global_var": "${runtime_params:x}", | ||
} | ||
local_globals_config = { | ||
"my_local_var": "${runtime_params:x}", # x does exist but shouldn't be allowed in globals | ||
"my_global_var": "${runtime_params:x}", # x does exist but shouldn't be allowed in globals | ||
} | ||
|
||
_write_yaml(base_globals, base_globals_config) | ||
_write_yaml(local_globals, local_globals_config) | ||
|
||
with pytest.raises( | ||
UnsupportedInterpolationType, | ||
match=r"The `runtime_params:` resolver is not supported for globals.", | ||
): | ||
OmegaConfigLoader( | ||
tmp_path, | ||
base_env="", | ||
default_run_env="local", | ||
base_env=_BASE_ENV, | ||
default_run_env=_DEFAULT_RUN_ENV, | ||
runtime_params=runtime_params, | ||
) | ||
with pytest.raises( | ||
UnsupportedInterpolationType, | ||
match=r"The `runtime_params:` resolver is not supported for globals.", | ||
): | ||
OmegaConfigLoader(tmp_path, runtime_params=runtime_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be reverted for code coverage I think
@ankatiyar Good point, we can do that in a separate PR. I am not sure where would be the best place to do this, maybe https://docs.kedro.org/en/stable/notebooks_and_ipython/notebook-example/add_kedro_to_a_notebook.html? Cc @stichbury What do you think? This related to the change of default arguments, thus make it easier to use ConfigLoader as a standalone component. Should we also update this in the Configuration page? The default of a Kedro project is unchanged (base and local), but it wouldn't be required if someone just import I will fix the test coverage later since I want to wait for @merelcht review as well. |
Thanks for the catch @noklam -- yes, I think the best option is to update the configuration docs to highlight the change. Then illustrate its usage in the notebook example as @ankatiyar suggests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks good to me! 👍 One thing I didn't immediately see was if we have test that explicitly tests different environments from base
, local
, and ""
. And if we have a test where we only set the default_run_env
and not the base?
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@merelcht I have added a test for the latter. One thing that I am not sure is the only Assuming a structure like this and the
You can either use both environments, or move everything to base. If you choose to keep this structure while setting no environment. You get "duplicate key error" because setting
We can avoid this by conditionally checking with something like if base_env or default_run_env:
self.config_patterns = {
"catalog": ["catalog*", "catalog*/**", "**/catalog*"],
"parameters": ["parameters*", "parameters*/**", "**/parameters*"],
"credentials": ["credentials*", "credentials*/**", "**/credentials*"],
"globals": ["globals.yml"],
}
else:
self.config_patterns = {
"catalog": ["catalog*", "catalog*/**",],
"parameters": ["parameters*", "parameters*/**"],
"credentials": ["credentials*", "credentials*/**"],
"globals": ["globals.yml"],
} It will avoid the problem but I don't like it because it is very special to this one case. Maybe what we can do is to enhance the error message, so it tells you which "env" is causing this error, additionally printing the related "config_pattern"? |
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Aahh sorry reading my own comment again, I realise it's not very clear 😅 What I meant to say, is that I'm not sure if there's a test which checks if this all works when you have a random environment, so |
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@merelcht Ah, I see what you mean now. I have updated the original tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! 👍
…ings` (#3311) * update release notes Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * Remove the default env in config loader - add the env in tests Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com> * remove unncessary `default_run_env` Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com> * fix tests Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com> * Added a couple of tests to make sure config loader standalone mode works Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com> * fix tests Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com> * lint Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com> * Fix tests Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * update default Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * fix test coverage Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * fix test and lint Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * rename test to 'without_environment' to reflect the change of defaults Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * fix tests according to comments Signed-off-by: Nok <nok.lam.chan@quantumblack.com> * update test to test arbitary env explicitly Signed-off-by: Nok <nok.lam.chan@quantumblack.com> --------- Signed-off-by: Nok <nok.lam.chan@quantumblack.com> Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com> Signed-off-by: Jo Stichbury <jo_stichbury@mckinsey.com>
Description
Part of #2971. This enable the use of ConfigLoader as a standalone component while keeping existing behavior unchanged.
Development notes
settings.py
to declare the defaults explicitlybase
andlocal
assumption from ConfigLoader ->_ProjectSettings
settings.py
in starters - add default environment in settings kedro-starters#183Developer Certificate of Origin
We need all contributions to comply with the Developer Certificate of Origin (DCO). All commits must be signed off by including a
Signed-off-by
line in the commit message. See our wiki for guidance.If your PR is blocked due to unsigned commits, then you must follow the instructions under "Rebase the branch" on the GitHub Checks page for your PR. This will retroactively add the sign-off to all unsigned commits and allow the DCO check to pass.
Checklist
RELEASE.md
file