From db4cae421bff7c9b87a6692023332318d18602f1 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Thu, 21 Mar 2024 10:09:37 -0400 Subject: [PATCH] add processing on docstring for both kinds of tables --- docs/source/conf.py | 22 ++++++++++++++++++++++ src/cool_seq_tool/schemas.py | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/docs/source/conf.py b/docs/source/conf.py index 7a163670..0291e57f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -79,3 +79,25 @@ def linkcode_resolve(domain, info): # -- code block style -------------------------------------------------------- pygments_style = "default" pygements_dark_style = "monokai" + +# -- preprocess docstrings --------------------------------------------------- +from typing import List +from types import ModuleType +from sphinx.application import Sphinx +from sphinx.ext.autodoc import Options + + +def _clip_rst_tables(app: Sphinx, what: str, name: str, obj: ModuleType, options: Options, lines: List[str]): + """The ResidueMode docstring contains an RST table and an ASCII table because + the former gets omitted in IDEs like VSCode and the latter won't render properly in + Sphinx docs. This chops out the ASCII table when rendering autodocs. + """ + if what == "class" and name == "cool_seq_tool.schemas.ResidueMode": + for i in range(len(lines) -1, -1, -1): + line = lines[i] + if line.count("|") >= 8: + del lines[i] + print("Running preprocessing on ResidueMode docstring...") + +def setup(app: Sphinx): + app.connect("autodoc-process-docstring", _clip_rst_tables) diff --git a/src/cool_seq_tool/schemas.py b/src/cool_seq_tool/schemas.py index d8d2fd1e..9786579c 100644 --- a/src/cool_seq_tool/schemas.py +++ b/src/cool_seq_tool/schemas.py @@ -56,6 +56,11 @@ class ResidueMode(str, Enum): careful to define the coordinate mode of their data when calling ``cool-seq-tool`` functions. + | | C | | T | | G | | + ZERO | | 0 | | 1 | | 2 | | + RESIDUE | | 1 | | 2 | | 3 | | + INTER_RESIDUE | 0 | | 1 | | 2 | | 3 | + .. tabularcolumns:: |L|C|C|C|C|C|C|C| .. list-table:: :header-rows: 1