Skip to content

Commit 79226f4

Browse files
sneakers-the-ratcmungall
authored andcommitted
[QoL] Pretty print - main package version (linkml#2032)
* make pythongen add repr=False by default * add test for repr override in python generator * update frozen strings in other tests * update snapshots * update code to match new pprint format * update snapshots * lint * use latest linkml-runtime with linkml/linkml-runtime#314 merged * regenerate snapshots --------- Co-authored-by: Chris Mungall <[email protected]>
1 parent db20f7d commit 79226f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+994
-916
lines changed

linkml/generators/pythongen.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ class PythonGenerator(Generator):
5454
gen_slots: bool = True
5555
genmeta: bool = False
5656
emit_metadata: bool = True
57+
dataclass_repr: bool = False
58+
"""
59+
Whether generated dataclasses should also generate a default __repr__ method.
60+
61+
Default ``False`` so that the parent :class:`linkml_runtime.utils.yamlutils.YAMLRoot` 's
62+
``__repr__`` method is inherited for model pretty printing.
63+
64+
References:
65+
- https://docs.python.org/3/library/dataclasses.html#dataclasses.dataclass
66+
"""
5767

5868
def __post_init__(self) -> None:
5969
if isinstance(self.schema, Path):
@@ -388,7 +398,7 @@ def gen_classdef(self, cls: ClassDefinition) -> str:
388398
return f"\n{self.class_or_type_name(cls.name)} = Any"
389399

390400
cd_str = (
391-
("\n@dataclass" if slotdefs else "")
401+
(f"\n@dataclass(repr={self.dataclass_repr})" if slotdefs else "")
392402
+ f"\nclass {self.class_or_type_name(cls.name)}{parentref}:{wrapped_description}"
393403
+ f"{self.gen_inherited_slots(cls)}"
394404
+ f"{self.gen_class_meta(cls)}"

poetry.lock

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jinja2 = ">= 3.1.0"
107107
jsonasobj2 = "==1.*,>=1.0.0,>=1.0.3"
108108
jsonschema = {extras = ["format"], version = ">=4.0.0"}
109109
linkml-dataops = "*"
110-
linkml-runtime = "1.8.0"
110+
linkml-runtime = "^1.8.1"
111111
openpyxl = "*"
112112
parse = "*"
113113
prefixcommons = ">=0.1.7"

tests/test_base/__snapshots__/annotations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class AnnotationTag(ExtensionTag):
4444
pass
4545

4646

47-
@dataclass
47+
@dataclass(repr=False)
4848
class Annotatable(YAMLRoot):
4949
"""
5050
mixin for classes that support annotations
@@ -64,7 +64,7 @@ def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
6464
super().__post_init__(**kwargs)
6565

6666

67-
@dataclass
67+
@dataclass(repr=False)
6868
class Annotation(Extension):
6969
"""
7070
a tag/value pair with the semantics of OWL Annotation

tests/test_base/__snapshots__/extensions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ExtensionTag(URIorCURIE):
4545

4646
AnyValue = Any
4747

48-
@dataclass
48+
@dataclass(repr=False)
4949
class Extension(YAMLRoot):
5050
"""
5151
a tag/value pair used to add non-model information to an entry
@@ -72,7 +72,7 @@ def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
7272
super().__post_init__(**kwargs)
7373

7474

75-
@dataclass
75+
@dataclass(repr=False)
7676
class Extensible(YAMLRoot):
7777
"""
7878
mixin for classes that support extension

tests/test_base/__snapshots__/markdown/meta/status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ URI: [linkml:status](https://w3id.org/linkml/status)
4848
| --- | --- | --- |
4949
| **Aliases:** | | workflow status |
5050
| **Mappings:** | | bibo:status |
51-
| **Examples:** | | Example(value='bibo:draft', description=None, object=None) |
51+
| **Examples:** | | Example({'value': 'bibo:draft'}) |
5252
| **In Subsets:** | | BasicSubset |
5353
| **See also:** | | [https://www.hl7.org/fhir/valueset-publication-status.html](https://www.hl7.org/fhir/valueset-publication-status.html) |
5454
| | | [https://www.hl7.org/fhir/versions.html#std-process](https://www.hl7.org/fhir/versions.html#std-process) |

tests/test_base/__snapshots__/markdown/meta/structured_alias_categories.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ URI: [linkml:structured_alias_categories](https://w3id.org/linkml/structured_ali
2727
| --- | --- | --- |
2828
| **Mappings:** | | dcterms:subject |
2929
| **Comments:** | | if you wish to use uncontrolled terms or terms that lack identifiers then use the keywords element |
30-
| **Examples:** | | Example(value='https://w3id.org/mod#acronym', description='An acronym', object=None) |
30+
| **Examples:** | | Example({'value': 'https://w3id.org/mod#acronym', 'description': 'An acronym'}) |
3131
| **In Subsets:** | | BasicSubset |

tests/test_base/__snapshots__/markdown/meta/subproperty_of.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,14 @@ URI: [linkml:subproperty_of](https://w3id.org/linkml/subproperty_of)
2525
| | | |
2626
| --- | --- | --- |
2727
| **Mappings:** | | rdfs:subPropertyOf |
28-
| **Examples:** | | Example(value='RO:HOM0000001', description='this is the RO term for "in homology relationship with", and used as a value of subproperty of this means that any ontological child (related to RO:HOM0000001 via an is_a relationship), is a valid value for the slot that declares this with the subproperty_of tag. This differs from the \'values_from\' meta model component in that \'values_from\' requires the id of a value set (said another way, if an entire ontology had a curie/identifier that was the identifier for the entire ontology, then that identifier would be used in \'values_from.\')', object=None) |
28+
| **Examples:** | | Example({
29+
'value': 'RO:HOM0000001',
30+
'description': ('this is the RO term for "in homology relationship with", and used as a value '
31+
'of subproperty of this means that any ontological child (related to '
32+
'RO:HOM0000001 via an is_a relationship), is a valid value for the slot that '
33+
'declares this with the subproperty_of tag. This differs from the '
34+
"'values_from' meta model component in that 'values_from' requires the id of "
35+
'a value set (said another way, if an entire ontology had a curie/identifier '
36+
'that was the identifier for the entire ontology, then that identifier would '
37+
"be used in 'values_from.')")
38+
}) |

0 commit comments

Comments
 (0)