Skip to content

Commit

Permalink
refactor: apply new lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-v4s committed Oct 25, 2024
1 parent 15d263c commit 32368d7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 46 deletions.
39 changes: 20 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ exclude = ['tests/']
module = [
"jsonpatch",
"jsonpointer",
"qualibrate",
"qualibrate_app.*",
"qualibrate_runner.*",
"json_timeline_database.*",
Expand All @@ -58,13 +57,25 @@ ignore_missing_imports = true

[tool.ruff]
line-length = 80
extend-select = ["I"]
target-version = "py39"

[tool.ruff.lint]
select = [
"E", # pycodestyle
"F", # Pyflakes
"UP", # pyupgrade
"B", # flake8-bugbear
"SIM", # flake8-simplify
"I", # isort
]

[tool.ruff.lint.pycodestyle]
max-line-length = 80
max-doc-length = 80

[tool.poe.tasks]
lint = "ruff ."
lint-fix = "ruff --fix ."
lint = "ruff check ."
lint-fix = "ruff check --fix ."
format = "ruff format --check ."
format-fix = "ruff format ."
type = "mypy ."
Expand Down
36 changes: 18 additions & 18 deletions qualibrate_composite/cli/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import sys
from collections.abc import Mapping
from importlib.util import find_spec
from itertools import filterfalse
from pathlib import Path
from typing import Any, Dict, Mapping, Optional
from typing import Any, Optional

import click
import tomli_w
Expand Down Expand Up @@ -67,7 +68,6 @@
QualibrateRunnerSettings,
)


__all__ = ["config_command"]


Expand Down Expand Up @@ -105,28 +105,28 @@ def _qualibrate_config_from_sources(
}
for arg_key, arg_value in ctx.params.items():
not_default_arg = not_default(ctx, arg_key)
if arg_key in qualibrate_composite_mapping.keys():
if arg_key in qualibrate_composite_mapping:
if not_default_arg or (
qualibrate_composite_mapping[arg_key] not in from_file
):
from_file[qualibrate_composite_mapping[arg_key]] = arg_value
elif arg_key in qualibrate_app_mapping.keys():
elif arg_key in qualibrate_app_mapping:
if not_default_arg or (
qualibrate_app_mapping[arg_key] not in from_file["app"]
):
from_file["app"][qualibrate_app_mapping[arg_key]] = arg_value
elif arg_key in timeline_db_mapping.keys():
elif arg_key in timeline_db_mapping:
if not_default_arg or (
timeline_db_mapping[arg_key] not in from_file["timeline_db"]
):
from_file["timeline_db"][
timeline_db_mapping[arg_key]
] = arg_value
elif arg_key in runner_mapping.keys():
if not_default_arg or (
runner_mapping[arg_key] not in from_file["runner"]
):
from_file["runner"][runner_mapping[arg_key]] = arg_value
from_file["timeline_db"][timeline_db_mapping[arg_key]] = (
arg_value
)
elif arg_key in runner_mapping and (
not_default_arg
or (runner_mapping[arg_key] not in from_file["runner"])
):
from_file["runner"][runner_mapping[arg_key]] = arg_value
return from_file


Expand Down Expand Up @@ -169,7 +169,7 @@ def _confirm(config_file: Path, exported_data: dict[str, Any]) -> None:


def _get_runner_config(
ctx: click.Context, from_file: Dict[str, Any]
ctx: click.Context, from_file: dict[str, Any]
) -> QualibrateRunnerSettings:
if qualibrate is None:
raise ImportError("Qualibrate is not installed")
Expand All @@ -190,7 +190,7 @@ def _get_runner_config(


def _get_qapp_config(
ctx: click.Context, qs: QualibrateSettings, from_file: Dict[str, Any]
ctx: click.Context, qs: QualibrateSettings, from_file: dict[str, Any]
) -> QualibrateAppSettingsSetup:
args_mapping = {
"app_static_site_files": "static_site_files",
Expand Down Expand Up @@ -220,7 +220,7 @@ def _get_qapp_config(


def _get_qapp_am_config(
ctx: click.Context, from_file: Dict[str, Any]
ctx: click.Context, from_file: dict[str, Any]
) -> ActiveMachineSettingsSetup:
args_mapping = {"active_machine_path": "path"}
data = {
Expand All @@ -237,7 +237,7 @@ def _get_qapp_am_config(


def _get_qapp_q_config(
ctx: click.Context, from_file: Dict[str, Any]
ctx: click.Context, from_file: dict[str, Any]
) -> QualibrateAppQSettingsSetup:
storage_keys = {
"app_storage_type": "type",
Expand Down Expand Up @@ -268,7 +268,7 @@ def _get_qapp_q_config(
return QualibrateAppQSettingsSetup(**from_file)


def reorder_common_config_entries(data: Dict[str, Any]) -> Dict[str, Any]:
def reorder_common_config_entries(data: dict[str, Any]) -> dict[str, Any]:
sorted_keys = (
QAPP_Q_CONFIG_KEY,
QUALIBRATE_CONFIG_KEY,
Expand Down
11 changes: 6 additions & 5 deletions qualibrate_composite/config/references/resolvers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import defaultdict
from typing import Any, List, Mapping, Optional, Sequence, Set, Tuple, cast
from collections.abc import Mapping, Sequence
from typing import Any, Optional, cast

import jsonpatch
import jsonpointer
Expand All @@ -14,7 +15,7 @@
def find_references_in_str(
to_search: str, config_path: str
) -> Sequence[Reference]:
to_resolve: List[Reference] = []
to_resolve: list[Reference] = []
template_start_index = to_search.find(TEMPLATE_START)
while template_start_index != -1:
template_end_index = to_search.find("}", template_start_index)
Expand Down Expand Up @@ -53,7 +54,7 @@ def find_all_references(

def check_cycles_in_references(
references: Mapping[str, Sequence[str]],
) -> Tuple[bool, Optional[Sequence[str]]]:
) -> tuple[bool, Optional[Sequence[str]]]:
"""Return True if the references has a cycle.
>>> check_cycles_in_references({"a": ("b",), "b": ("c",), "c": ("a",)})
Expand All @@ -62,8 +63,8 @@ def check_cycles_in_references(
(False, None)
"""
path: List[str] = []
visited: Set[str] = set()
path: list[str] = []
visited: set[str] = set()
cycled_item: str = ""

def visit(vertex: str) -> bool:
Expand Down

0 comments on commit 32368d7

Please sign in to comment.