Skip to content

Commit

Permalink
Introduction of a way provide a custom configuration folder.
Browse files Browse the repository at this point in the history
This patch fixes #377.

Contributors:
  * @spirillen
  • Loading branch information
funilrys committed Sep 29, 2024
1 parent 90b0d98 commit 541dd57
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions PyFunceble/cli/entry_points/pyfunceble/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,16 @@ def get_default_group_data() -> List[Tuple[List[str], dict]]:
"overwritten by your overwrite configuration file.",
},
),
(
[
"--config-dir",
],
{
"dest": "config_dir",
"type": os.path.realpath,
"help": "Sets the configuration directory to use.",
},
),
]


Expand Down
4 changes: 4 additions & 0 deletions PyFunceble/cli/system/integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ def start(self) -> "SystemIntegrator":
)
)

if hasattr(self.args, "config_dir") and self.args.config_dir:
PyFunceble.facility.ConfigLoader.set_config_dir(self.args.config_dir)
PyFunceble.storage.CONFIG_DIRECTORY = self.args.config_dir

if hasattr(self.args, "config_file") and self.args.config_file:
PyFunceble.facility.ConfigLoader.set_remote_config_location(
self.args.config_file
Expand Down
6 changes: 5 additions & 1 deletion PyFunceble/config/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import importlib_resources as package_resources

from box import Box
from dotenv import load_dotenv
from yaml.error import MarkedYAMLError

import PyFunceble.cli.storage
Expand Down Expand Up @@ -144,7 +145,7 @@ def wrapper(self, *args, **kwargs):
result = func(self, *args, **kwargs) # pylint: disable=not-callable

if self.is_already_loaded():
self.start()
self.reload()

return result

Expand Down Expand Up @@ -531,6 +532,9 @@ def start(self) -> "ConfigLoader":
Starts the loading processIs.
"""

load_dotenv(os.path.join(self.config_dir, ".env"))
load_dotenv(os.path.join(self.config_dir, PyFunceble.storage.ENV_FILENAME))

config = self.get_config_file_content()

if self.custom_config:
Expand Down

0 comments on commit 541dd57

Please sign in to comment.