Skip to content

Commit 30a6dc6

Browse files
committed
Use tabulate
1 parent aabc645 commit 30a6dc6

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

examples/document.rst

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@ A model for documents
66
Allowed parameters
77
==================
88

9-
============ === =====================
10-
<b>title</b> str <i>Document title</i>
11-
============ === =====================
12-
=========== === =========================================
13-
<b>ISBN</b> int <i>International Standard Book Number</i>
14-
=========== === =========================================
15-
========= === ===========================
16-
<b>id</b> str <i>Unique ID of element</i>
17-
========= === ===========================
18-
============ === ===========================
19-
<b>notes</b> str <i>Human readable notes</i>
20-
============ === ===========================
21-
</table>
9+
=============== =========== ====================================
10+
Allowed field Data Type Description
11+
=============== =========== ====================================
12+
**title** str *Document title*
13+
**ISBN** int *International Standard Book Number*
14+
**id** str *Unique ID of element*
15+
**notes** str *Human readable notes*
16+
=============== =========== ====================================
2217

2318
Allowed children
2419
================

modelspec/BaseTypes.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import sys
44
from collections import OrderedDict
5+
from tabulate import tabulate
56

67
verbose = False
78

@@ -415,6 +416,7 @@ def insert_links(text):
415416
if format == RST_FORMAT:
416417
ap = "Allowed parameters"
417418
doc_string += "%s\n%s\n\n" % (ap,"="*len(ap))
419+
table_info = []
418420
if format == DICT_FORMAT:
419421
doc_dict[name]["allowed_parameters"] = {}
420422

@@ -445,19 +447,16 @@ def insert_links(text):
445447
insert_links(self.allowed_fields[f][0])
446448
)
447449
if format == RST_FORMAT:
448-
n = "<b>%s</b>" % f
450+
n = "**%s**" % f
449451
t = "%s" % (
450452
'<a href="#%s">%s</a>' % (type_.lower(), type_)
451453
if referencable
452454
else type_,
453455
)
454-
d = "<i>%s</i>" % (
456+
d = "*%s*" % (
455457
insert_links(self.allowed_fields[f][0])
456458
)
457-
458-
doc_string += "%s %s %s\n"%("="*len(n),"="*len(t),"="*len(d))
459-
doc_string += "%s %s %s\n"%(n,t,d)
460-
doc_string += "%s %s %s\n"%("="*len(n),"="*len(t),"="*len(d))
459+
table_info.append([n,t,d])
461460

462461
if referencable:
463462
inst = self.allowed_fields[f][1]()
@@ -468,7 +467,7 @@ def insert_links(text):
468467
if format == MARKDOWN_FORMAT:
469468
doc_string += "</table>\n\n"
470469
if format == RST_FORMAT:
471-
doc_string += "</table>\n\n"
470+
doc_string += "%s\n\n"%(tabulate(table_info, ['Allowed field','Data Type','Description'], tablefmt="rst"))
472471

473472
if len(self.allowed_children) > 0:
474473
if format == MARKDOWN_FORMAT:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
description="A common JSON/YAML based format for compact model specification",
1616
long_description=open("README.md").read(),
1717
long_description_content_type="text/markdown",
18-
install_requires=["pyyaml", "numpy"],
18+
install_requires=["pyyaml", "numpy", "tabulate"],
1919
classifiers=[
2020
"Intended Audience :: Science/Research",
2121
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",

0 commit comments

Comments
 (0)