Skip to content

Commit

Permalink
fix issue when reloading configuration.
Browse files Browse the repository at this point in the history
Indeed, before this patch, any custom configuration may have been
destroyed when config_file and config_dir has been changed.
  • Loading branch information
funilrys committed Sep 29, 2024
1 parent 541dd57 commit a587817
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions PyFunceble/config/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def wrapper(self, *args, **kwargs):
result = func(self, *args, **kwargs) # pylint: disable=not-callable

if self.is_already_loaded():
self.reload()
self.reload(keep_custom=True)

return result

Expand Down Expand Up @@ -519,12 +519,16 @@ def get_configured_value(self, entry: str) -> Any:

return PyFunceble.storage.FLATTEN_CONFIGURATION[entry]

def reload(self) -> "ConfigLoader":
def reload(self, keep_custom: bool = False) -> "ConfigLoader":
"""
Reloads the configuration.
:param bool keep_custom:
If set to :code:`True`, we keep the custom configuration, otherwise
we delete it.
"""

self.destroy()
self.destroy(keep_custom=keep_custom)
self.start()

def start(self) -> "ConfigLoader":
Expand Down Expand Up @@ -560,9 +564,13 @@ def start(self) -> "ConfigLoader":

return self

def destroy(self) -> "ConfigLoader":
def destroy(self, keep_custom: bool = False) -> "ConfigLoader":
"""
Destroys everything loaded.
:param bool keep_custom:
If set to :code:`True`, we keep the custom configuration, otherwise
we delete it.
"""

try:
Expand All @@ -577,7 +585,8 @@ def destroy(self) -> "ConfigLoader":
except (AttributeError, TypeError): # pragma: no cover ## Safety.
pass

# This is not a mistake.
self._custom_config = {}
if not keep_custom:
# This is not a mistake.
self._custom_config = {}

return self

0 comments on commit a587817

Please sign in to comment.