Skip to content

Commit

Permalink
Update ruff; enable more rules
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmpr committed Jul 30, 2024
1 parent c3eaff1 commit cede24e
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 45 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand Down
25 changes: 17 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/kataloger/catalog_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/kataloger/cli/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions src/kataloger/cli/configuration_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions src/kataloger/cli/update_print_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion src/kataloger/helpers/path_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 11 additions & 11 deletions src/kataloger/helpers/toml_parse_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")

Expand All @@ -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]:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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]

Expand All @@ -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
Expand All @@ -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)


Expand Down
8 changes: 2 additions & 6 deletions src/kataloger/helpers/update_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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(
Expand Down
8 changes: 1 addition & 7 deletions src/kataloger/update_resolver/universal/universal_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit cede24e

Please sign in to comment.