Skip to content

Conversation

@artemrys
Copy link
Member

Issue number: ADDON-78488

PR Type

What kind of change does this PR introduce?

  • Feature
  • Bug Fix
  • Refactoring (no functional or API changes)
  • Documentation Update
  • Maintenance (dependency updates, CI, etc.)

Summary

Changes

This PR introduces a new method to initialize GlobalConfig instance - from_file. It accepts a path to the globalConfig file (can be JSON or YAML) and returns an instance of GlobalConfig.

It's a preparation work for #1625 PR.

User experience

N/A

Checklist

If an item doesn't apply to your changes, leave it unchecked.

Review

  • self-review - I have performed a self-review of this change according to the development guidelines
  • Changes are documented. The documentation is understandable, examples work (more info)
  • PR title and description follows the contributing principles
  • meeting - I have scheduled a meeting or recorded a demo to explain these changes (if there is a video, put a link below and in the ticket)

Tests

See the testing doc.

  • Unit - tests have been added/modified to cover the changes
  • Smoke - tests have been added/modified to cover the changes
  • UI - tests have been added/modified to cover the changes
  • coverage - I have checked the code coverage of my changes (see more)

Demo/meeting:

Reviewers are encouraged to request meetings or demos if any part of the change is unclear

@github-actions
Copy link

Code Coverage 🎉

Type PR Develop Change Status
Line Coverage 86.97% 86.95% 0.02% 🟢 Increased
Branch Coverage 80.27% 80.27% 0.00% ⚪ Unchanged

@artemrys artemrys marked this pull request as ready for review March 21, 2025 14:14
@artemrys artemrys requested a review from a team as a code owner March 21, 2025 14:14

class GlobalConfig:
def __init__(self, global_config_path: str) -> None:
def __init__(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we could cover tests and use cases to capture this alteration, to ensure that this isn't changed in future?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's indirectly tested by from_file calling it, do you think about some other tests we can have?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can add those in a separate small PR.

self,
content: Dict[str, Any],
is_yaml: bool,
original_path: str,
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are passing the original_path, we could directly load the file into memory, making content redundant, as we are doing right now. How does this new __init__ benefit us?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see one advantage - easier unit testing, as a file does not need to be created.

As for the original_path, maybe we should remove it? It is used in dashboards to read the global config (we can access the content directly instead), plus handle_global_config_update - we could add a new parameter for path.

Copy link
Member Author

Choose a reason for hiding this comment

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

+1 to what Kamił said

As for the original_path, maybe we should remove it? It is used in dashboards to read the global config (we can access the content directly instead), plus handle_global_config_update - we could add a new parameter for path.

Totally agree with you, I've been thinking about it but I'd like to do it in a separate small PR so it can be reviewed and merged quickly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we update the source code to simplify unit testing, or when we have to add optimizations and efficiencies to source code? This way, I think we would be proceeding with Classical unit testing instead of Mockist unit testing.

Copy link
Member Author

Choose a reason for hiding this comment

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

In my opinion, if it's hard to write unit tests or it's hard to understand what's there - it's time to simplify. It might take couple of iterations to come up with the testable implementation for the feature which is completely fine by me.

self,
content: Dict[str, Any],
is_yaml: bool,
original_path: str,
Copy link
Contributor

Choose a reason for hiding this comment

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

I see one advantage - easier unit testing, as a file does not need to be created.

As for the original_path, maybe we should remove it? It is used in dashboards to read the global config (we can access the content directly instead), plus handle_global_config_update - we could add a new parameter for path.

@artemrys artemrys merged commit 34ad0cb into develop Mar 26, 2025
93 of 94 checks passed
@artemrys artemrys deleted the refactor/global-config branch March 26, 2025 14:00
@github-actions github-actions bot locked and limited conversation to collaborators Mar 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants