From d4a0c82d002e76c0aac45f13a985aeeea0bea293 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Mon, 1 Jul 2024 22:09:49 -0700 Subject: [PATCH] some ruff fixes --- nwb_linkml/src/nwb_linkml/__init__.py | 9 ++++++- .../src/nwb_linkml/adapters/__init__.py | 14 ++++++++++ nwb_linkml/src/nwb_linkml/adapters/adapter.py | 26 +++++++++++-------- nwb_linkml/{ => tests}/conftest.py | 0 pyproject.toml | 10 ++++--- 5 files changed, 43 insertions(+), 16 deletions(-) rename nwb_linkml/{ => tests}/conftest.py (100%) diff --git a/nwb_linkml/src/nwb_linkml/__init__.py b/nwb_linkml/src/nwb_linkml/__init__.py index 1b76aaf..ace1adc 100644 --- a/nwb_linkml/src/nwb_linkml/__init__.py +++ b/nwb_linkml/src/nwb_linkml/__init__.py @@ -1,5 +1,12 @@ +""" +NWB in LinkML +""" from nwb_linkml.monkeypatch import apply_patches apply_patches() -from nwb_linkml.config import Config +from nwb_linkml.config import Config # noqa: E402 + +__all__ = [ + "Config" +] diff --git a/nwb_linkml/src/nwb_linkml/adapters/__init__.py b/nwb_linkml/src/nwb_linkml/adapters/__init__.py index 9c2a1ac..db1da1f 100644 --- a/nwb_linkml/src/nwb_linkml/adapters/__init__.py +++ b/nwb_linkml/src/nwb_linkml/adapters/__init__.py @@ -1,6 +1,20 @@ +""" +Adapter classes for translating from NWB schema language to LinkML +""" + from nwb_linkml.adapters.adapter import Adapter, BuildResult from nwb_linkml.adapters.classes import ClassAdapter from nwb_linkml.adapters.dataset import DatasetAdapter from nwb_linkml.adapters.group import GroupAdapter from nwb_linkml.adapters.namespaces import NamespacesAdapter from nwb_linkml.adapters.schema import SchemaAdapter + +__all__ = [ + "Adapter", + "BuildResult", + "ClassAdapter", + "DatasetAdapter", + "GroupAdapter", + "NamespacesAdapter", + "SchemaAdapter", +] diff --git a/nwb_linkml/src/nwb_linkml/adapters/adapter.py b/nwb_linkml/src/nwb_linkml/adapters/adapter.py index fd68fba..b4b2641 100644 --- a/nwb_linkml/src/nwb_linkml/adapters/adapter.py +++ b/nwb_linkml/src/nwb_linkml/adapters/adapter.py @@ -13,11 +13,13 @@ from typing import ( Type, TypeVar, TypeVarTuple, + Union, Unpack, ) from linkml_runtime.linkml_model import ( ClassDefinition, + Definition, SchemaDefinition, SlotDefinition, TypeDefinition, @@ -26,11 +28,15 @@ from pydantic import BaseModel from nwb_schema_language import Attribute, Dataset, Group, Schema -# SchemaDefClass = dataclass(SchemaDefinition).__pydantic_model__ - +T = TypeVar("T", Dataset, Attribute, Schema, Group, BaseModel) +Ts = TypeVarTuple("Ts") +Td = TypeVar('Td', bound=Union[Definition,SchemaDefinition,TypeDefinition]) @dataclass class BuildResult: + """ + Container class for propagating nested build results back up to caller + """ # pass schemas: List[SchemaDefinition] = field(default_factory=list) classes: List[ClassDefinition] = field(default_factory=list) @@ -38,12 +44,12 @@ class BuildResult: types: List[TypeDefinition] = field(default_factory=list) def __post_init__(self): - for field in ("schemas", "classes", "slots", "types"): - attr = getattr(self, field) + for a_field in ("schemas", "classes", "slots", "types"): + attr = getattr(self, a_field) if not isinstance(attr, list): - setattr(self, field, [attr]) + setattr(self, a_field, [attr]) - def _dedupe(self, ours, others): + def _dedupe(self, ours: List[Td], others: List[Td]) -> List[Td]: existing_names = [c.name for c in ours] others_dedupe = [o for o in others if o.name not in existing_names] return others_dedupe @@ -80,11 +86,9 @@ class BuildResult: return out_str -T = TypeVar("T", Dataset, Attribute, Schema, Group, BaseModel) -Ts = TypeVarTuple("Ts") - - class Adapter(BaseModel): + """Abstract base class for adapters""" + @abstractmethod def build(self) -> "BuildResult": """ @@ -101,7 +105,7 @@ class Adapter(BaseModel): yield input if isinstance(input, BaseModel): - for key in input.model_fields.keys(): + for key in input.model_fields: # Special case where SchemaAdapter Imports are themselves # SchemaAdapters that should be located under the same # NamespacesAdapter when it's important to query across SchemaAdapters, diff --git a/nwb_linkml/conftest.py b/nwb_linkml/tests/conftest.py similarity index 100% rename from nwb_linkml/conftest.py rename to nwb_linkml/tests/conftest.py diff --git a/pyproject.toml b/pyproject.toml index 287c4f2..0d7a7e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,9 +49,9 @@ select = [ ## ---------- # pydocstyle # undocumented public objects - "D100", "D101", "D102", "D103", "D104", "D106", "D107", + "D100", "D101", "D102", "D103", "D104", "D106", # indentation - "D207", "D208", + "D207", "D208", "D209", # whitespace "D210", "D211", # emptiness @@ -65,12 +65,13 @@ ignore = [ "UP006", "UP035", # | for Union types (only supported >=3.10 "UP007", "UP038", - # docstrings for __init__ - "D107", ] fixable = ["ALL"] +[tool.ruff.lint.per-file-ignores] +"**/tests/**.py" = ["D", "ANN"] + [tool.mypy] plugins = [ "pydantic.mypy" @@ -86,5 +87,6 @@ warn_unreachable = true [tool.black] target-version = ['py38', 'py39', 'py310', 'py311'] +enable-unstable-feature = ["string_processing"] include = "nwb_linkml/.*\\.py$|nwb_schema_language/.*\\.py$" line-length = 100 \ No newline at end of file