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

Refactor OmegaConfigLoader #4100

Merged
merged 8 commits into from
Aug 29, 2024
Merged

Refactor OmegaConfigLoader #4100

merged 8 commits into from
Aug 29, 2024

Conversation

merelcht
Copy link
Member

@merelcht merelcht commented Aug 16, 2024

Description

The methods in OmegaConfigLoader are big and getting more complicated each time we make a change.

Development notes

I simplified things by:

  • Extracting the filesystem and protocol setup into a separate function _initialise_filesystem_and_protocol
  • Extracting the merging steps of the base and default_run_env config into a separate function _merge_configs
  • Added a check to return early if chosen env config is the same as base config to avoid loading the same config twice and not do unnecessary merging.

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

…un env is also set

Signed-off-by: Merel Theisen <merel.theisen@quantumblack.com>
Signed-off-by: Merel Theisen <merel.theisen@quantumblack.com>
@merelcht merelcht changed the base branch from main to fix/omegaconf-runtime-param-resolution August 16, 2024 11:46
Base automatically changed from fix/omegaconf-runtime-param-resolution to main August 21, 2024 15:52
# Conflicts:
#	tests/config/test_omegaconf_config.py
Signed-off-by: Merel Theisen <merel.theisen@quantumblack.com>
@merelcht merelcht marked this pull request as ready for review August 22, 2024 15:58
@merelcht merelcht self-assigned this Aug 22, 2024
Copy link
Contributor

@ElenaKhaustova ElenaKhaustova left a comment

Choose a reason for hiding this comment

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

Thank you, @merelcht, changes looks good to me.

Left one non-blocking suggestion.

key: str,
env_path: str,
) -> Any:
merging_strategy = self.merge_strategy.get(key, "destructive")
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we go even further and move merging strategies outside to the Enum and create a mapping of symbolic names to the implementations? Then all the possible values and implementations will be in one place, so it's easier to navigate and compare them, and additionally, we will get rid if else logic when applying a merging strategy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Some clarification on the above comment.

I was thinking of something like that:

class MergingStrategies(Enum):
    FIRST = "first"
    SECOND = "second"

def first_strat():
    pass
    
def second_strat():
    pass
    
merging_strategies_map = {
    MergingStrategies.FIRST: first_strat,
    MergingStrategies.SECOND: second_strat,
}

Usage:

first = strategies_map[MergingStrategies.FIRST]()
second = strategies_map[MergingStrategies("second")]()

merelcht and others added 2 commits August 28, 2024 17:53
Signed-off-by: Merel Theisen <merel.theisen@quantumblack.com>
Signed-off-by: Merel Theisen <49397448+merelcht@users.noreply.github.com>
Signed-off-by: Merel Theisen <merel.theisen@quantumblack.com>
Signed-off-by: Merel Theisen <merel.theisen@quantumblack.com>
Copy link
Contributor

@ElenaKhaustova ElenaKhaustova left a comment

Choose a reason for hiding this comment

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

Thank you, @merelcht, all clear! ✨

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.

Looks good! 💯

@merelcht merelcht merged commit f738dc8 into main Aug 29, 2024
34 checks passed
@merelcht merelcht deleted the refactor-ocl branch August 29, 2024 09:29
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.

3 participants