Skip to content

Commit ed53327

Browse files
authored
⬆️ Support Sphinx v5, drop v3 (#74)
1 parent 4cebac2 commit ed53327

File tree

8 files changed

+51
-14
lines changed

8 files changed

+51
-14
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@ jobs:
5555
file: ./coverage.xml
5656
fail_ci_if_error: true
5757

58+
tests-sphinx4:
59+
60+
strategy:
61+
matrix:
62+
os: [ubuntu-latest]
63+
python-version: ["3.7", "3.10"]
64+
65+
runs-on: ${{ matrix.os }}
66+
67+
steps:
68+
- uses: actions/checkout@v2
69+
- name: Set up Python ${{ matrix.python-version }}
70+
uses: actions/setup-python@v2
71+
with:
72+
python-version: ${{ matrix.python-version }}
73+
- name: Install dependencies
74+
run: |
75+
python -m pip install --upgrade pip
76+
pip install -e .[testing] sphinx~=4.5
77+
- name: Run pytest
78+
run: pytest
79+
5880
publish:
5981

6082
name: Publish to PyPi

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ classifiers = [
2727
]
2828
keywords = ["sphinx", "extension", "material design", "web components"]
2929
requires-python = ">=3.7"
30-
dependencies = ["sphinx>=3,<5"]
30+
dependencies = ["sphinx>=4,<6"]
3131

3232
[project.urls]
3333
Homepage = "https://github.com/executablebooks/sphinx-design"
3434
Documentation = "https://sphinx-design.readthedocs.io"
3535

3636
[project.optional-dependencies]
3737
code_style = ["pre-commit~=2.12"]
38-
rtd = ["myst-parser~=0.17.0"]
38+
rtd = ["myst-parser~=0.18.0"]
3939
testing = [
40-
"myst-parser~=0.17.0",
41-
"pytest~=6.2",
40+
"myst-parser~=0.18.0",
41+
"pytest~=7.1",
4242
"pytest-cov",
4343
"pytest-regressions",
4444
]
45-
theme_furo = ["furo==2022.04.07"]
46-
theme_pydata = ["pydata-sphinx-theme~=0.8.1"]
45+
theme_furo = ["furo>=2022.06.04,<2022.07"]
46+
theme_pydata = ["pydata-sphinx-theme~=0.9.0"]
4747
theme_rtd = ["sphinx-rtd-theme~=1.0"]
4848
theme_sbt = ["sphinx-book-theme~=0.3.0"]
4949

sphinx_design/_compat.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Helpers for cross compatibility across dependency versions."""
2+
from typing import Callable, Iterable
3+
4+
from docutils.nodes import Element
5+
6+
7+
def findall(node: Element) -> Callable[..., Iterable[Element]]:
8+
"""Iterate through"""
9+
# findall replaces traverse in docutils v0.18
10+
# note a difference is that findall is an iterator
11+
return getattr(node, "findall", node.traverse)

sphinx_design/cards.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from sphinx.util.docutils import SphinxDirective
1010
from sphinx.util.logging import getLogger
1111

12+
from ._compat import findall
1213
from .shared import (
1314
WARNING_TYPE,
1415
PassthroughTextElement,
@@ -229,11 +230,11 @@ def _create_component(
229230
@staticmethod
230231
def add_card_child_classes(node):
231232
"""Add classes to specific child nodes."""
232-
for para in node.traverse(nodes.paragraph):
233+
for para in findall(node)(nodes.paragraph):
233234
para["classes"] = ([] if "classes" not in para else para["classes"]) + [
234235
"sd-card-text"
235236
]
236-
# for title in node.traverse(nodes.title):
237+
# for title in findall(node)(nodes.title):
237238
# title["classes"] = ([] if "classes" not in title else title["classes"]) + [
238239
# "sd-card-title"
239240
# ]

sphinx_design/dropdown.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
margin_option,
1515
)
1616

17+
from ._compat import findall
1718
from .icons import get_octicon, list_octicons
1819

1920

@@ -217,7 +218,7 @@ def run(self):
217218
children=body_children,
218219
)
219220
if use_card:
220-
for para in body_node.traverse(nodes.paragraph):
221+
for para in findall(body_node)(nodes.paragraph):
221222
para["classes"] = ([] if "classes" in para else para["classes"]) + [
222223
"sd-card-text"
223224
]

sphinx_design/extension.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from sphinx.util.docutils import SphinxDirective
1111

1212
from . import compiled as static_module
13+
from ._compat import findall
1314
from .article_info import setup_article_info
1415
from .badges_buttons import setup_badges_and_buttons
1516
from .cards import setup_cards
@@ -143,15 +144,15 @@ class AddFirstTitleCss(SphinxTransform):
143144

144145
def apply(self):
145146
hide = False
146-
for docinfo in self.document.traverse(nodes.docinfo):
147-
for name in docinfo.traverse(nodes.field_name):
147+
for docinfo in findall(self.document)(nodes.docinfo):
148+
for name in findall(docinfo)(nodes.field_name):
148149
if name.astext() == "sd_hide_title":
149150
hide = True
150151
break
151152
break
152153
if not hide:
153154
return
154-
for section in self.document.traverse(nodes.section):
155+
for section in findall(self.document)(nodes.section):
155156
if isinstance(section.children[0], nodes.title):
156157
if "classes" in section.children[0]:
157158
section.children[0]["classes"].append("sd-d-none")

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sphinx.testing.path import path as sphinx_path
88
from sphinx.testing.util import SphinxTestApp
99

10+
from sphinx_design._compat import findall
1011
from sphinx_design.tabs import TabSetHtmlTransform
1112

1213
pytest_plugins = "sphinx.testing.fixtures"
@@ -46,7 +47,7 @@ def get_doctree(
4647
if post_transforms:
4748
self.app.env.apply_post_transforms(doctree, docname)
4849
# make source path consistent for test comparisons
49-
for node in doctree.traverse(include_self=True):
50+
for node in findall(doctree)(include_self=True):
5051
if not ("source" in node and node["source"]):
5152
continue
5253
node["source"] = Path(node["source"]).relative_to(self.src_path).as_posix()

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ envlist = py38
99
[testenv]
1010
usedevelop = true
1111

12-
[testenv:py{36,37,38,39}]
12+
[testenv:py{37,38,39,310}]
1313
description = Run unit tests with this Python version
1414
extras =
1515
testing

0 commit comments

Comments
 (0)