mirror of
https://github.com/p2p-ld/nwb-linkml.git
synced 2024-11-10 00:34: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
|
from nwb_linkml.monkeypatch import apply_patches
|
||||||
|
|
||||||
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.adapter import Adapter, BuildResult
|
||||||
from nwb_linkml.adapters.classes import ClassAdapter
|
from nwb_linkml.adapters.classes import ClassAdapter
|
||||||
from nwb_linkml.adapters.dataset import DatasetAdapter
|
from nwb_linkml.adapters.dataset import DatasetAdapter
|
||||||
from nwb_linkml.adapters.group import GroupAdapter
|
from nwb_linkml.adapters.group import GroupAdapter
|
||||||
from nwb_linkml.adapters.namespaces import NamespacesAdapter
|
from nwb_linkml.adapters.namespaces import NamespacesAdapter
|
||||||
from nwb_linkml.adapters.schema import SchemaAdapter
|
from nwb_linkml.adapters.schema import SchemaAdapter
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"Adapter",
|
||||||
|
"BuildResult",
|
||||||
|
"ClassAdapter",
|
||||||
|
"DatasetAdapter",
|
||||||
|
"GroupAdapter",
|
||||||
|
"NamespacesAdapter",
|
||||||
|
"SchemaAdapter",
|
||||||
|
]
|
||||||
|
|
|
@ -13,11 +13,13 @@ from typing import (
|
||||||
Type,
|
Type,
|
||||||
TypeVar,
|
TypeVar,
|
||||||
TypeVarTuple,
|
TypeVarTuple,
|
||||||
|
Union,
|
||||||
Unpack,
|
Unpack,
|
||||||
)
|
)
|
||||||
|
|
||||||
from linkml_runtime.linkml_model import (
|
from linkml_runtime.linkml_model import (
|
||||||
ClassDefinition,
|
ClassDefinition,
|
||||||
|
Definition,
|
||||||
SchemaDefinition,
|
SchemaDefinition,
|
||||||
SlotDefinition,
|
SlotDefinition,
|
||||||
TypeDefinition,
|
TypeDefinition,
|
||||||
|
@ -26,11 +28,15 @@ from pydantic import BaseModel
|
||||||
|
|
||||||
from nwb_schema_language import Attribute, Dataset, Group, Schema
|
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
|
@dataclass
|
||||||
class BuildResult:
|
class BuildResult:
|
||||||
|
"""
|
||||||
|
Container class for propagating nested build results back up to caller
|
||||||
|
"""
|
||||||
# pass
|
# pass
|
||||||
schemas: List[SchemaDefinition] = field(default_factory=list)
|
schemas: List[SchemaDefinition] = field(default_factory=list)
|
||||||
classes: List[ClassDefinition] = field(default_factory=list)
|
classes: List[ClassDefinition] = field(default_factory=list)
|
||||||
|
@ -38,12 +44,12 @@ class BuildResult:
|
||||||
types: List[TypeDefinition] = field(default_factory=list)
|
types: List[TypeDefinition] = field(default_factory=list)
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
for field in ("schemas", "classes", "slots", "types"):
|
for a_field in ("schemas", "classes", "slots", "types"):
|
||||||
attr = getattr(self, field)
|
attr = getattr(self, a_field)
|
||||||
if not isinstance(attr, list):
|
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]
|
existing_names = [c.name for c in ours]
|
||||||
others_dedupe = [o for o in others if o.name not in existing_names]
|
others_dedupe = [o for o in others if o.name not in existing_names]
|
||||||
return others_dedupe
|
return others_dedupe
|
||||||
|
@ -80,11 +86,9 @@ class BuildResult:
|
||||||
return out_str
|
return out_str
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar("T", Dataset, Attribute, Schema, Group, BaseModel)
|
|
||||||
Ts = TypeVarTuple("Ts")
|
|
||||||
|
|
||||||
|
|
||||||
class Adapter(BaseModel):
|
class Adapter(BaseModel):
|
||||||
|
"""Abstract base class for adapters"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def build(self) -> "BuildResult":
|
def build(self) -> "BuildResult":
|
||||||
"""
|
"""
|
||||||
|
@ -101,7 +105,7 @@ class Adapter(BaseModel):
|
||||||
yield input
|
yield input
|
||||||
if isinstance(input, BaseModel):
|
if isinstance(input, BaseModel):
|
||||||
|
|
||||||
for key in input.model_fields.keys():
|
for key in input.model_fields:
|
||||||
# Special case where SchemaAdapter Imports are themselves
|
# Special case where SchemaAdapter Imports are themselves
|
||||||
# SchemaAdapters that should be located under the same
|
# SchemaAdapters that should be located under the same
|
||||||
# NamespacesAdapter when it's important to query across SchemaAdapters,
|
# NamespacesAdapter when it's important to query across SchemaAdapters,
|
||||||
|
|
|
@ -49,9 +49,9 @@ select = [
|
||||||
## ----------
|
## ----------
|
||||||
# pydocstyle
|
# pydocstyle
|
||||||
# undocumented public objects
|
# undocumented public objects
|
||||||
"D100", "D101", "D102", "D103", "D104", "D106", "D107",
|
"D100", "D101", "D102", "D103", "D104", "D106",
|
||||||
# indentation
|
# indentation
|
||||||
"D207", "D208",
|
"D207", "D208", "D209",
|
||||||
# whitespace
|
# whitespace
|
||||||
"D210", "D211",
|
"D210", "D211",
|
||||||
# emptiness
|
# emptiness
|
||||||
|
@ -65,12 +65,13 @@ ignore = [
|
||||||
"UP006", "UP035",
|
"UP006", "UP035",
|
||||||
# | for Union types (only supported >=3.10
|
# | for Union types (only supported >=3.10
|
||||||
"UP007", "UP038",
|
"UP007", "UP038",
|
||||||
# docstrings for __init__
|
|
||||||
"D107",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
fixable = ["ALL"]
|
fixable = ["ALL"]
|
||||||
|
|
||||||
|
[tool.ruff.lint.per-file-ignores]
|
||||||
|
"**/tests/**.py" = ["D", "ANN"]
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
plugins = [
|
plugins = [
|
||||||
"pydantic.mypy"
|
"pydantic.mypy"
|
||||||
|
@ -86,5 +87,6 @@ warn_unreachable = true
|
||||||
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
target-version = ['py38', 'py39', 'py310', 'py311']
|
target-version = ['py38', 'py39', 'py310', 'py311']
|
||||||
|
enable-unstable-feature = ["string_processing"]
|
||||||
include = "nwb_linkml/.*\\.py$|nwb_schema_language/.*\\.py$"
|
include = "nwb_linkml/.*\\.py$|nwb_schema_language/.*\\.py$"
|
||||||
line-length = 100
|
line-length = 100
|
Loading…
Reference in a new issue