From d9db40fddcaec5a8643d9a50de42a622a8bb8fba Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 31 Aug 2025 11:25:41 -0500 Subject: [PATCH] fix: fix 'too-many-locals' for pylint --- .pylintrc | 1 - src/wuttjamaican/conf.py | 36 +++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.pylintrc b/.pylintrc index 7a86915..bd7e6f3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -5,4 +5,3 @@ disable= attribute-defined-outside-init, fixme, too-many-branches, - too-many-locals, diff --git a/src/wuttjamaican/conf.py b/src/wuttjamaican/conf.py index ad834a6..fc8ed5c 100644 --- a/src/wuttjamaican/conf.py +++ b/src/wuttjamaican/conf.py @@ -275,20 +275,8 @@ class WuttaConfig: # pylint: disable=too-many-instance-attributes raise FileNotFoundError(f"could not read required config file: {path}") return - # load all values into (yet another) temp config - temp_config = configparser.RawConfigParser() - for section in config.sections(): - temp_config.add_section(section) - # nb. must interpolate most values but *not* for logging formatters - raw = section.startswith("formatter_") - for option in config.options(section): - temp_config.set(section, option, config.get(section, option, raw=raw)) - - # re-write as temp file with "final" values - fd, temp_path = tempfile.mkstemp(suffix=".ini") - os.close(fd) - with open(temp_path, "wt", encoding="utf_8") as f: - temp_config.write(f) + # write config to temp file + temp_path = self._write_temp_config_file(config) # and finally, load that into our main config config = configuration.config_from_ini(temp_path, read_from_file=True) @@ -308,6 +296,24 @@ class WuttaConfig: # pylint: disable=too-many-instance-attributes for p in self.parse_list(includes): self._load_ini_configs(p, configs, require=False) + def _write_temp_config_file(self, config): + # load all values into (yet another) temp config + temp_config = configparser.RawConfigParser() + for section in config.sections(): + temp_config.add_section(section) + # nb. must interpolate most values but *not* for logging formatters + raw = section.startswith("formatter_") + for option in config.options(section): + temp_config.set(section, option, config.get(section, option, raw=raw)) + + # re-write as temp file with "final" values + fd, temp_path = tempfile.mkstemp(suffix=".ini") + os.close(fd) + with open(temp_path, "wt", encoding="utf_8") as f: + temp_config.write(f) + + return temp_path + def get_prioritized_files(self): """ Returns list of config files in order of priority. @@ -942,7 +948,7 @@ def get_config_paths( # pylint: disable=too-many-arguments,too-many-positional- return files -def make_config( # pylint: disable=too-many-arguments,too-many-positional-arguments +def make_config( # pylint: disable=too-many-arguments,too-many-positional-arguments,too-many-locals files=None, plus_files=None, appname="wutta",