Skip to content
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

Merged
merged 22 commits into from
Nov 21, 2023

Conversation

noklam
Copy link
Contributor

@noklam noklam commented Nov 15, 2023

NOTE: Kedro datasets are moving from kedro.extras.datasets to a separate kedro-datasets package in
kedro-plugins repository. Any changes to the dataset implementations
should be done by opening a pull request in that repository.

Description

Part of #2971. This enable the use of ConfigLoader as a standalone component while keeping existing behavior unchanged.

Development notes

Developer 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

  • Read the contributing guidelines
  • Signed off each commit with a Developer Certificate of Origin (DCO)
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added a description of this change in the RELEASE.md file
  • Added tests to cover my changes
  • Checked if this change will affect Kedro-Viz, and if so, communicated that with the Viz team

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@noklam noklam force-pushed the noklam/remove-the-environment-default-2971 branch from fa67190 to 6a363cf Compare November 15, 2023 07:11
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>
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>
Signed-off-by: Nok Chan <nok.lam.chan@quantumblack.com>
Comment on lines +198 to +204
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
Copy link
Contributor Author

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>
@noklam noklam marked this pull request as ready for review November 16, 2023 06:02
@noklam noklam self-assigned this Nov 16, 2023
@noklam noklam linked an issue Nov 16, 2023 that may be closed by this pull request
@noklam noklam linked an issue Nov 16, 2023 that may be closed by this pull request
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Copy link
Member

@astrojuanlu astrojuanlu left a 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 👍🏽

Copy link
Contributor

@ankatiyar ankatiyar left a 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?

Comment on lines 1068 to 1008
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)
Copy link
Contributor

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

@noklam
Copy link
Contributor Author

noklam commented Nov 17, 2023

LGTM! Tried it locally. Do the docs need to be updated for this too?

@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 OmegaConfigLoader

I will fix the test coverage later since I want to wait for @merelcht review as well.

@stichbury
Copy link
Contributor

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 OmegaConfigLoader

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.

Copy link
Member

@merelcht merelcht left a 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?

RELEASE.md Outdated Show resolved Hide resolved
tests/config/test_omegaconf_config.py Outdated Show resolved Hide resolved
tests/config/test_omegaconf_config.py Outdated Show resolved Hide resolved
@noklam
Copy link
Contributor Author

noklam commented Nov 20, 2023

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?

@merelcht I have added a test for the latter. One thing that I am not sure is the only "" case.

Assuming a structure like this and the parameters.yml has the same content.

--base/parameters.yml
--local/parameters.yml

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 base_env="." is going to read both files due to this the default config pattern **/parameters* (match "local/parameters.yml" and "base/parameters.yml").

E ValueError: Duplicate keys found in /tmp/pytest-of-gitpod/pytest-5/test_load_config_only_default_0/local/parameters.yml and /tmp/pytest-of-gitpod/pytest-5/test_load_config_only_default_0/base/parameters.yml: dummy

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>
@merelcht
Copy link
Member

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?

@merelcht I have added a test for the latter. One thing that I am not sure is the only "" case.

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 base_env="my_env" and default_run_env="my_other_env". I guess this isn't actually different from "base" and "local", but might be good to have an explicit test.

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@noklam
Copy link
Contributor Author

noklam commented Nov 21, 2023

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 base_env="my_env" and default_run_env="my_other_env". I guess this isn't actually different from "base" and "local", but might be good to have an explicit test.

@merelcht Ah, I see what you mean now. I have updated the original tests test_load_config_only_default_run_environment and test_load_config_only_base_environment for this.

Copy link
Member

@merelcht merelcht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! 👍

@noklam noklam enabled auto-merge (squash) November 21, 2023 10:10
@noklam noklam merged commit c1cf255 into develop Nov 21, 2023
36 checks passed
@noklam noklam deleted the noklam/remove-the-environment-default-2971 branch November 21, 2023 13:22
stichbury pushed a commit that referenced this pull request Nov 28, 2023
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove the environment default for ConfigLoader
5 participants