From cede24e0637c2f2df33af756c0506bb6cb9d19f8 Mon Sep 17 00:00:00 2001 From: Dzmitry Pryskoka Date: Tue, 30 Jul 2024 20:02:18 +0300 Subject: [PATCH] Update ruff; enable more rules --- .github/workflows/run-tests.yml | 6 ++--- pyproject.toml | 25 +++++++++++++------ src/kataloger/catalog_updater.py | 2 +- src/kataloger/cli/argument_parser.py | 2 +- src/kataloger/cli/configuration_provider.py | 10 ++++---- src/kataloger/cli/update_print_helper.py | 4 +-- src/kataloger/helpers/path_helpers.py | 2 +- src/kataloger/helpers/toml_parse_helpers.py | 22 ++++++++-------- src/kataloger/helpers/update_helpers.py | 8 ++---- .../universal/universal_version.py | 8 +----- 10 files changed, 44 insertions(+), 45 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 42d19a5..57fccde 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,12 +12,12 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 with: - python-version: 3.12 + python-version: 3.13 - name: Install ruff run: | python -m pip install --upgrade pip - pip install ruff==0.3.4 + pip install ruff==0.5.5 - name: Run ruff check run: ruff check --output-format=github @@ -37,7 +37,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 with: - python-version: 3.11 + python-version: 3.13 - name: Install dependencies run: | diff --git a/pyproject.toml b/pyproject.toml index aff58da..ed90f78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,26 +49,35 @@ pythonpath = "src/" line-length = 120 indent-width = 4 target-version = "py38" +required-version = ">=0.5.5" +output-format = "concise" src = ["src", "tests"] [tool.ruff.lint] select = [ - "E", # pycodestyle errors - "W", # pycodestyle warnings - "F", # pyflakes - "I", # isort - "B", # flake8-bugbear + "F", # pyflakes + "E", # pycodestyle errors + "W", # pycodestyle warnings + "I", # isort + "UP", # pyupgrade + "YTT", # flake8-2020 "ANN", # flake8-annotations + "B", # flake8-bugbear + "A", # flake8-builtins "COM", # flake8-commas - "C4", # flake8-comprehensions - "EM", # flake8-errmsg - "UP", # pyupgrade + "C4", # flake8-comprehensions + "EM", # flake8-errmsg + "ISC", # flake8-implicit-str-concat + "PIE", # flake8-pie "PYI", # flake8-pyi "PT", # flake8-pytest-style + "Q", # flake8-quotes + "RSE", # flake8-raise "RET", # flake8-return "SIM", # flake8-simplify "ARG", # flake8-unused-arguments "PTH", # flake8-use-pathlib + "PERF", # perflint ] ignore = [ "ANN101", # will be deprecated diff --git a/src/kataloger/catalog_updater.py b/src/kataloger/catalog_updater.py index b725ca0..4bcfbab 100644 --- a/src/kataloger/catalog_updater.py +++ b/src/kataloger/catalog_updater.py @@ -40,7 +40,7 @@ async def get_catalog_updates(self, catalog_path: Path) -> List[ArtifactUpdate]: libraries, plugins = load_catalog(catalog_path, self.verbose) if not (libraries or plugins): if self.verbose: - log_warning(f"Catalog \"{catalog_path.name}\" is empty.") + log_warning(f'Catalog "{catalog_path.name}" is empty.') return [] library_updates, plugin_updates = await self.get_updates(libraries, plugins) diff --git a/src/kataloger/cli/argument_parser.py b/src/kataloger/cli/argument_parser.py index 60ef4dc..d0a137a 100644 --- a/src/kataloger/cli/argument_parser.py +++ b/src/kataloger/cli/argument_parser.py @@ -74,7 +74,7 @@ def parse_arguments(*args: str) -> KatalogerArguments: def _get_kataloger_version() -> str: - if __name__ == '__main__': + if __name__ == "__main__": return "indev" return version(package_name) diff --git a/src/kataloger/cli/configuration_provider.py b/src/kataloger/cli/configuration_provider.py index 5ed8009..2ec423f 100644 --- a/src/kataloger/cli/configuration_provider.py +++ b/src/kataloger/cli/configuration_provider.py @@ -71,9 +71,9 @@ def get_catalogs(arg_catalogs: Optional[List[Catalog]], conf_catalogs: Optional[ if cwd_catalogs: return cwd_catalogs - message = "Gradle version catalog not found in current directory. " \ - "Please specify path to catalog via parameter, in configuration " \ - "file or run tool from directory with catalog (*.versions.toml) file." + message = ("Gradle version catalog not found in current directory. " + "Please specify path to catalog via parameter, in configuration " + "file or run tool from directory with catalog (*.versions.toml) file.") raise KatalogerConfigurationException(message) @@ -95,8 +95,8 @@ def get_repositories( plugin_repositories = conf_plugin_repositories if conf_plugin_repositories is not None else [] return library_repositories, plugin_repositories - message = "No repositories provided! You can specify repositories to " \ - "search artifact updates through configuration file." + message = ("No repositories provided! You can specify repositories to " + "search artifact updates through configuration file.") raise KatalogerConfigurationException(message) diff --git a/src/kataloger/cli/update_print_helper.py b/src/kataloger/cli/update_print_helper.py index d429d88..b1c0ff2 100644 --- a/src/kataloger/cli/update_print_helper.py +++ b/src/kataloger/cli/update_print_helper.py @@ -11,9 +11,9 @@ def print_catalog_updates( ) -> None: if catalog_count > 1: if updates: - print(f"Updates for \"{catalog_name}\" catalog:") + print(f'Updates for "{catalog_name}" catalog:') else: - print(f"Catalog \"{catalog_name}\" is up to date!") + print(f'Catalog "{catalog_name}" is up to date!') for update in updates: version_part = f"{update.current_version} -> {update.available_version}" diff --git a/src/kataloger/helpers/path_helpers.py b/src/kataloger/helpers/path_helpers.py index 50aa092..e46d11b 100644 --- a/src/kataloger/helpers/path_helpers.py +++ b/src/kataloger/helpers/path_helpers.py @@ -19,7 +19,7 @@ def str_to_path(path_string: str, root_path: Optional[Path] = None) -> Path: path = (root_path / path).resolve() if not file_exists(path): - raise KatalogerConfigurationException(message=f"Incorrect path: \"{path_string}\".") + raise KatalogerConfigurationException(message=f'Incorrect path: "{path_string}".') return path diff --git a/src/kataloger/helpers/toml_parse_helpers.py b/src/kataloger/helpers/toml_parse_helpers.py index 3704b46..0bbf323 100644 --- a/src/kataloger/helpers/toml_parse_helpers.py +++ b/src/kataloger/helpers/toml_parse_helpers.py @@ -77,7 +77,7 @@ def parse_catalogs(data: Union[List, Dict], configuration_root_dir: Optional[Pat if isinstance(data, list): for path in data: if not isinstance(path, str): - raise KatalogerParseException(message=f"Unexpected catalog path: \"{path}\".") + raise KatalogerParseException(message=f'Unexpected catalog path: "{path}".') if not path.strip(): raise KatalogerParseException(message="Catalog path can't be empty!") @@ -87,18 +87,18 @@ def parse_catalogs(data: Union[List, Dict], configuration_root_dir: Optional[Pat if isinstance(data, dict): for name, path in data.items(): if not isinstance(name, str): - raise KatalogerParseException(message=f"Unexpected catalog name: \"{name}\".") + raise KatalogerParseException(message=f'Unexpected catalog name: "{name}".') if not isinstance(path, str): - raise KatalogerParseException(message=f"Unexpected catalog path: \"{path}\".") + raise KatalogerParseException(message=f'Unexpected catalog path: "{path}".') if not name.strip(): raise KatalogerParseException(message="Catalog name can't be empty!") if not path.strip(): - raise KatalogerParseException(message=f"Catalog \"{name}\" has empty path!") + raise KatalogerParseException(message=f'Catalog "{name}" has empty path!') catalogs.append(Catalog(name=name, path=str_to_path(path, root_path=configuration_root_dir))) return catalogs - raise KatalogerParseException(message=f"Unexpected catalogs data format: \"{data}\".") + raise KatalogerParseException(message=f'Unexpected catalogs data format: "{data}".') def parse_libraries(catalog: Dict[str, Union[Dict, str]], versions: Dict, verbose: bool) -> List[Library]: @@ -146,7 +146,7 @@ def parse_libraries(catalog: Dict[str, Union[Dict, str]], versions: Dict, verbos libraries.append(library) case {"module": str(module)}: if verbose: - log_warning(f"Library \"{module}\" has no version in catalog.") + log_warning(f'Library "{module}" has no version in catalog.') case _: message = f"Unknown library notation: {library}" raise KatalogerParseException(message) @@ -185,7 +185,7 @@ def parse_plugins(catalog: Dict[str, Union[Dict, str]], versions: Dict, verbose: plugins.append(plugin) case {"id": str(plugin_id)}: if verbose: - log_warning(f"Plugin \"{plugin_id}\" has no version in catalog.") + log_warning(f'Plugin "{plugin_id}" has no version in catalog.') case _: message = f"Unknown plugin notation: {plugin}" raise KatalogerParseException(message) @@ -194,9 +194,9 @@ def parse_plugins(catalog: Dict[str, Union[Dict, str]], versions: Dict, verbose: def __parse_declaration(declaration: str) -> Tuple[str, str]: - components = declaration.rsplit(':', 1) + components = declaration.rsplit(":", 1) if len(components) != 2 or not (components[0].strip() and components[1].strip()): - message = f"Unknown declaration format: \"{declaration}\"." + message = f'Unknown declaration format: "{declaration}".' raise KatalogerParseException(message) return components[0], components[1] @@ -207,7 +207,7 @@ def __get_version_by_reference( artifact_name: str, ) -> str: if not (version := versions.get(version_ref)): - message = f"Version for \"{artifact_name}\" not specified by reference \"{version_ref}\"." + message = f'Version for "{artifact_name}" not specified by reference "{version_ref}".' raise KatalogerParseException(message) return version @@ -218,7 +218,7 @@ def __extract_optional_boolean(data: Dict, key: str) -> Optional[bool]: if value is None or isinstance(value, bool): return value - message = f"Configuration field \"{key}\" has incorrect value \"{value}\", while expected boolean type." + message = f'Configuration field "{key}" has incorrect value "{value}", while expected boolean type.' raise KatalogerParseException(message) diff --git a/src/kataloger/helpers/update_helpers.py b/src/kataloger/helpers/update_helpers.py index de40ae4..3c764b7 100644 --- a/src/kataloger/helpers/update_helpers.py +++ b/src/kataloger/helpers/update_helpers.py @@ -19,7 +19,7 @@ async def get_all_artifact_metadata( if not artifacts: return {} - search_results: Dict[Artifact, List[MetadataRepositoryInfo]] = defaultdict(lambda: []) + search_results: Dict[Artifact, List[MetadataRepositoryInfo]] = defaultdict(list) for repository in repositories: result = await get_all_artifact_metadata_in_repository(repository, artifacts, verbose) for artifact, metadata in result.items(): @@ -44,11 +44,7 @@ async def get_all_artifact_metadata_in_repository( requests.append(request) results = await asyncio.gather(*requests) - artifact_to_metadata: Dict[Artifact, MetadataRepositoryInfo] = {} - for artifact, metadata in zip(artifacts, results): - if metadata: - artifact_to_metadata[artifact] = metadata - return artifact_to_metadata + return {artifact: metadata for artifact, metadata in zip(artifacts, results) if metadata} async def get_artifact_metadata( diff --git a/src/kataloger/update_resolver/universal/universal_version.py b/src/kataloger/update_resolver/universal/universal_version.py index b6f297c..f4cb39e 100644 --- a/src/kataloger/update_resolver/universal/universal_version.py +++ b/src/kataloger/update_resolver/universal/universal_version.py @@ -67,13 +67,7 @@ def to_digits_list(version_part: str) -> List[int]: return False return False - if not self.is_pre_release() and other.is_pre_release(): - return False - - if self.is_pre_release() and not other.is_pre_release(): - return True - - return False + return self.is_pre_release() and not other.is_pre_release() def _pre_release_index(self) -> int: lowercase_pre_release_name = self.pre_release_name.lower()