From c1a1ca7158ba703ce854ce7c67ddcf23c8387708 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 27 Apr 2022 16:50:28 +0100 Subject: [PATCH 1/2] Custom class for weights table --- docs/source/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/conf.py b/docs/source/conf.py index e54e8bfb582..7e07eadfe54 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -342,6 +342,7 @@ def inject_weight_metadata(app, what, name, obj, options, lines): v = f"`link <{v}>`__" table.append((str(k), str(v))) table = tabulate(table, tablefmt="rst") + lines += [".. rst-class:: table-myclass"] lines += [".. table::", ""] lines += textwrap.indent(table, " " * 4).split("\n") lines.append("") From bf8e902eab98d9e7d4b4dc3f31e3700223a7954f Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Thu, 28 Apr 2022 09:57:27 +0100 Subject: [PATCH 2/2] Proper CSS --- docs/source/_static/css/custom_torchvision.css | 13 ++++++++++++- docs/source/conf.py | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/source/_static/css/custom_torchvision.css b/docs/source/_static/css/custom_torchvision.css index aa0e74c753a..bdc4071c1aa 100644 --- a/docs/source/_static/css/custom_torchvision.css +++ b/docs/source/_static/css/custom_torchvision.css @@ -1,4 +1,4 @@ -/* This rule (and possibly this entire file) should be removed once +/* This rule should be removed once https://github.com/pytorch/pytorch_sphinx_theme/issues/125 is fixed. We override the rule so that the links to the notebooks aren't hidden in the @@ -10,3 +10,14 @@ article.pytorch-article .sphx-glr-download-link-note.admonition.note, article.pytorch-article .reference.download.internal, article.pytorch-article .sphx-glr-signature { display: block; } + +/* These 2 rules below are for the weight tables (generated in conf.py) to look + * better. In particular we make their row height shorter */ +.table-weights td, .table-weights th { + margin-bottom: 0.2rem; + padding: 0 !important; + line-height: 1 !important; +} +.table-weights p { + margin-bottom: 0.2rem !important; +} diff --git a/docs/source/conf.py b/docs/source/conf.py index 7e07eadfe54..db831a85155 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -342,7 +342,7 @@ def inject_weight_metadata(app, what, name, obj, options, lines): v = f"`link <{v}>`__" table.append((str(k), str(v))) table = tabulate(table, tablefmt="rst") - lines += [".. rst-class:: table-myclass"] + lines += [".. rst-class:: table-weights"] # Custom CSS class, see custom_torchvision.css lines += [".. table::", ""] lines += textwrap.indent(table, " " * 4).split("\n") lines.append("") @@ -370,6 +370,7 @@ def generate_weights_table(module, table_name, metrics): generated_dir = Path("generated") generated_dir.mkdir(exist_ok=True) with open(generated_dir / f"{table_name}_table.rst", "w+") as table_file: + table_file.write(".. rst-class:: table-weights\n") # Custom CSS class, see custom_torchvision.css table_file.write(".. table::\n") table_file.write(f" :widths: 100 {'20 ' * len(metrics_names)} 20 10\n\n") table_file.write(f"{textwrap.indent(table, ' ' * 4)}\n\n")