From c645a9d75371e52a1b8fcdf26f57cb77a95bb561 Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Wed, 19 Feb 2025 13:38:09 -0800 Subject: [PATCH 1/3] Require Sphinx 7 --- .github/workflows/test.yml | 2 +- pyproject.toml | 12 ++++++------ requirements/default.txt | 4 ++-- requirements/doc.txt | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8db3074c..1cac16cf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: os: [Ubuntu] python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] sphinx-version: - ["sphinx==6.0", "sphinx==6.2", "sphinx==7.0", "sphinx>=7.3"] + ["sphinx==7.0", "sphinx==7.4", "sphinx==8.0", "sphinx>=8.2"] include: - os: Windows python-version: "3.12" diff --git a/pyproject.toml b/pyproject.toml index 04f18d86..cdcce933 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,9 +28,9 @@ classifiers = [ 'Topic :: Documentation', ] dependencies = [ - 'sphinx>=6', + 'sphinx>=7', 'tabulate>=0.8.10', - "tomli>=1.1.0;python_version<'3.11'", + "tomli>=2.1.0;python_version<'3.11'", ] [[project.authors]] @@ -50,10 +50,10 @@ developer = [ "tomli; python_version < '3.11'", ] doc = [ - 'numpy>=1.22', - 'matplotlib>=3.5', - 'pydata-sphinx-theme>=0.13.3', - 'sphinx>=7', + 'numpy>=1.26', + 'matplotlib>=3.8', + 'pydata-sphinx-theme>=0.16.1', + 'sphinx>=8', 'intersphinx_registry', ] test = [ diff --git a/requirements/default.txt b/requirements/default.txt index 5a1986a1..4bd17e9d 100644 --- a/requirements/default.txt +++ b/requirements/default.txt @@ -1,5 +1,5 @@ # Generated via tools/generate_requirements.py and pre-commit hook. # Do not edit this file; modify pyproject.toml instead. -sphinx>=6 +sphinx>=7 tabulate>=0.8.10 -tomli>=1.1.0;python_version<'3.11' +tomli>=2.1.0;python_version<'3.11' diff --git a/requirements/doc.txt b/requirements/doc.txt index 950966b6..d7b70e7a 100644 --- a/requirements/doc.txt +++ b/requirements/doc.txt @@ -1,7 +1,7 @@ # Generated via tools/generate_requirements.py and pre-commit hook. # Do not edit this file; modify pyproject.toml instead. -numpy>=1.22 -matplotlib>=3.5 -pydata-sphinx-theme>=0.13.3 -sphinx>=7 +numpy>=1.26 +matplotlib>=3.8 +pydata-sphinx-theme>=0.16.1 +sphinx>=8 intersphinx_registry From af936a1c6ceed837964bd0bc54167524a08f878a Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Wed, 19 Feb 2025 14:49:06 -0800 Subject: [PATCH 2/3] Use node.findall (docutils 18.x) --- numpydoc/numpydoc.py | 31 +++++++------------------------ numpydoc/tests/test_full.py | 11 ++--------- 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/numpydoc/numpydoc.py b/numpydoc/numpydoc.py index a04443b3..9417c177 100644 --- a/numpydoc/numpydoc.py +++ b/numpydoc/numpydoc.py @@ -39,19 +39,6 @@ HASH_LEN = 12 -def _traverse_or_findall(node, condition, **kwargs): - """Triage node.traverse (docutils <0.18.1) vs node.findall. - - TODO: This check can be removed when the minimum supported docutils version - for numpydoc is docutils>=0.18.1 - """ - return ( - node.findall(condition, **kwargs) - if hasattr(node, "findall") - else node.traverse(condition, **kwargs) - ) - - def rename_references(app, what, name, obj, options, lines): # decorate reference numbers so that there are no duplicates # these are later undecorated in the doctree, in relabel_references @@ -92,12 +79,8 @@ def is_docstring_section(node): return False sibling_sections = itertools.chain( - _traverse_or_findall( - section_node, - is_docstring_section, - include_self=True, - descend=False, - siblings=True, + section_node.findall( + is_docstring_section, include_self=True, descend=False, siblings=True ) ) for sibling_section in sibling_sections: @@ -116,7 +99,7 @@ def is_docstring_section(node): def relabel_references(app, doc): # Change 'hash-ref' to 'ref' in label text - for citation_node in _traverse_or_findall(doc, citation): + for citation_node in doc.findall(citation): if not _is_cite_in_numpydoc_docstring(citation_node): continue label_node = citation_node[0] @@ -136,7 +119,7 @@ def matching_pending_xref(node): and node[0].astext() == f"[{ref_text}]" ) - for xref_node in _traverse_or_findall(ref.parent, matching_pending_xref): + for xref_node in ref.parent.findall(matching_pending_xref): xref_node.replace(xref_node[0], Text(f"[{new_text}]")) ref.replace(ref_text, new_text.copy()) @@ -144,14 +127,14 @@ def matching_pending_xref(node): def clean_backrefs(app, doc, docname): # only::latex directive has resulted in citation backrefs without reference known_ref_ids = set() - for ref in _traverse_or_findall(doc, reference, descend=True): + for ref in doc.findall(reference, descend=True): for id_ in ref["ids"]: known_ref_ids.add(id_) # some extensions produce backrefs to inline elements - for ref in _traverse_or_findall(doc, inline, descend=True): + for ref in doc.findall(inline, descend=True): for id_ in ref["ids"]: known_ref_ids.add(id_) - for citation_node in _traverse_or_findall(doc, citation, descend=True): + for citation_node in doc.findall(citation, descend=True): # remove backrefs to non-existent refs citation_node["backrefs"] = [ id_ for id_ in citation_node["backrefs"] if id_ in known_ref_ids diff --git a/numpydoc/tests/test_full.py b/numpydoc/tests/test_full.py index 9ab241fa..0372d15c 100644 --- a/numpydoc/tests/test_full.py +++ b/numpydoc/tests/test_full.py @@ -3,8 +3,6 @@ import shutil import pytest -from docutils import __version__ as docutils_version -from packaging import version from sphinx.application import Sphinx from sphinx.util.docutils import docutils_namespace @@ -90,14 +88,9 @@ def test_reference(sphinx_app, html_file, expected_length): with open(op.join(out_dir, *html_file)) as fid: html = fid.read() - # TODO: This check can be removed when the minimum supported docutils version - # for numpydoc is docutils>=0.18 - pattern = ( - 'role="doc-backlink"' - if version.parse(docutils_version) >= version.parse("0.18") - else 'class="fn-backref"' + reference_list = re.findall( + r'(.*)<\/a>', html ) - reference_list = re.findall(rf'(.*)<\/a>', html) assert len(reference_list) == expected_length for ref in reference_list: From 7685419bc9a77da2cce2c2e6c5d0c1ab7c603924 Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Wed, 19 Feb 2025 14:57:07 -0800 Subject: [PATCH 3/3] Fix tests --- .github/workflows/test.yml | 3 +-- pyproject.toml | 2 +- requirements/doc.txt | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1cac16cf..7c2533bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,8 +17,7 @@ jobs: matrix: os: [Ubuntu] python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] - sphinx-version: - ["sphinx==7.0", "sphinx==7.4", "sphinx==8.0", "sphinx>=8.2"] + sphinx-version: ["sphinx==7.0", "sphinx==7.3", "sphinx>=7.4"] include: - os: Windows python-version: "3.12" diff --git a/pyproject.toml b/pyproject.toml index cdcce933..25a91073 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,7 @@ doc = [ 'numpy>=1.26', 'matplotlib>=3.8', 'pydata-sphinx-theme>=0.16.1', - 'sphinx>=8', + 'sphinx>=7', 'intersphinx_registry', ] test = [ diff --git a/requirements/doc.txt b/requirements/doc.txt index d7b70e7a..805bdfeb 100644 --- a/requirements/doc.txt +++ b/requirements/doc.txt @@ -3,5 +3,5 @@ numpy>=1.26 matplotlib>=3.8 pydata-sphinx-theme>=0.16.1 -sphinx>=8 +sphinx>=7 intersphinx_registry