mirror of
https://github.com/p2p-ld/nwb-linkml.git
synced 2024-11-12 17:54:29 +00:00
some ruff fixes
This commit is contained in:
parent
07aa879bb9
commit
d4a0c82d00
5 changed files with 43 additions and 16 deletions
|
@ -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"
|
||||
]
|
||||
|
|
|
@ -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",
|
||||
]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue