Skip to content

Commit 4fd3f89

Browse files
committed
Less verbose doc generation
1 parent a773f88 commit 4fd3f89

File tree

6 files changed

+20
-12
lines changed

6 files changed

+20
-12
lines changed

examples/document.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A model for documents.
1313
<tr>
1414
<td><b>title</b></td>
1515
<td>str</td>
16-
<td><i>Document title</i></td>
16+
<td><i>The document title</i></td>
1717
</tr>
1818

1919

examples/document.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Document(Base):
4040
4141
Args:
4242
id: The unique id of the document
43-
title: Document title
43+
title: The document title
4444
ISBN: International Standard Book Number
4545
sections: The sections of the document
4646
"""
@@ -65,24 +65,29 @@ class Document(Base):
6565

6666
print(doc)
6767
print(doc.sections[0].paragraphs[0].contents)
68-
print(doc.sections[0].paragraphs[0].__getattribute__("contents"))
68+
print(doc.sections[0].paragraphs[1].__getattribute__("contents"))
6969

7070
doc.to_json_file("document.json")
7171
doc.to_yaml_file("document.yaml")
7272
doc.to_bson_file("document.bson")
7373

74+
print(" >> Full document details in YAML format:\n")
75+
76+
print(doc.to_yaml())
77+
7478
doc_md = doc.generate_documentation(format="markdown")
7579

7680
with open("document.md", "w") as d:
7781
d.write(doc_md)
7882

83+
7984
doc_rst = doc.generate_documentation(format="rst")
8085

8186
with open("document.rst", "w") as d:
8287
d.write(doc_rst)
8388

8489

85-
print("\nGenerating specification in dict form")
90+
print("\n >> Generating specification in dict form...")
8691
doc_dict = doc.generate_documentation(format="dict")
8792

8893
import json
@@ -92,9 +97,12 @@ class Document(Base):
9297
with open("document.specification.json", "w") as d:
9398
d.write(json.dumps(doc_dict, indent=4))
9499

95-
print("Generating specification in YAML")
100+
print(" >> Generating specification in YAML...\n")
101+
96102
with open("document.specification.yaml", "w") as d:
97-
d.write(yaml.dump(doc_dict, indent=4, sort_keys=False))
103+
yy = yaml.dump(doc_dict, indent=4, sort_keys=False)
104+
print(yy)
105+
d.write(yy)
98106

99107
with open("document.specification.bson", "wb") as d:
100108
d.write(bson.encode(doc_dict))

examples/document.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A model for documents.
99
Allowed field Data Type Description
1010
=============== =========== ==================================
1111
**id** str The unique id of the document
12-
**title** str Document title
12+
**title** str The document title
1313
**ISBN** int International Standard Book Number
1414
=============== =========== ==================================
1515

examples/document.specification.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"title": {
1010
"type": "str",
11-
"description": "Document title"
11+
"description": "The document title"
1212
},
1313
"ISBN": {
1414
"type": "int",

examples/document.specification.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Document:
66
description: The unique id of the document
77
title:
88
type: str
9-
description: Document title
9+
description: The document title
1010
ISBN:
1111
type: int
1212
description: International Standard Book Number

src/modelspec/base_types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def _cls_generate_documentation(cls, format: str = MARKDOWN_FORMAT):
584584
allowed_fields = cls._parse_allowed_fields()
585585
allowed_children = cls._parse_allowed_children()
586586

587-
print(f" - {cls.__name__} ({definition})")
587+
# print(f" - {cls.__name__} ({definition})")
588588

589589
rst_url_format = "`%s <%s>`__"
590590

@@ -693,7 +693,7 @@ def insert_links(text, format=MARKDOWN_FORMAT):
693693
type_, can_be_eval_expr=True, can_be_dict=True
694694
)
695695
type_str = Base._type_to_str(type_)
696-
print(" Allowed parameter: {} {}".format(f, (description, type_str)))
696+
# print(" Allowed parameter: {} {}".format(f, (description, type_str)))
697697

698698
if format == DICT_FORMAT:
699699
doc_dict[name]["allowed_parameters"][f] = {}
@@ -750,7 +750,7 @@ def insert_links(text, format=MARKDOWN_FORMAT):
750750

751751
for c, (description, type_) in allowed_children.items():
752752
type_str = Base._type_to_str(type_)
753-
print(" Allowed child: {} {}".format(c, (description, type_str)))
753+
# print(" Allowed child: {} {}".format(c, (description, type_str)))
754754

755755
referencable = not Base._is_base_type(type_, can_be_dict=True)
756756

0 commit comments

Comments
 (0)