Skip to content

Commit

Permalink
acacore - format and lint with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoCampinoti94 committed Jun 21, 2024
1 parent 16b4e15 commit 2efab99
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 44 deletions.
40 changes: 14 additions & 26 deletions acacore/database/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand All @@ -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]:
"""
Expand All @@ -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:
"""
Expand Down Expand Up @@ -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 []
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand All @@ -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]:
"""
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions acacore/database/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion acacore/models/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions acacore/models/reference_files.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions acacore/siegfried/siegfried.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 2 additions & 4 deletions acacore/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 9 additions & 9 deletions tests/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2efab99

Please sign in to comment.