This commit is contained in:
sneakers-the-rat 2024-09-19 19:21:03 -07:00
parent 1d27c6a259
commit 03ba6568a3
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
2 changed files with 29 additions and 14 deletions

View file

@ -224,7 +224,7 @@ class NamespacesAdapter(Adapter):
return parents 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 Overwrite the version of a dataset or group that is stored in our schemas
""" """
@ -264,9 +264,14 @@ class NamespacesAdapter(Adapter):
matches = [] matches = []
for schema in self.all_schemas(): for schema in self.all_schemas():
in_schema = False in_schema = False
if isinstance(cls, str) and cls in [ if (
c.neurodata_type_def for c in schema.created_classes isinstance(cls, str)
] or isinstance(cls, Dataset) and cls in schema.datasets or isinstance(cls, Group) and cls in schema.groups: 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 in_schema = True
if in_schema: if in_schema:

View file

@ -1,27 +1,37 @@
from pprint import pformat as _pformat """
import textwrap The fabled junk drawer
"""
import re import re
import textwrap
from pprint import pformat as _pformat
def pformat(fields: dict, cls_name: str, indent: str = " ") -> str: 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. pretty format the fields of the items of a ``YAMLRoot`` object without the
see ``YAMLRoot.__repr__``. wonky indentation of pformat.
formatting is similar to black - items at similar levels of nesting have similar levels of indentation, formatting is similar to black -
rather than getting placed at essentially random levels of indentation depending on what came before them. 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 = [] res = []
total_len = 0 total_len = 0
for key, val in fields.items(): for key, val in fields.items():
if val == [] or val == {} or val is None: if val == [] or val == {} or val is None:
continue continue
# pformat handles everything else that isn't a YAMLRoot object, but it sure does look ugly # pformat handles everything else that isn't a YAMLRoot object,
# use it to split lines and as the thing of last resort, but otherwise indent = 0, we'll do that # 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) 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)) 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 val_str = f"'{key}': " + val_str
# count the total length of this string so we know if we need to linebreak or not later # count the total length of this string so we know if we need to linebreak or not later