Skip to content

Commit 8a157fb

Browse files
pretty print models
1 parent 81b3c62 commit 8a157fb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

linkml_runtime/utils/yamlutils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from copy import copy
22
from json import JSONDecoder
33
from typing import Union, Any, List, Optional, Type, Callable, Dict
4+
from pprint import pformat
45

56
import yaml
67
from deprecated.classic import deprecated
@@ -11,6 +12,7 @@
1112

1213
from linkml_runtime.utils.context_utils import CONTEXTS_PARAM_TYPE, merge_contexts
1314
from linkml_runtime.utils.formatutils import is_empty
15+
from linkml_runtime.utils.formatutils import remove_empty_items
1416

1517
YAMLObjTypes = Union[JsonObjTypes, "YAMLRoot"]
1618

@@ -277,6 +279,11 @@ def MissingRequiredField(self, field_name: str) -> None:
277279
""" Generic loader error handler """
278280
raise ValueError(f"{field_name} must be supplied")
279281

282+
def __str__(self):
283+
res = remove_empty_items(self)
284+
return pformat(as_dict(res),indent=2,compact=True)
285+
286+
280287

281288
def root_representer(dumper: yaml.Dumper, data: YAMLRoot):
282289
""" YAML callback -- used to filter out empty values (None, {}, [] and false)

0 commit comments

Comments
 (0)