From 2efab99c0d7bd1aab81a619cd4cab95af1beecca Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Fri, 21 Jun 2024 13:49:10 +0200 Subject: [PATCH] acacore - format and lint with ruff --- acacore/database/base.py | 40 +++++++++++-------------------- acacore/database/column.py | 4 ++-- acacore/models/file.py | 2 +- acacore/models/reference_files.py | 1 + acacore/siegfried/siegfried.py | 4 ++-- acacore/utils/log.py | 6 ++--- tests/linting.py | 18 +++++++------- 7 files changed, 31 insertions(+), 44 deletions(-) diff --git a/acacore/database/base.py b/acacore/database/base.py index 1b9ffc7..d6c9dc2 100644 --- a/acacore/database/base.py +++ b/acacore/database/base.py @@ -76,12 +76,10 @@ def fetchonetuple(self) -> tuple | None: return tuple(c.from_entry(v) for c, v in zip(self.columns, vs)) if vs else None @overload - def fetchall(self) -> Generator[dict[str, Any], None, None]: - ... + def fetchall(self) -> Generator[dict[str, Any], None, None]: ... @overload - def fetchall(self, model: Type[M]) -> Generator[M, None, None]: - ... + def fetchall(self, model: Type[M]) -> Generator[M, None, None]: ... def fetchall(self, model: Type[M] | None = None) -> Generator[dict[str, Any] | M, None, None]: """ @@ -103,12 +101,10 @@ def fetchall(self, model: Type[M] | None = None) -> Generator[dict[str, Any] | M return ({c.alias or c.name: c.from_entry(v) for c, v in zip(select_columns, vs)} for vs in self.cursor) @overload - def fetchmany(self, size: int) -> Generator[dict[str, Any], None, None]: - ... + def fetchmany(self, size: int) -> Generator[dict[str, Any], None, None]: ... @overload - def fetchmany(self, size: int, model: Type[M]) -> Generator[M, None, None]: - ... + def fetchmany(self, size: int, model: Type[M]) -> Generator[M, None, None]: ... def fetchmany(self, size: int, model: Type[M] | None = None) -> Generator[dict[str, Any] | M, None, None]: """ @@ -134,12 +130,10 @@ def fetchmany(self, size: int, model: Type[M] | None = None) -> Generator[dict[s ) @overload - def fetchone(self) -> dict[str, Any] | None: - ... + def fetchone(self) -> dict[str, Any] | None: ... @overload - def fetchone(self, model: Type[M]) -> M | None: - ... + def fetchone(self, model: Type[M]) -> M | None: ... def fetchone(self, model: Type[M] | None = None) -> dict[str, Any] | M | None: """ @@ -232,7 +226,7 @@ def __init__( :param columns: The columns of the table. :param indices: The indices to create in the table, defaults to None. """ - self.connection: "FileDBBase" = connection + self.connection: FileDBBase = connection self.name: str = name self.columns: list[Column] = columns self.indices: list[Index] = indices or [] @@ -526,7 +520,7 @@ def __init__(self, connection: "FileDBBase", name: str, keys: list[Column]) -> N :param keys: The keys of the table. """ self.keys: list[Column] = keys - self.connection: "FileDBBase" = connection + self.connection: FileDBBase = connection self.name: str = name self.columns: list[Column] = [ Column("KEY", "text", str, str, True, True), @@ -886,12 +880,10 @@ def is_open(self) -> bool: return False @overload - def create_table(self, name: str, columns: Type[M], indices: list[Index] | None = None) -> ModelTable[M]: - ... + def create_table(self, name: str, columns: Type[M], indices: list[Index] | None = None) -> ModelTable[M]: ... @overload - def create_table(self, name: str, columns: list[Column], indices: list[Index] | None = None) -> Table: - ... + def create_table(self, name: str, columns: list[Column], indices: list[Index] | None = None) -> Table: ... def create_table( self, @@ -914,12 +906,10 @@ def create_table( return Table(self, name, columns, indices) @overload - def create_keys_table(self, name: str, columns: Type[M]) -> ModelKeysTable[M]: - ... + def create_keys_table(self, name: str, columns: Type[M]) -> ModelKeysTable[M]: ... @overload - def create_keys_table(self, name: str, columns: list[Column]) -> KeysTable: - ... + def create_keys_table(self, name: str, columns: list[Column]) -> KeysTable: ... def create_keys_table(self, name: str, columns: Type[M] | list[Column]) -> KeysTable | ModelKeysTable[M]: """ @@ -948,8 +938,7 @@ def create_view( joins: list[str] | None = None, *, select_columns: list[Column | SelectColumn] | None = None, - ) -> ModelView[M]: - ... + ) -> ModelView[M]: ... @overload def create_view( @@ -962,8 +951,7 @@ def create_view( order_by: list[tuple[str | Column, str]] | None = None, limit: int | None = None, joins: list[str] | None = None, - ) -> View: - ... + ) -> View: ... def create_view( self, diff --git a/acacore/database/column.py b/acacore/database/column.py index 3a68813..142396d 100644 --- a/acacore/database/column.py +++ b/acacore/database/column.py @@ -232,7 +232,7 @@ def _schema_to_column(name: str, schema: dict, defs: dict[str, dict] | None = No defs = defs or {} if schema.get("$ref"): schema.update(defs[schema.get("$ref", "").removeprefix("#/$defs/")]) - schema_type: str | None = schema.get("type", None) + schema_type: str | None = schema.get("type") schema_any_of: list[dict] = schema.get("anyOf", []) sql_type: str @@ -241,7 +241,7 @@ def _schema_to_column(name: str, schema: dict, defs: dict[str, dict] | None = No not_null: bool = (schema_any_of or [{}])[-1].get("type", None) != "null" if schema_type: - sql_type = _sql_schema_types.get(schema_type, None) + sql_type = _sql_schema_types.get(schema_type) type_name: str = schema.get("format", schema_type) if schema.get("enum") is not None: diff --git a/acacore/models/file.py b/acacore/models/file.py index 8ae6ef7..17b9498 100644 --- a/acacore/models/file.py +++ b/acacore/models/file.py @@ -266,7 +266,7 @@ def get_action( if not self.size: identifiers.insert(0, "!empty") - action: Action | None = reduce(lambda acc, cur: acc or actions.get(cur, None), identifiers, None) + action: Action | None = reduce(lambda acc, cur: acc or actions.get(cur), identifiers, None) if set_match: self.action, self.action_data = action.action if action else None, action.action_data if action else None diff --git a/acacore/models/reference_files.py b/acacore/models/reference_files.py index 9387505..4e0630e 100644 --- a/acacore/models/reference_files.py +++ b/acacore/models/reference_files.py @@ -1,4 +1,5 @@ """Data models for the data on saved to different .json files on the `reference_files` repo.""" + from typing import get_args as get_type_args from typing import Literal diff --git a/acacore/siegfried/siegfried.py b/acacore/siegfried/siegfried.py index 24ebedd..a981ca2 100644 --- a/acacore/siegfried/siegfried.py +++ b/acacore/siegfried/siegfried.py @@ -83,8 +83,8 @@ class SiegfriedMatch(BaseModel): """ ns: str - id: str | None # noqa: A003 - format: str # noqa: A003 + id: str | None + format: str version: str | None = None mime: str match_class: list[TSiegfriedFileClass] | None = Field(None, alias="class") diff --git a/acacore/utils/log.py b/acacore/utils/log.py index c2eba26..c772500 100644 --- a/acacore/utils/log.py +++ b/acacore/utils/log.py @@ -10,13 +10,11 @@ @overload -def setup_logger(log_name: str, *, files: list[Path], streams: list[IO] | None = None) -> Logger: - ... +def setup_logger(log_name: str, *, files: list[Path], streams: list[IO] | None = None) -> Logger: ... @overload -def setup_logger(log_name: str, *, files: list[Path] | None = None, streams: list[IO]) -> Logger: - ... +def setup_logger(log_name: str, *, files: list[Path] | None = None, streams: list[IO]) -> Logger: ... def setup_logger(log_name: str, *, files: list[Path] | None = None, streams: list[IO] | None = None) -> Logger: diff --git a/tests/linting.py b/tests/linting.py index 267ba46..976bcdb 100644 --- a/tests/linting.py +++ b/tests/linting.py @@ -4,17 +4,17 @@ from acacore import __file__ as acacore_init_file -def test_black(test_folder: Path): - completed_process = subprocess.run( - ["poetry", "run", "black", "--check", str(Path(acacore_init_file).parent)], - check=False, - ) - assert completed_process.returncode == 0 - - def test_ruff(test_folder: Path): completed_process = subprocess.run( - ["poetry", "run", "ruff", "check", str(Path(acacore_init_file).parent)], + [ + "poetry", + "run", + "ruff", + "check", + "--config", + str(test_folder.parent / "pyproject.toml"), + str(Path(acacore_init_file).parent), + ], check=False, ) assert completed_process.returncode == 0