From 3768e3ce0dc3de3e9290f5e25f50837523dd4039 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Mon, 1 Jul 2024 22:12:16 -0700 Subject: [PATCH] enable black preview and automatic linebreaks in long strings --- nwb_linkml/src/nwb_linkml/__init__.py | 5 ++--- nwb_linkml/src/nwb_linkml/adapters/adapter.py | 5 +++-- nwb_linkml/src/nwb_linkml/adapters/dataset.py | 7 +++++-- .../src/nwb_linkml/adapters/namespaces.py | 7 ++++--- nwb_linkml/src/nwb_linkml/adapters/schema.py | 8 ++++++-- .../src/nwb_linkml/generators/pydantic.py | 5 ++++- nwb_linkml/src/nwb_linkml/maps/hdf5.py | 4 +--- nwb_linkml/src/nwb_linkml/providers/git.py | 19 ++++++++++++++----- nwb_linkml/src/nwb_linkml/providers/schema.py | 3 ++- nwb_linkml/tests/fixtures.py | 5 ++++- .../tests/test_adapters/test_adapter.py | 1 - .../test_adapters/test_adapter_classes.py | 1 - .../test_adapters/test_adapter_dataset.py | 4 ---- .../test_adapters/test_adapter_namespaces.py | 1 - nwb_linkml/tests/test_maps/test_hdmf.py | 1 - .../src/nwb_schema_language/__init__.py | 3 ++- .../datamodel/nwb_schema_language.py | 4 +++- pyproject.toml | 1 + 18 files changed, 51 insertions(+), 33 deletions(-) diff --git a/nwb_linkml/src/nwb_linkml/__init__.py b/nwb_linkml/src/nwb_linkml/__init__.py index ace1adc..51a3fed 100644 --- a/nwb_linkml/src/nwb_linkml/__init__.py +++ b/nwb_linkml/src/nwb_linkml/__init__.py @@ -1,12 +1,11 @@ """ NWB in LinkML """ + from nwb_linkml.monkeypatch import apply_patches apply_patches() from nwb_linkml.config import Config # noqa: E402 -__all__ = [ - "Config" -] +__all__ = ["Config"] diff --git a/nwb_linkml/src/nwb_linkml/adapters/adapter.py b/nwb_linkml/src/nwb_linkml/adapters/adapter.py index b4b2641..eaed721 100644 --- a/nwb_linkml/src/nwb_linkml/adapters/adapter.py +++ b/nwb_linkml/src/nwb_linkml/adapters/adapter.py @@ -30,14 +30,15 @@ from nwb_schema_language import Attribute, Dataset, Group, Schema T = TypeVar("T", Dataset, Attribute, Schema, Group, BaseModel) Ts = TypeVarTuple("Ts") -Td = TypeVar('Td', bound=Union[Definition,SchemaDefinition,TypeDefinition]) +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) slots: List[SlotDefinition] = field(default_factory=list) diff --git a/nwb_linkml/src/nwb_linkml/adapters/dataset.py b/nwb_linkml/src/nwb_linkml/adapters/dataset.py index c35f8c8..c3e2bb0 100644 --- a/nwb_linkml/src/nwb_linkml/adapters/dataset.py +++ b/nwb_linkml/src/nwb_linkml/adapters/dataset.py @@ -365,7 +365,8 @@ class DatasetAdapter(ClassAdapter): if len(matches) > 1: # pragma: no cover raise RuntimeError( - f"Only one map should apply to a dataset, you need to refactor the maps! Got maps: {matches}" + "Only one map should apply to a dataset, you need to refactor the maps! Got maps:" + f" {matches}" ) # apply matching maps @@ -412,7 +413,9 @@ def make_arraylike(cls: Dataset, name: Optional[str] = None) -> ClassDefinition: slots = [] for dims, shape in dims_shape: # if there is just a single list of possible dimensions, it's required - if not any([isinstance(inner_dim, list) for inner_dim in cls.dims]) or all([dims in inner_dim for inner_dim in cls.dims]): + if not any([isinstance(inner_dim, list) for inner_dim in cls.dims]) or all( + [dims in inner_dim for inner_dim in cls.dims] + ): required = True else: required = False diff --git a/nwb_linkml/src/nwb_linkml/adapters/namespaces.py b/nwb_linkml/src/nwb_linkml/adapters/namespaces.py index ba38c59..e0f9c6c 100644 --- a/nwb_linkml/src/nwb_linkml/adapters/namespaces.py +++ b/nwb_linkml/src/nwb_linkml/adapters/namespaces.py @@ -5,7 +5,6 @@ Wraps the :class:`nwb_schema_language.Namespaces` and other objects with conveni for extracting information and generating translated schema """ - from copy import copy from pathlib import Path from pprint import pformat @@ -154,7 +153,8 @@ class NamespacesAdapter(Adapter): if len(internal_matches) > 1: raise KeyError( - f"Found multiple schemas in namespace that define {name}:\ninternal: {pformat(internal_matches)}\nimported:{pformat(import_matches)}" + f"Found multiple schemas in namespace that define {name}:\ninternal:" + f" {pformat(internal_matches)}\nimported:{pformat(import_matches)}" ) elif len(internal_matches) == 1: return internal_matches[0] @@ -168,7 +168,8 @@ class NamespacesAdapter(Adapter): if len(import_matches) > 1: raise KeyError( - f"Found multiple schemas in namespace that define {name}:\ninternal: {pformat(internal_matches)}\nimported:{pformat(import_matches)}" + f"Found multiple schemas in namespace that define {name}:\ninternal:" + f" {pformat(internal_matches)}\nimported:{pformat(import_matches)}" ) elif len(import_matches) == 1: return import_matches[0] diff --git a/nwb_linkml/src/nwb_linkml/adapters/schema.py b/nwb_linkml/src/nwb_linkml/adapters/schema.py index 8fbb5ed..70f033f 100644 --- a/nwb_linkml/src/nwb_linkml/adapters/schema.py +++ b/nwb_linkml/src/nwb_linkml/adapters/schema.py @@ -34,7 +34,10 @@ class SchemaAdapter(Adapter): ) version: Optional[str] = Field( None, - description="Version of schema, populated by NamespacesAdapter since individual schema files dont know their version in NWB Schema Lang", + description=( + "Version of schema, populated by NamespacesAdapter since individual schema files dont" + " know their version in NWB Schema Lang" + ), ) _created_classes: List[Type[Group | Dataset]] = PrivateAttr(default_factory=list) @@ -81,7 +84,8 @@ class SchemaAdapter(Adapter): len(res.slots) > 0 ): # pragma: no cover - hard to induce this error because the child classes don't fuck up like this raise RuntimeError( - "Generated schema in this translation can only have classes, all slots should be attributes within a class" + "Generated schema in this translation can only have classes, all slots should be" + " attributes within a class" ) sch = SchemaDefinition( diff --git a/nwb_linkml/src/nwb_linkml/generators/pydantic.py b/nwb_linkml/src/nwb_linkml/generators/pydantic.py index 176b211..b83bc16 100644 --- a/nwb_linkml/src/nwb_linkml/generators/pydantic.py +++ b/nwb_linkml/src/nwb_linkml/generators/pydantic.py @@ -253,7 +253,10 @@ class NWBPydanticGenerator(PydanticGenerator): SKIP_SLOTS: Tuple[str] = ("",) SKIP_CLASSES: Tuple[str] = ("",) INJECTED_FIELDS: Tuple[str] = ( - 'hdf5_path: Optional[str] = Field(None, description="The absolute path that this object is stored in an NWB file")', + ( + 'hdf5_path: Optional[str] = Field(None, description="The absolute path that this object' + ' is stored in an NWB file")' + ), 'object_id: Optional[str] = Field(None, description="Unique UUID for each object")', ) # SKIP_CLASSES=('VectorData','VectorIndex') diff --git a/nwb_linkml/src/nwb_linkml/maps/hdf5.py b/nwb_linkml/src/nwb_linkml/maps/hdf5.py index 18d752a..bbad48d 100644 --- a/nwb_linkml/src/nwb_linkml/maps/hdf5.py +++ b/nwb_linkml/src/nwb_linkml/maps/hdf5.py @@ -639,9 +639,7 @@ class CompleteNWBFile(HDF5Map): def check( cls, src: H5ReadResult, provider: SchemaProvider, completed: Dict[str, H5ReadResult] ) -> bool: - if src.neurodata_type == "NWBFile" and all( - [depend in completed for depend in src.depends] - ): + if src.neurodata_type == "NWBFile" and all([depend in completed for depend in src.depends]): return True else: return False diff --git a/nwb_linkml/src/nwb_linkml/providers/git.py b/nwb_linkml/src/nwb_linkml/providers/git.py index 7bb5a24..84bec58 100644 --- a/nwb_linkml/src/nwb_linkml/providers/git.py +++ b/nwb_linkml/src/nwb_linkml/providers/git.py @@ -20,14 +20,20 @@ class NamespaceRepo(BaseModel): """ name: str = Field( - description="Short name used to refer to this namespace (usually equivalent to the name field within a namespaces NWB list)" + description=( + "Short name used to refer to this namespace (usually equivalent to the name field" + " within a namespaces NWB list)" + ) ) repository: HttpUrl | DirectoryPath = Field( description="URL or local absolute path to the root repository" ) path: Path = Field(description="Relative path from the repository root to the namespace file") versions: List[str] = Field( - description="Known versions for this namespace repository, correspond to commit hashes or git tags that can be checked out by :class:`.GitRepo`", + description=( + "Known versions for this namespace repository, correspond to commit hashes or git tags" + " that can be checked out by :class:`.GitRepo`" + ), default_factory=list, ) @@ -248,7 +254,8 @@ class GitRepo: # Check that the remote matches if self.remote != str(self.namespace.repository): warnings.warn( - f'Repository exists, but has the wrong remote URL.\nExpected: {self.namespace.repository}\nGot:{self.remote.strip(".git")}' + "Repository exists, but has the wrong remote URL.\nExpected:" + f" {self.namespace.repository}\nGot:{self.remote.strip('.git')}" ) return False @@ -269,7 +276,8 @@ class GitRepo: or str(self.temp_directory).startswith(str(Config().git_dir)) ): warnings.warn( - "Temp directory is outside of the system temp dir or git directory set by environmental variables, not deleting in case this has been changed by mistake" + "Temp directory is outside of the system temp dir or git directory set by" + " environmental variables, not deleting in case this has been changed by mistake" ) self._temp_directory = None return @@ -293,7 +301,8 @@ class GitRepo: else: if not self.check(): warnings.warn( - "Destination directory is not empty and does not pass checks for correctness! cleaning up" + "Destination directory is not empty and does not pass checks for" + " correctness! cleaning up" ) self.cleanup() else: diff --git a/nwb_linkml/src/nwb_linkml/providers/schema.py b/nwb_linkml/src/nwb_linkml/providers/schema.py index 519675b..2298904 100644 --- a/nwb_linkml/src/nwb_linkml/providers/schema.py +++ b/nwb_linkml/src/nwb_linkml/providers/schema.py @@ -467,7 +467,8 @@ class LinkMLProvider(Provider): ns_repo = DEFAULT_REPOS.get(namespace, None) if ns_repo is None: raise KeyError( - f"Namespace {namespace} could not be found, and no git repository source has been configured!" + f"Namespace {namespace} could not be found, and no git repository source has been" + " configured!" ) ns_file = ns_repo.provide_from_git(commit=version) res = self.build_from_yaml(ns_file) diff --git a/nwb_linkml/tests/fixtures.py b/nwb_linkml/tests/fixtures.py index 8b703eb..a857847 100644 --- a/nwb_linkml/tests/fixtures.py +++ b/nwb_linkml/tests/fixtures.py @@ -117,7 +117,10 @@ def linkml_schema_bare() -> TestSchemas: ), SlotDefinition( name="inline_dict", - description="This should be inlined as a dictionary despite this class having an identifier", + description=( + "This should be inlined as a dictionary despite this class having" + " an identifier" + ), multivalued=True, inlined=True, inlined_as_list=False, diff --git a/nwb_linkml/tests/test_adapters/test_adapter.py b/nwb_linkml/tests/test_adapters/test_adapter.py index e6d2b75..12be06a 100644 --- a/nwb_linkml/tests/test_adapters/test_adapter.py +++ b/nwb_linkml/tests/test_adapters/test_adapter.py @@ -1,4 +1,3 @@ - import numpy as np import pytest from linkml_runtime.linkml_model import ( diff --git a/nwb_linkml/tests/test_adapters/test_adapter_classes.py b/nwb_linkml/tests/test_adapters/test_adapter_classes.py index 2617edf..3cc173e 100644 --- a/nwb_linkml/tests/test_adapters/test_adapter_classes.py +++ b/nwb_linkml/tests/test_adapters/test_adapter_classes.py @@ -1,4 +1,3 @@ - import pytest from linkml_runtime.linkml_model import SlotDefinition diff --git a/nwb_linkml/tests/test_adapters/test_adapter_dataset.py b/nwb_linkml/tests/test_adapters/test_adapter_dataset.py index bd032ca..6c06a21 100644 --- a/nwb_linkml/tests/test_adapters/test_adapter_dataset.py +++ b/nwb_linkml/tests/test_adapters/test_adapter_dataset.py @@ -1,7 +1,3 @@ - - - - from nwb_linkml.adapters.dataset import ( MapScalar, ) diff --git a/nwb_linkml/tests/test_adapters/test_adapter_namespaces.py b/nwb_linkml/tests/test_adapters/test_adapter_namespaces.py index 2d9acb5..5124bdd 100644 --- a/nwb_linkml/tests/test_adapters/test_adapter_namespaces.py +++ b/nwb_linkml/tests/test_adapters/test_adapter_namespaces.py @@ -1,4 +1,3 @@ - import pytest from nwb_linkml.adapters import SchemaAdapter diff --git a/nwb_linkml/tests/test_maps/test_hdmf.py b/nwb_linkml/tests/test_maps/test_hdmf.py index ceabe03..d95f61a 100644 --- a/nwb_linkml/tests/test_maps/test_hdmf.py +++ b/nwb_linkml/tests/test_maps/test_hdmf.py @@ -1,4 +1,3 @@ - import time import h5py diff --git a/nwb_schema_language/src/nwb_schema_language/__init__.py b/nwb_schema_language/src/nwb_schema_language/__init__.py index e13b65f..4c93a08 100644 --- a/nwb_schema_language/src/nwb_schema_language/__init__.py +++ b/nwb_schema_language/src/nwb_schema_language/__init__.py @@ -18,5 +18,6 @@ try: DTypeType = Union[List[CompoundDtype], FlatDtype, ReferenceDtype] except (NameError, RecursionError): warnings.warn( - "Error importing pydantic classes, passing because we might be in the process of patching them, but it is likely they are broken and you will be unable to use them!" + "Error importing pydantic classes, passing because we might be in the process of patching" + " them, but it is likely they are broken and you will be unable to use them!" ) diff --git a/nwb_schema_language/src/nwb_schema_language/datamodel/nwb_schema_language.py b/nwb_schema_language/src/nwb_schema_language/datamodel/nwb_schema_language.py index 0b0493c..3479735 100644 --- a/nwb_schema_language/src/nwb_schema_language/datamodel/nwb_schema_language.py +++ b/nwb_schema_language/src/nwb_schema_language/datamodel/nwb_schema_language.py @@ -510,7 +510,9 @@ class ReftypeOptions(EnumDefinitionImpl): ) region = PermissibleValue( text="region", - description="Reference to a region (i.e. subset) of another dataset of the given target_type", + description=( + "Reference to a region (i.e. subset) of another dataset of the given target_type" + ), ) _defn = EnumDefinition( diff --git a/pyproject.toml b/pyproject.toml index 0d7a7e1..93e076c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -88,5 +88,6 @@ warn_unreachable = true [tool.black] target-version = ['py38', 'py39', 'py310', 'py311'] enable-unstable-feature = ["string_processing"] +preview = true include = "nwb_linkml/.*\\.py$|nwb_schema_language/.*\\.py$" line-length = 100 \ No newline at end of file