Commit c97ea8a3 authored by Nic's avatar Nic
Browse files

add default custom.css and fix tests

parent 8fe93eda
......@@ -9,12 +9,10 @@ import string
import re
import textwrap
import numpy as np
import pandas as pd
import tabulate
from gridsource import Data as IVData
from gridsource.validation import load_yaml
INDENT = " "
HEADERS = ["=", "-", '"', "'", "~"]
......@@ -72,10 +70,10 @@ def _include(filename, relative_to=False, relative_prefix=None, literal=False):
# =============================================================================
# slugification and label forger
# =============================================================================
ROLES = re.compile(":\w+:")
ROLES = re.compile(r":\w+:")
DUPLICATED_UNDERSCORE = re.compile("(_){2,}")
DUPLICATED_DASH = re.compile("(-){2,}")
REMAINS = re.compile("\W")
REMAINS = re.compile(r"\W")
def _slugify(text):
......@@ -106,7 +104,7 @@ def _directive(name="", arg=None, fields=None, content=None, indent=0):
>>> print(_directive(content='bla\\nbla'))
.. bla
blad
bla
"""
o = list()
if name:
......@@ -209,17 +207,23 @@ class VDataAutodoc:
shutil.rmtree(self.target_dir)
# -----------------------------------------------------------------
# create project structure
cmd = f"sphinx-quickstart --sep -p {project_name} -a {author} -v {version} -l {lang} {self.target_dir} -q --ext-mathjax"
cmd = (
f"sphinx-quickstart --sep -p {project_name}"
f" -a {author} -v {version} -l {lang} {self.target_dir}"
" -q --ext-mathjax"
)
if templatedir:
cmd += f" --templatedir {templatedir} "
# =====================================================================
# updating expected mastertoctree with head and tail chapters
# =====================================================================
mastertoctree = (
["head.rst"] + kwargs.pop("mastertoctree") + ["tail.rst", "glossary.rst"]
["head.rst"]
+ kwargs.pop("mastertoctree", [])
+ ["tail.rst", "glossary.rst"]
)
mastertoctree = _indent("\n".join(mastertoctree), 1)
cmd += f"-d mastertoctree='{mastertoctree}' "
cmd += f" -d mastertoctree='{mastertoctree}' "
cmd += " ".join([f"-d {k}={v}" for k, v in kwargs.items()])
print(40 * "*")
print(cmd)
......@@ -227,6 +231,154 @@ class VDataAutodoc:
sp.run(shlex.split(cmd))
self.src_dir = self.target_dir / "source"
# ---------------------------------------------------------------------
# minimal custom.css
css_fname = self.src_dir / "_static" / "custom.css"
with open(css_fname, "w") as fh:
fh.write(
"""
/* Colors and text decoration.
For example, :black:`text in black` or :blink:`text blinking` in rST. */
.black {
color: black;
}
.gray {
color: gray;
}
.grey {
color: gray;
}
.silver {
color: silver;
}
.white {
color: white;
}
.maroon {
color: maroon;
}
.red {
color: red;
}
.magenta {
color: magenta;
}
.fuchsia {
color: fuchsia;
}
.pink {
color: pink;
}
.orange {
color: orange;
}
.yellow {
color: yellow;
}
.lime {
color: lime;
}
.green {
color: green;
}
.olive {
color: olive;
}
.teal {
color: teal;
}
.cyan {
color: cyan;
}
.aqua {
color: aqua;
}
.blue {
color: blue;
}
.navy {
color: navy;
}
.purple {
color: purple;
}
.under {
text-decoration: underline;
}
.over {
text-decoration: overline;
}
.blink {
text-decoration: blink;
}
.line {
text-decoration: line-through;
}
.strike {
text-decoration: line-through;
}
.it {
font-style: italic;
}
.ob {
font-style: oblique;
}
.small {
font-size: small;
}
.large {
font-size: large;
}
.smallpar {
font-size: small;
}
table.docutils {
border: 1px solid {{ theme_table_border }};
-moz-box-shadow: 2px 2px 4px {{ theme_shadow }};
-webkit-box-shadow: 2px 2px 4px {{ theme_shadow }};
box-shadow: 2px 2px 4px {{ theme_shadow }};
font-size: 12px;
}
table.docutils th {
border: 1px solid {{ theme_table_border }};
padding: 0.25em 0.7em;
background-color: bisque;
}
"""
)
# ---------------------------------------------------------------------
# create head and tails files
for chapter in ("head.rst", "tail.rst"):
path = self.src_dir / Path(chapter)
......@@ -240,7 +392,10 @@ class VDataAutodoc:
p += "* :gray:`<SHEET>`-:orange:`<field>`: Mandatory field\n"
p += "* :gray:`<SHEET>`-:green:`<field>`: Padded field\n"
p += "* :gray:`<SHEET>`-<field>: Optional field\n"
p += "\nWhere ``<SHEET>`` is the tab featuring the field, and ``<field>`` is the field name."
p += (
"\nWhere ``<SHEET>`` is the tab featuring the field,"
" and ``<field>`` is the field name."
)
fh.write(_write(p))
# create glossary
glossary_file = self.src_dir / "glossary.rst"
......@@ -282,7 +437,7 @@ class VDataAutodoc:
drop_columns=(),
rename_columns=(),
order_columns=("column",),
tabs_chapters=((None, "*"),),
tabs_chapters=(("Input Data", "*"),),
):
processed_tabs = set()
......
......@@ -3,6 +3,8 @@ import tempfile
from io import StringIO
from pathlib import Path
import shutil
import subprocess
import shlex
import pytest
......@@ -36,9 +38,15 @@ def test_00(datadir):
)
# with tempfile.TemporaryDirectory() as tmpdirname:
# ad = VDataAutodoc(ivdata, target_dir=Path(tmpdirname)/"DOC")
ad = VDataAutodoc(ivdata, target_dir=Path("~/DOC").expanduser())
target_dir = Path(tempfile.mkdtemp()) / "test_autodoc"
ad = VDataAutodoc(ivdata, target_dir=target_dir)
try:
ad.create(project_name="totor", author="me", version="1.2", exist_ok=False)
ad.create(
project_name="totor",
author="me",
version="1.2",
exist_ok=False,
)
except FileExistsError:
pass
ad.dump_data(
......@@ -50,3 +58,10 @@ def test_00(datadir):
"maximum": "max",
},
)
# -------------------------------------------------------------------------
# check make html works
prev_cwd = os.getcwd()
os.chdir(target_dir)
ret = subprocess.run(["/usr/bin/make", "html"], shell=True)
assert ret.returncode == 0
os.chdir(prev_cwd)
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