From 73795d27b872f700669a17cabb128eff9f2157b8 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 14 Dec 2023 21:25:00 +0100 Subject: [PATCH] config: add default_config_filename parameter --- mylib/config.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mylib/config.py b/mylib/config.py index 8efd5af..fad492d 100644 --- a/mylib/config.py +++ b/mylib/config.py @@ -666,6 +666,7 @@ class Config: # pylint: disable=too-many-instance-attributes encoding=None, config_file_env_variable=None, default_config_dirpath=None, + default_config_filename=None, ): self.appname = appname self.shortname = shortname @@ -680,6 +681,7 @@ class Config: # pylint: disable=too-many-instance-attributes self._filepath = None self.config_file_env_variable = config_file_env_variable self.default_config_dirpath = default_config_dirpath + self.default_config_filename = default_config_filename self._init_config_parser() def add_section(self, name, loaded_callback=None, **kwargs): @@ -1204,9 +1206,11 @@ class Config: # pylint: disable=too-many-instance-attributes return self._filepath if self.config_file_env_variable and os.environ.get(self.config_file_env_variable): return os.environ.get(self.config_file_env_variable) - return os.path.join( - self.config_dir, f"{self.shortname}.ini" if self.shortname else "config.ini" - ) + if self.default_config_filename: + filename = self.default_config_filename + else: + filename = f"{self.shortname}.ini" if self.shortname else "config.ini" + return os.path.join(self.config_dir, filename) class ConfigurableObject: