chiark / gitweb /
documentation/python: less responsibility on docstring-processing plugins.
authorVladimír Vondruš <mosra@centrum.cz>
Fri, 30 Aug 2019 12:59:21 +0000 (14:59 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Fri, 30 Aug 2019 16:29:56 +0000 (18:29 +0200)
Until now, the plugin was expected to fill both summary and content for
the symbol it's ccalled on. THat made plugin implementation harder than it
should be, causing a lot of code duplication and explosion of testing
effort.

Now the script simply sills in summary / content if it isn't there after
all processing and that's it. No asserts anymore.

documentation/python.py
plugins/m/sphinx.py

index 2abfbd798a26f86285e34e3890ae46613021cb53..cd757a067b0c915293c6ff062a08aa90a4378f3e 100755 (executable)
@@ -899,21 +899,17 @@ def extract_docs(state: State, external_docs, type: EntryType, path: List[str],
                         doc=doc)
 
                     # The hook could have replaced the entry with a new dict
-                    # instance, fetch it again to avoid looking at stale data below
+                    # instance, fetch it again to avoid looking at stale data
+                    # below
                     external_doc_entry = external_docs[path_signature_str]
 
-                    if not doc:
-                        # Assuming the doc were non-empty on input, if those are
-                        # empty on output, the hook should be filling both summary
-                        # and content to non-None values (so, in the worst case,
-                        # an empty string)
-                        assert external_doc_entry['summary'] is not None
-                        assert external_doc_entry['content'] is not None
-                        break
+                    # Once there's nothing left to parse, stop executing the
+                    # hooks.
+                    if not doc: break
 
                 except docutils.utils.SystemMessage:
                     logging.error("Failed to process a docstring for %s, ignoring:\n%s", path_signature_str, prettify_multiline_error(doc))
-                    doc = ''
+                    break
 
             # If there's still something left after the hooks (or there are no
             # hooks), process it as a plain unformatted text.
@@ -939,14 +935,13 @@ def extract_docs(state: State, external_docs, type: EntryType, path: List[str],
             docutils.utils.extract_options = prev_extract_options
             docutils.utils.assemble_option_dict = prev_assemble_option_dict
 
-        # We ain't got nothing (or the above parse failed). If there isn't
-        # anything supplied externally, set summary / content to an empty
-        # string so this branch isn't entered again.
-        if not doc:
-            if external_doc_entry.get('summary') is None:
-                external_doc_entry['summary'] = ''
-            if external_doc_entry.get('content') is None:
-                external_doc_entry['content'] = ''
+        # If there isn't anything supplied for summary / content even after all
+        # the processing above, set it to an empty string so this branch isn't
+        # entered again next time.
+        if external_doc_entry.get('summary') is None:
+            external_doc_entry['summary'] = ''
+        if external_doc_entry.get('content') is None:
+            external_doc_entry['content'] = ''
 
     # Render. This can't be done just once and then cached because e.g. math
     # rendering needs to ensure each SVG formula has unique IDs on each page.
index 9d37e215df503b02a840f935050bdadf19c34b43..955cc2217e07e4659dc447e5eff718ec6a0bb9a2 100755 (executable)
@@ -392,11 +392,6 @@ def consume_docstring(type, path: List[str], signature: Optional[str], doc: str)
     pub.set_source(source=source)
     pub.publish()
 
-    # Because there's no fallback to a docstring, mark everything as non-None
-    doc_output = doc_output[path_signature_str]
-    if doc_output.get('summary') is None: doc_output['summary'] = ''
-    if doc_output.get('content') is None: doc_output['content'] = ''
-
 def merge_inventories(name_map, **kwargs):
     global intersphinx_inventory