From f3cf51e73a4b263225ac4849b155569373c0c636 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 16 Jan 2024 10:57:20 -0500 Subject: [PATCH 01/10] no bootstrap --- pyproject.toml | 1 - sphinx_asdf/nodes.py | 11 +++-------- sphinx_asdf/templates/schema.html | 4 ---- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index faf1b76..aea4815 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,6 @@ dependencies = [ "packaging", "sphinx", "sphinx-astropy", - "sphinx_bootstrap_theme", "sphinx-rtd-theme", "toml", diff --git a/sphinx_asdf/nodes.py b/sphinx_asdf/nodes.py index 5c3ea47..44d232c 100644 --- a/sphinx_asdf/nodes.py +++ b/sphinx_asdf/nodes.py @@ -140,14 +140,9 @@ def depart_html(self, node): class schema_combiner_body(nodes.compound): def visit_html(self, node): self.body.append( - """ - -
- """.format( - node.get("path") - ) + f""" +
+ """ ) def depart_html(self, node): diff --git a/sphinx_asdf/templates/schema.html b/sphinx_asdf/templates/schema.html index f3128f1..bad9c70 100644 --- a/sphinx_asdf/templates/schema.html +++ b/sphinx_asdf/templates/schema.html @@ -4,10 +4,6 @@ {%- endblock %} -{% block extrahead %} - - -{% endblock %} {% block footer %} {{ super() }}
From b88b224c5998bd9745a778537bdb62b13f41c756 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 16 Jan 2024 12:34:33 -0500 Subject: [PATCH 02/10] fix formatting after bootstrap removal --- sphinx_asdf/directives.py | 27 ++++++++++++++------------- sphinx_asdf/nodes.py | 20 ++++++++++---------- sphinx_asdf/static/sphinx_asdf.css | 10 +++++----- sphinx_asdf/templates/schema.html | 2 +- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/sphinx_asdf/directives.py b/sphinx_asdf/directives.py index 2e8e8d0..b480a2e 100644 --- a/sphinx_asdf/directives.py +++ b/sphinx_asdf/directives.py @@ -153,6 +153,7 @@ def _create_toc(self, schema): if "definitions" in schema: toc.append(toc_link(text=INTERNAL_DEFINITIONS_SECTION_TITLE)) toc.append(toc_link(text=ORIGINAL_SCHEMA_SECTION_TITLE)) + toc.append(nodes.paragraph()) return toc def _markdown_to_nodes(self, text, filename): @@ -226,7 +227,7 @@ def _create_ref_node(self, ref): def _create_enum_node(self, enum_values): enum_nodes = nodes.compound() - enum_nodes.append(nodes.line(text="Only the following values are valid for this node:")) + enum_nodes.append(nodes.paragraph(text="Only the following values are valid for this node:")) markdown = "\n".join([f"* **{val}**" for val in enum_values]) enum_nodes.extend(self._markdown_to_nodes(markdown, "")) return enum_nodes @@ -240,14 +241,14 @@ def _create_array_items_node(self, items, path): node_list = nodes.compound() if isinstance(items, list): text = "The first {} item{} in the list must be the following types:" - node_list.append(nodes.line(text=text.format(len(items), "s" if len(items) > 1 else ""))) + node_list.append(nodes.paragraph(text=text.format(len(items), "s" if len(items) > 1 else ""))) item_list = nodes.bullet_list() for i, it in enumerate(items): item_path = self._append_to_path(path, i) item_list.append(self._process_properties(it, top=True, path=item_path)) node_list.append(item_list) else: - node_list.append(nodes.line(text="Items in the array are restricted to the following types:")) + node_list.append(nodes.paragraph(text="Items in the array are restricted to the following types:")) node_list.append(self._process_properties(items, top=True, path=path)) return node_list @@ -260,21 +261,21 @@ def _process_validation_keywords(self, schema, typename=None, path=""): node_list.append(nodes.emphasis(text="No length restriction")) if schema.get("minLength", 0): text = f"Minimum length: {schema['minLength']}" - node_list.append(nodes.line(text=text)) + node_list.append(nodes.paragraph(text=text)) if "maxLength" in schema: text = f"Maximum length: {schema['maxLength']}" - node_list.append(nodes.line(text=text)) + node_list.append(nodes.paragraph(text=text)) if "pattern" in schema: - node_list.append(nodes.line(text="Must match the following pattern:")) + node_list.append(nodes.paragraph(text="Must match the following pattern:")) node_list.append(nodes.literal_block(text=schema["pattern"], language="none")) elif typename == "array": if schema.get("minItems", 0): text = f"Minimum length: {schema['minItems']}" - node_list.append(nodes.line(text=text)) + node_list.append(nodes.paragraph(text=text)) if "maxItems" in schema: text = f"Maximum length: {schema['maxItems']}" - node_list.append(nodes.line(text=text)) + node_list.append(nodes.paragraph(text=text)) if "additionalItems" in schema and "items" in schema: if isinstance(schema["items"], list) and schema["additionalItems"] is False: node_list.append(nodes.emphasis(text="Additional items not permitted")) @@ -288,10 +289,10 @@ def _process_validation_keywords(self, schema, typename=None, path=""): elif typename in ["integer", "number"]: if "minimum" in schema: text = f"Minimum value: {schema['minimum']}" - node_list.append(nodes.line(text=text)) + node_list.append(nodes.paragraph(text=text)) if "maximum" in schema: text = f"Maximum value: {schema['maximum']}" - node_list.append(nodes.line(text=text)) + node_list.append(nodes.paragraph(text=text)) if "enum" in schema: node_list.append(self._create_enum_node(schema["enum"])) @@ -303,10 +304,10 @@ def _process_validation_keywords(self, schema, typename=None, path=""): else: default = schema["default"] text = f"Default value: {default}" - node_list.append(nodes.line(text=text)) + node_list.append(nodes.paragraph(text=text)) else: default_node = nodes.compound() - default_node.append(nodes.line(text="Default value:")) + default_node.append(nodes.paragraph(text="Default value:")) default_node.append(nodes.literal_block(text=pformat(schema["default"]), language="none")) node_list.append(default_node) @@ -338,7 +339,7 @@ def _process_properties(self, schema, top=False, path=""): for key, node in schema["properties"].items(): new_path = self._append_to_path(path, key) treenodes.append(self._create_property_node(key, node, key in required, path=new_path)) - comment = nodes.line(text="This type is an object with the following properties:") + comment = nodes.paragraph(text="This type is an object with the following properties:") return schema_properties(None, *[comment, treenodes], id=path) elif "type" in schema: details = self._process_top_type(schema, path=path) diff --git a/sphinx_asdf/nodes.py b/sphinx_asdf/nodes.py index 44d232c..2e461bd 100644 --- a/sphinx_asdf/nodes.py +++ b/sphinx_asdf/nodes.py @@ -17,7 +17,7 @@ def depart_html(self, node): class schema_title(nodes.compound): def visit_html(self, node): - self.body.append(r'
') + self.body.append(r'
') def depart_html(self, node): self.body.append(r"
") @@ -42,7 +42,7 @@ def depart_html(self, node): class schema_description(nodes.compound): def visit_html(self, node): - self.body.append(r'
') def depart_html(self, node): self.body.append(r"
") @@ -50,7 +50,7 @@ def depart_html(self, node): class section_header(nodes.line): def visit_html(self, node): - self.body.append(r'

') + self.body.append(r'

') def depart_html(self, node): self.body.append(headerlink_template.format(name=node[0].title(), title="")) @@ -59,7 +59,7 @@ def depart_html(self, node): class schema_properties(nodes.compound): def visit_html(self, node): - self.body.append(r'
'.format(node.get("id"))) + self.body.append(r'
'.format(node.get("id"))) def depart_html(self, node): self.body.append(r"
") @@ -67,7 +67,7 @@ def depart_html(self, node): class schema_property(nodes.compound): def visit_html(self, node): - self.body.append(r'
  • '.format(node.get("id"))) + self.body.append(r'
  • '.format(node.get("id"))) def depart_html(self, node): self.body.append(r"
  • ") @@ -75,7 +75,7 @@ def depart_html(self, node): class schema_property_name(nodes.line): def visit_html(self, node): - self.body.append(r'
    ') + self.body.append(r'
    ') def depart_html(self, node): self.body.append(r"
    ") @@ -99,7 +99,7 @@ def depart_html(self, node): class asdf_tree(nodes.bullet_list): def visit_html(self, node): - self.body.append(r'
      ') + self.body.append(r'
        ') def depart_html(self, node): self.body.append(r"
      ") @@ -107,7 +107,7 @@ def depart_html(self, node): class asdf_ref(nodes.line): def visit_html(self, node): - self.body.append(f"") + self.body.append(f'') def depart_html(self, node): self.body.append(r"") @@ -123,7 +123,7 @@ def depart_html(self, node): class example_item(nodes.compound): def visit_html(self, node): - self.body.append(r'
      ') + self.body.append(r'
      ') def depart_html(self, node): self.body.append(r"
      ") @@ -141,7 +141,7 @@ class schema_combiner_body(nodes.compound): def visit_html(self, node): self.body.append( f""" -
      +
      """ ) diff --git a/sphinx_asdf/static/sphinx_asdf.css b/sphinx_asdf/static/sphinx_asdf.css index 48ba2d8..9d98e77 100644 --- a/sphinx_asdf/static/sphinx_asdf.css +++ b/sphinx_asdf/static/sphinx_asdf.css @@ -1,13 +1,13 @@ -div.schema_title { +div.schema-title { font-size: 1.5em; font-weight: bold; } -div.property_description { +div.property-description { font-side: 1em; } -div.schema_property_name { +div.schema-property-name { font-size: 1.5em; font-weight: bold; } @@ -16,11 +16,11 @@ table { width: 30%; } -td.schema_property_required { +td.schema-property-required { font-style: italic; } -.asdf_ref { +.asdf-ref { font-size: 1.5em; font-weight: bold; } diff --git a/sphinx_asdf/templates/schema.html b/sphinx_asdf/templates/schema.html index bad9c70..432690c 100644 --- a/sphinx_asdf/templates/schema.html +++ b/sphinx_asdf/templates/schema.html @@ -7,6 +7,6 @@ {% block footer %} {{ super() }}
      - Schema documentation automatically generated by sphinx-asdf {{ sphinx_asdf_version }}. + Schema documentation automatically generated by sphinx-asdf {{ sphinx_asdf_version }}.
      {% endblock %} From 460f0ed350ec2c7e58dbad48fc84c69f3e2a0549 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 16 Jan 2024 12:35:33 -0500 Subject: [PATCH 03/10] remove unused sphinx_asdf.js --- sphinx_asdf/connections.py | 2 +- sphinx_asdf/static/sphinx_asdf.js | 0 sphinx_asdf/templates/schema.html | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 sphinx_asdf/static/sphinx_asdf.js diff --git a/sphinx_asdf/connections.py b/sphinx_asdf/connections.py index 36d8bf8..3d020d7 100644 --- a/sphinx_asdf/connections.py +++ b/sphinx_asdf/connections.py @@ -158,7 +158,7 @@ def add_labels_to_nodes(app, document): def on_build_finished(app, exc): if exc is None: - for asset in ["sphinx_asdf.css", "sphinx_asdf.js"]: + for asset in ["sphinx_asdf.css"]: src = posixpath.join(posixpath.dirname(__file__), "static", asset) dst = posixpath.join(app.outdir, "_static") copy_asset(src, dst) diff --git a/sphinx_asdf/static/sphinx_asdf.js b/sphinx_asdf/static/sphinx_asdf.js deleted file mode 100644 index e69de29..0000000 diff --git a/sphinx_asdf/templates/schema.html b/sphinx_asdf/templates/schema.html index 432690c..9d33fdc 100644 --- a/sphinx_asdf/templates/schema.html +++ b/sphinx_asdf/templates/schema.html @@ -2,7 +2,6 @@ {%- block scripts %} {{ super() }} - {%- endblock %} {% block footer %} {{ super() }} From fdfdb8b6ee805d56d2e020a024f703d7d90a20bc Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 16 Jan 2024 12:37:32 -0500 Subject: [PATCH 04/10] remove sphinx_asdf.css --- sphinx_asdf/connections.py | 8 ----- sphinx_asdf/static/sphinx_asdf.css | 48 ------------------------------ sphinx_asdf/templates/schema.html | 4 --- 3 files changed, 60 deletions(-) delete mode 100644 sphinx_asdf/static/sphinx_asdf.css diff --git a/sphinx_asdf/connections.py b/sphinx_asdf/connections.py index 3d020d7..e98b6f3 100644 --- a/sphinx_asdf/connections.py +++ b/sphinx_asdf/connections.py @@ -154,11 +154,3 @@ def add_labels_to_nodes(app, document): anonlabels[name] = docname, labelid # labelname -> docname, labelid, sectionname labels[name] = docname, labelid, "" - - -def on_build_finished(app, exc): - if exc is None: - for asset in ["sphinx_asdf.css"]: - src = posixpath.join(posixpath.dirname(__file__), "static", asset) - dst = posixpath.join(app.outdir, "_static") - copy_asset(src, dst) diff --git a/sphinx_asdf/static/sphinx_asdf.css b/sphinx_asdf/static/sphinx_asdf.css deleted file mode 100644 index 9d98e77..0000000 --- a/sphinx_asdf/static/sphinx_asdf.css +++ /dev/null @@ -1,48 +0,0 @@ -div.schema-title { - font-size: 1.5em; - font-weight: bold; -} - -div.property-description { - font-side: 1em; -} - -div.schema-property-name { - font-size: 1.5em; - font-weight: bold; -} - -table { - width: 30%; -} - -td.schema-property-required { - font-style: italic; -} - -.asdf-ref { - font-size: 1.5em; - font-weight: bold; -} - -.example-description { - top: 0; - position: sticky; - background: #ffffff; - font-size: 1.25em; - padding-left: 1%; - padding-right: 1%; -} - -.highlight-yaml { - padding-left: 1%; - padding-right: 1%; -} - -.combiner-list-item { - display: list-item; -} - -.toc-link { - display: block; -} diff --git a/sphinx_asdf/templates/schema.html b/sphinx_asdf/templates/schema.html index 9d33fdc..1b2ed9a 100644 --- a/sphinx_asdf/templates/schema.html +++ b/sphinx_asdf/templates/schema.html @@ -1,8 +1,4 @@ {% extends "!page.html" %} -{%- block scripts %} - {{ super() }} - -{%- endblock %} {% block footer %} {{ super() }}
      From 88f5a5b4cd271436c4596ead96749b47e29d18d9 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 16 Jan 2024 12:38:47 -0500 Subject: [PATCH 05/10] remove custom template --- sphinx_asdf/__init__.py | 2 -- sphinx_asdf/connections.py | 10 +--------- sphinx_asdf/templates/schema.html | 7 ------- 3 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 sphinx_asdf/templates/schema.html diff --git a/sphinx_asdf/__init__.py b/sphinx_asdf/__init__.py index ce7553d..072b902 100644 --- a/sphinx_asdf/__init__.py +++ b/sphinx_asdf/__init__.py @@ -4,7 +4,6 @@ from .connections import ( add_labels_to_nodes, autogenerate_schema_docs, - handle_page_context, on_build_finished, update_app_config, ) @@ -27,7 +26,6 @@ def setup(app): app.connect("builder-inited", autogenerate_schema_docs) app.connect("config-inited", update_app_config) - app.connect("html-page-context", handle_page_context) app.connect("doctree-read", add_labels_to_nodes) app.connect("build-finished", on_build_finished) diff --git a/sphinx_asdf/connections.py b/sphinx_asdf/connections.py index e98b6f3..a7a2cb6 100644 --- a/sphinx_asdf/connections.py +++ b/sphinx_asdf/connections.py @@ -13,7 +13,6 @@ from .directives import schema_def from .nodes import schema_doc -TEMPLATE_PATH = os.path.join(os.path.dirname(__file__), "templates") # docutils 0.19.0 fixed a bug in traverse/findall # https://sourceforge.net/p/docutils/bugs/448/ @@ -43,7 +42,7 @@ def find_autoasdf_directives(env, filename): builder.read_doc(docname) doctree = env.get_and_resolve_doctree(docname, builder) - return traverse(doctree, schema_def) + return traverse(doctree, cchema_def) def find_autoschema_references(app, genfiles): @@ -119,13 +118,6 @@ def update_app_config(app, config): config.html_context["sphinx_asdf_version"] = dist.version -def handle_page_context(app, pagename, templatename, ctx, doctree): - # Use custom template when rendering pages containing schema documentation. - # This allows us to selectively include bootstrap - if doctree is not None and traverse(doctree, schema_doc): - return os.path.join(TEMPLATE_PATH, "schema.html") - - def normalize_name(name): for char in [".", "_", "/"]: name = name.replace(char, "-") diff --git a/sphinx_asdf/templates/schema.html b/sphinx_asdf/templates/schema.html deleted file mode 100644 index 1b2ed9a..0000000 --- a/sphinx_asdf/templates/schema.html +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "!page.html" %} -{% block footer %} - {{ super() }} -
      - Schema documentation automatically generated by sphinx-asdf {{ sphinx_asdf_version }}. -
      -{% endblock %} From 313cbc3618d934760829a56c377cb3405efdec5c Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 16 Jan 2024 12:41:02 -0500 Subject: [PATCH 06/10] removed on_build_finished --- sphinx_asdf/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sphinx_asdf/__init__.py b/sphinx_asdf/__init__.py index 072b902..98bd379 100644 --- a/sphinx_asdf/__init__.py +++ b/sphinx_asdf/__init__.py @@ -4,7 +4,6 @@ from .connections import ( add_labels_to_nodes, autogenerate_schema_docs, - on_build_finished, update_app_config, ) from .directives import AsdfAutoschemas, AsdfSchema @@ -27,7 +26,6 @@ def setup(app): app.connect("builder-inited", autogenerate_schema_docs) app.connect("config-inited", update_app_config) app.connect("doctree-read", add_labels_to_nodes) - app.connect("build-finished", on_build_finished) static_dir = os.path.join(os.path.dirname(__file__), "static") From 8c709425843b693d04d39e3a85778598414d14cd Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 16 Jan 2024 12:41:42 -0500 Subject: [PATCH 07/10] fix typo --- sphinx_asdf/connections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx_asdf/connections.py b/sphinx_asdf/connections.py index a7a2cb6..1867070 100644 --- a/sphinx_asdf/connections.py +++ b/sphinx_asdf/connections.py @@ -42,7 +42,7 @@ def find_autoasdf_directives(env, filename): builder.read_doc(docname) doctree = env.get_and_resolve_doctree(docname, builder) - return traverse(doctree, cchema_def) + return traverse(doctree, schema_def) def find_autoschema_references(app, genfiles): From c399b21df37723e13280e9a1786d544f5cffea33 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 16 Jan 2024 13:56:41 -0500 Subject: [PATCH 08/10] switch toc_link to list --- sphinx_asdf/directives.py | 3 +-- sphinx_asdf/nodes.py | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/sphinx_asdf/directives.py b/sphinx_asdf/directives.py index b480a2e..de33d16 100644 --- a/sphinx_asdf/directives.py +++ b/sphinx_asdf/directives.py @@ -146,14 +146,13 @@ def run(self): return [docnodes] def _create_toc(self, schema): - toc = nodes.compound() + toc = nodes.bullet_list() toc.append(toc_link(text=SCHEMA_DEF_SECTION_TITLE)) if "examples" in schema: toc.append(toc_link(text=EXAMPLE_SECTION_TITLE)) if "definitions" in schema: toc.append(toc_link(text=INTERNAL_DEFINITIONS_SECTION_TITLE)) toc.append(toc_link(text=ORIGINAL_SCHEMA_SECTION_TITLE)) - toc.append(nodes.paragraph()) return toc def _markdown_to_nodes(self, text, filename): diff --git a/sphinx_asdf/nodes.py b/sphinx_asdf/nodes.py index 2e461bd..6da51b3 100644 --- a/sphinx_asdf/nodes.py +++ b/sphinx_asdf/nodes.py @@ -23,13 +23,12 @@ def depart_html(self, node): self.body.append(r"
      ") -class toc_link(nodes.line): +class toc_link(nodes.bullet_list): def visit_html(self, node): - text = node[0].title() - self.body.append(f'') + self.body.append(f'
    • {node["text"]}') def depart_html(self, node): - self.body.append("") + self.body.append("
    • ") class schema_header_title(nodes.line): From 3e003832a3b8fefd914dfb968ad154eb29221a11 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 16 Jan 2024 14:09:52 -0500 Subject: [PATCH 09/10] make schema-property-name use h4 --- sphinx_asdf/nodes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx_asdf/nodes.py b/sphinx_asdf/nodes.py index 6da51b3..7eab63a 100644 --- a/sphinx_asdf/nodes.py +++ b/sphinx_asdf/nodes.py @@ -74,10 +74,10 @@ def depart_html(self, node): class schema_property_name(nodes.line): def visit_html(self, node): - self.body.append(r'
      ') + self.body.append(r'

      ') def depart_html(self, node): - self.body.append(r"

      ") + self.body.append(r"

    ") class schema_property_details(nodes.compound): From 23433fc24d0fa0dc9a15d30510c2ac18b7361ac2 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 16 Jan 2024 14:17:34 -0500 Subject: [PATCH 10/10] fix style --- sphinx_asdf/connections.py | 3 --- sphinx_asdf/nodes.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/sphinx_asdf/connections.py b/sphinx_asdf/connections.py index 1867070..2a4e484 100644 --- a/sphinx_asdf/connections.py +++ b/sphinx_asdf/connections.py @@ -8,11 +8,8 @@ from docutils import nodes from sphinx.util import rst from sphinx.util.docutils import sphinx_domains -from sphinx.util.fileutil import copy_asset from .directives import schema_def -from .nodes import schema_doc - # docutils 0.19.0 fixed a bug in traverse/findall # https://sourceforge.net/p/docutils/bugs/448/ diff --git a/sphinx_asdf/nodes.py b/sphinx_asdf/nodes.py index 7eab63a..6bd0fbf 100644 --- a/sphinx_asdf/nodes.py +++ b/sphinx_asdf/nodes.py @@ -49,7 +49,7 @@ def depart_html(self, node): class section_header(nodes.line): def visit_html(self, node): - self.body.append(r'

    ') + self.body.append(r"

    ") def depart_html(self, node): self.body.append(headerlink_template.format(name=node[0].title(), title=""))