refactor(settings): make HathorSettings always return the same instance#626
Merged
refactor(settings): make HathorSettings always return the same instance#626
Conversation
Codecov Report
@@ Coverage Diff @@
## master #626 +/- ##
==========================================
+ Coverage 83.91% 83.94% +0.02%
==========================================
Files 240 240
Lines 20127 20126 -1
Branches 2744 2743 -1
==========================================
+ Hits 16890 16895 +5
+ Misses 2640 2635 -5
+ Partials 597 596 -1
|
glevco
requested changes
May 23, 2023
5e7f3d9 to
4fe59cd
Compare
msbrogli
previously approved these changes
May 24, 2023
glevco
requested changes
May 24, 2023
4fe59cd to
4db657c
Compare
glevco
approved these changes
May 24, 2023
This wasn't _exactly_ the case before this commit. On one side when using the deprecated module settings the same module would always be loaded, and the same `SETTINGS` property would be accessed, but reloading the module (or at least leaving that up to importlib) unnecessary. On the new YAML system the file is reloaded everytime, this is also unnecessary. This commit will make it the last HathorSettings instantiated will be returned, as long as the source is the same, otherwise an exception is raised. There is a little small caveat that is fixed in this commit is that in the YAML file could in theory be altered between different calls to HathorSettings, which would lead to different content being loaded silently. What happens now is that the first time it is loaded is what is used for every call, any change in the file won't have any effect.
4db657c to
94e99cc
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This wasn't exactly the case before this commit. On one side when using the deprecated module settings the same module would always be loaded, and the same
SETTINGSproperty would be accessed, but reloading the module (or at least leaving that up to importlib) unnecessary. On the new YAML system the file is reloaded everytime, this is also unnecessary.This commit will make it the last HathorSettings instantiated will be returned, as long as the source is the same, otherwise an exception is raised.
There is a little small caveat that is fixed in this commit is that in the YAML file could in theory be altered between different calls to HathorSettings, which would lead to different content being loaded silently. What happens now is that the first time it is loaded is what is used for every call, any change in the file won't have any effect.
Acceptance Criteria
hathor.conf.HathorSettingsinstance when callinghathor.conf.get_settings.HathorSettingsget_settings_modulewithget_settings_module_paththat returns the loaded path instead of the loaded module