From 2a2179f396e21d77fd39d58eb5c55020338e4125 Mon Sep 17 00:00:00 2001 From: neofelis2X Date: Thu, 23 Jan 2025 02:51:35 +0100 Subject: [PATCH] Docs: update postprocessing to account for sphinx v8 --- sphinxtools/constants.py | 8 +++--- sphinxtools/postprocess.py | 52 +++++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/sphinxtools/constants.py b/sphinxtools/constants.py index 7ee45bfe..70debebd 100644 --- a/sphinxtools/constants.py +++ b/sphinxtools/constants.py @@ -169,15 +169,17 @@ RE_KEEP_SPACES = re.compile(r'(\s+)') # A list of things used in the post-processing of the HTML files generated by Sphinx # This list is used only to insert a HTML horizontal line (
) after each method/function # description -HTML_REPLACE = ['module', 'function', 'method', 'class', 'classmethod', 'staticmethod', 'attribute'] +HTML_REPLACE = ['module', 'function', 'py function', 'class', 'py class', + 'method', 'py method', 'classmethod', 'staticmethod', + 'attribute', 'py attribute'] # Today's date representation for the Sphinx HTML docs TODAY = datetime.date.today().strftime('%d %B %Y') # Inheritance diagram external hyperlinks -PYTHON_DOCS = 'http://docs.python.org/library/' -NUMPY_DOCS = 'http://docs.scipy.org/doc/numpy/reference/generated/' +PYTHON_DOCS = 'https://docs.python.org/3/library/' +NUMPY_DOCS = 'https://numpy.org/doc/stable/reference/' EXTERN_INHERITANCE = {'UserDict.' : PYTHON_DOCS, 'ctypes.' : PYTHON_DOCS, diff --git a/sphinxtools/postprocess.py b/sphinxtools/postprocess.py index 3b33de61..43848fca 100644 --- a/sphinxtools/postprocess.py +++ b/sphinxtools/postprocess.py @@ -657,22 +657,27 @@ def postProcess(folder, options): for indx, enum in enumerate(enum_base): html_file = os.path.split(enum_files[indx])[1] base = enum.split('.')[-1] - new = '(%s)'%(html_file, base, base) - enum_dict['(%s)'%enum] = new + new = '(%s)' % (html_file, base, base) + enum_dict['(%s)' % enum] = new for filename in fileNames: if "genindex" in filename or "modindex" in filename: continue - methods_done = properties_done = False + methods_done = attr_done = fn_done = False with textfile_open(filename, "rt") as fid: orig_text = text = fid.read() - text = text.replace('Overloaded Implementations:', 'Overloaded Implementations:') + text = text.replace('Overloaded Implementations:', + 'Overloaded Implementations:') + for item in HTML_REPLACE: - if item != 'class': - text = text.replace('
'%item, '\n

\n
'%item) + if item in ('class', 'py class'): + continue + + text = text.replace('
' % item, + '

' % item) newtext = '' splitted_text = text.splitlines() @@ -684,19 +689,32 @@ def postProcess(folder, options): line = line.replace('–

', '– ') line = line.replace('

', '') - if line.strip() == '

' or line.strip() == '


': - next_line = splitted_text[index+1] - stripline = next_line.strip() + if not fn_done and \ + line.strip() in ('

', + '

'): - # replace the
with a new headline for the first method or first property - if (stripline == '
' or stripline == '
' \ - or stripline == '
') and not methods_done: - line = '\n

Methods

\n' - methods_done = True + line = line[8:] + fn_done = True - elif stripline == '
' and not properties_done: - line = '\n

Properties

\n' - properties_done = True + if not methods_done and \ + line.strip() in ('

', + '

', + '

', + '

'): + + line = '\n
\n

Methods

\n' + line[8:] + methods_done = True + + if not attr_done and \ + line.strip() in ('

', + '

'): + + line = '\n
\n

Properties

\n' + line[8:] + attr_done = True newtext += line + '\n'