mirror of
https://github.com/p2p-ld/nwb-linkml.git
synced 2024-12-04 20:44:29 +00:00
lint
This commit is contained in:
parent
1d27c6a259
commit
03ba6568a3
2 changed files with 29 additions and 14 deletions
|
@ -224,7 +224,7 @@ class NamespacesAdapter(Adapter):
|
|||
|
||||
return parents
|
||||
|
||||
def _overwrite_class(self, new_cls: Dataset | Group, old_cls: Dataset | Group):
|
||||
def _overwrite_class(self, new_cls: Dataset | Group, old_cls: Dataset | Group) -> None:
|
||||
"""
|
||||
Overwrite the version of a dataset or group that is stored in our schemas
|
||||
"""
|
||||
|
@ -264,9 +264,14 @@ class NamespacesAdapter(Adapter):
|
|||
matches = []
|
||||
for schema in self.all_schemas():
|
||||
in_schema = False
|
||||
if isinstance(cls, str) and cls in [
|
||||
c.neurodata_type_def for c in schema.created_classes
|
||||
] or isinstance(cls, Dataset) and cls in schema.datasets or isinstance(cls, Group) and cls in schema.groups:
|
||||
if (
|
||||
isinstance(cls, str)
|
||||
and cls in [c.neurodata_type_def for c in schema.created_classes]
|
||||
or isinstance(cls, Dataset)
|
||||
and cls in schema.datasets
|
||||
or isinstance(cls, Group)
|
||||
and cls in schema.groups
|
||||
):
|
||||
in_schema = True
|
||||
|
||||
if in_schema:
|
||||
|
|
|
@ -1,27 +1,37 @@
|
|||
from pprint import pformat as _pformat
|
||||
import textwrap
|
||||
"""
|
||||
The fabled junk drawer
|
||||
"""
|
||||
|
||||
import re
|
||||
import textwrap
|
||||
from pprint import pformat as _pformat
|
||||
|
||||
|
||||
def pformat(fields: dict, cls_name: str, indent: str = " ") -> str:
|
||||
"""
|
||||
pretty format the fields of the items of a ``YAMLRoot`` object without the wonky indentation of pformat.
|
||||
see ``YAMLRoot.__repr__``.
|
||||
pretty format the fields of the items of a ``YAMLRoot`` object without the
|
||||
wonky indentation of pformat.
|
||||
|
||||
formatting is similar to black - items at similar levels of nesting have similar levels of indentation,
|
||||
rather than getting placed at essentially random levels of indentation depending on what came before them.
|
||||
formatting is similar to black -
|
||||
items at similar levels of nesting have similar levels of indentation,
|
||||
rather than getting placed at essentially random levels of indentation
|
||||
depending on what came before them.
|
||||
"""
|
||||
res = []
|
||||
total_len = 0
|
||||
for key, val in fields.items():
|
||||
if val == [] or val == {} or val is None:
|
||||
continue
|
||||
# pformat handles everything else that isn't a YAMLRoot object, but it sure does look ugly
|
||||
# use it to split lines and as the thing of last resort, but otherwise indent = 0, we'll do that
|
||||
# pformat handles everything else that isn't a YAMLRoot object,
|
||||
# but it sure does look ugly
|
||||
# use it to split lines and as the thing of last resort,
|
||||
# but otherwise indent = 0, we'll do that
|
||||
val_str = _pformat(val, indent=0, compact=True, sort_dicts=False)
|
||||
# now we indent everything except the first line by indenting and then using regex to remove just the first indent
|
||||
# now we indent everything except the first line by indenting
|
||||
# and then using regex to remove just the first indent
|
||||
val_str = re.sub(rf"\A{re.escape(indent)}", "", textwrap.indent(val_str, indent))
|
||||
# now recombine with the key in a format that can be re-eval'd into an object if indent is just whitespace
|
||||
# now recombine with the key in a format that can be re-eval'd
|
||||
# into an object if indent is just whitespace
|
||||
val_str = f"'{key}': " + val_str
|
||||
|
||||
# count the total length of this string so we know if we need to linebreak or not later
|
||||
|
|
Loading…
Reference in a new issue