From 051392ced03b1041209741854ed358df9e57815f Mon Sep 17 00:00:00 2001 From: "Jesse P. Johnson" Date: Tue, 30 Apr 2024 22:44:24 -0500 Subject: [PATCH] test: resolve linting issues --- pyproject.toml | 1 + src/compendium/config_manager.py | 11 ++++++----- src/compendium/filepaths.py | 5 ++++- src/compendium/filetypes/ini.py | 8 ++++++-- src/compendium/filetypes/json.py | 2 +- src/compendium/filetypes/xml.py | 2 +- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2de8089..2a3dfcc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,7 @@ dependencies = [ [project.optional-dependencies] xml = ["xmltodict>=0.12.0,<1"] +toml = ["tomlkit>=1,<2"] dev = [ "build", "proman-versioning>=0.1.1-beta.4", diff --git a/src/compendium/config_manager.py b/src/compendium/config_manager.py index b5a74d2..19d29ee 100644 --- a/src/compendium/config_manager.py +++ b/src/compendium/config_manager.py @@ -104,8 +104,8 @@ def load_config( self, config_file: ConfigFile, update: bool = True, - *args: str, - **kwargs: Any, + # *args: str, + # **kwargs: Any, ) -> Optional[Dict[str, Any]]: """Load settings from configuration.""" if os.path.exists(config_file.filepath): @@ -216,7 +216,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: @property def namepaths(self) -> Tuple[str, ...]: """Return list of namepaths.""" - return tuple([self.get_namepath(x.filepath) for x in self.filepaths]) + return tuple(self.get_namepath(x.filepath) for x in self.filepaths) def get_name(self, filepath: str) -> str: """Get name from tree path.""" @@ -273,13 +273,14 @@ def _prep_filepaths(self) -> None: def load_config( self, config_file: ConfigFile, - update: bool = False, *args: str, **kwargs: Any, ) -> Optional[Dict[str, Any]]: """Load config.""" # TODO: need to separate chainmap of defaults from namespace config - settings = super().load_config(config_file, update) + settings = super().load_config( + config_file, bool(kwargs.pop('update', False)) + ) return self.new_child( settings, name=self.get_name(config_file.filepath), *args, **kwargs ) diff --git a/src/compendium/filepaths.py b/src/compendium/filepaths.py index facf218..07176c5 100644 --- a/src/compendium/filepaths.py +++ b/src/compendium/filepaths.py @@ -13,6 +13,8 @@ @dataclass class File: + """Provider file data.""" + path: str name: str = field(init=False) extension: Optional[str] = field(init=False) @@ -28,7 +30,7 @@ def __post_init__(self) -> None: @dataclass -class ConfigPaths: +class ConfigPaths: # pylint: disable=too-many-instance-attributes r"""Load config paths based on priority. First(lowest) to last(highest): @@ -51,6 +53,7 @@ class ConfigPaths: - """ + name: str filename: str filetype: Optional[str] = field(init=False) diff --git a/src/compendium/filetypes/ini.py b/src/compendium/filetypes/ini.py index 947d773..e1f39bf 100644 --- a/src/compendium/filetypes/ini.py +++ b/src/compendium/filetypes/ini.py @@ -4,7 +4,7 @@ import errno import logging -from configparser import ConfigParser # ExtendedInterpolation +from configparser import ConfigParser, Error # ExtendedInterpolation from typing import Any, Dict, Tuple from compendium.filetypes import FiletypesBase @@ -30,9 +30,13 @@ def load_config(self, filepath: str) -> Dict[str, Any]: logging.info('loading INI configuration file') try: self.__config_parser.read([filepath], encoding=self.encoding) - except Exception: + except Error: logging.error('Unable to read file') + + # pylint: disable-next=protected-access data = self.__config_parser._sections # type: ignore + + # pylint: disable-next=protected-access for k, v in self.__config_parser._defaults.items(): # type: ignore data[k] = v return data diff --git a/src/compendium/filetypes/json.py b/src/compendium/filetypes/json.py index b2c7b2c..dbe2bec 100644 --- a/src/compendium/filetypes/json.py +++ b/src/compendium/filetypes/json.py @@ -46,7 +46,7 @@ def dump_config(self, content: Dict[str, Any], filepath: str) -> None: content, file, indent=2, - sort_keys=False + sort_keys=False, # , default=self.encoder ) except IOError as err: diff --git a/src/compendium/filetypes/xml.py b/src/compendium/filetypes/xml.py index 8131fb9..4e9cdcc 100644 --- a/src/compendium/filetypes/xml.py +++ b/src/compendium/filetypes/xml.py @@ -8,7 +8,7 @@ import os from typing import Any, Dict, Tuple -import xmltodict +import xmltodict # pylint: disable=import-error from compendium.filetypes import FiletypesBase