Commit 6e04d7bb authored by Nic's avatar Nic
Browse files

improve autodoc

parent 20ff2749
......@@ -42,11 +42,10 @@ def _indent(txt, indent):
if indent == 0:
return txt
else:
indent = INDENT * indent
if isinstance(txt, list):
return ["".join([indent, line]) for line in txt]
else:
return "".join([indent, txt])
txt = "\n".join(txt)
txt = textwrap.indent(txt, prefix=INDENT * indent, predicate=lambda line: True)
return txt + "\n"
def _comment(txt):
......@@ -238,31 +237,32 @@ class VDataAutodoc:
if tabnames == "*":
# retrieve remaining tabs
tabnames = set(self.schemas.keys()) - processed_tabs
for tab in tabnames:
for tab_no, tab in enumerate(tabnames):
processed_tabs.add(tab)
if tab in skip_tabs:
continue
schema = self.schemas[tab]
# -----------------------------------------------------------------
# update private master file
with open(_master_file, "a") as fh:
fh.write(
_include(root_tabdir / f".{tab}.rst", relative_to=self.src_dir)
)
fh.write(_write("-------------------------"))
# -----------------------------------------------------------------
# create public tab description file `source/tabs/<tab>.rst`
filename = root_tabdir / f"{tab}.rst"
if not filename.exists():
_new_public_file(filename)
# -----------------------------------------------------------------
# create private tab description file `source/tabs/.<tab>.rst`
_filename = root_tabdir / f".{tab}.rst"
with open(_filename, "w") as fh:
# update private master file
with open(_master_file, "a") as fh:
fh.write(_write(f'Sheet "``{tab}``"', header=tab_header_level))
# fh.write(_write(f"Specifications", header=tab_header_level + 1))
# include public tab description file `source/tabs/<tab>.rst`
fh.write(_include(filename, relative_to=self.src_dir))
fh.write(
_include(root_tabdir / f".{tab}.rst", relative_to=self.src_dir)
)
if tab_no < len(tabnames) - 1:
fh.write(_write("\n-------------------------\n"))
# -----------------------------------------------------------------
# create private tab description file `source/tabs/.<tab>.rst`
_filename = root_tabdir / f".{tab}.rst"
with open(_filename, "w") as fh:
fh.write(
_write(
f'"``{tab}``" Columns Specifications',
......@@ -294,6 +294,7 @@ class VDataAutodoc:
)
_uniq = dict(schema.uniqueness_sets)
if _uniq:
_uniq = {f"Set ({id})": v for id, v in _uniq.items()}
uniq = {}
for id, cols in _uniq.items():
for col in cols:
......@@ -345,16 +346,15 @@ class VDataAutodoc:
# table caption
fh.write(_write(f"\n.. table:: {tab} columns specifications\n"))
fh.write(_write(table, indent=1))
fh.write("\n")
# ---------------------------------------------------------
# note about uniqueness sets
if _uniq:
fh.write(
_write(
"\nthe following sets of columns combination need to be **unique**:"
)
)
for uniq, cols in _uniq.items():
columns = ", ".join([f"``{c}``" for c in cols])
fh.write(_write(f" * ``{uniq}``: {columns}"))
msg = "The following set(s) of columns combination need to be unique:\n\n"
for uniq, cols in _uniq.items():
columns = ", ".join([f"``{c}``" for c in cols])
msg += f" * ``{uniq}``: {columns}\n"
fh.write(_directive(name="note", content=msg))
# ---------------------------------------------------------
# xref
if schema.xcalling:
......@@ -366,17 +366,11 @@ class VDataAutodoc:
table = tabulate.tabulate(
df, headers="keys", tablefmt="rst", showindex=False
)
fh.write(
_write(
"**The following columns need to refer to existing values from other sheet(s):**"
)
)
# ---------------------------------------------------------
# XREF table caption
fh.write(
_write(f"\n.. table:: {tab} columns cross-references\n")
)
fh.write(_write(table, indent=1))
msg = "The following column(s) need to refer to existing value(s) from other sheet(s):\n\n"
msg += _write(f"\n.. table:: {tab} columns cross-references\n")
msg += _write(table, indent=1)
fh.write(_directive(name="note", content=msg))
# =============================================================================
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment