Skip to content

Commit 26c7b27

Browse files
authored
MAINT: update build and CI for Sphinx 7 (#65)
* maint: update build and CI * maint: revert version to current * maint: more CI fixes,pre-commit * maint: fix quoting * maint: update pytest * maint: fix spec * maint: fix CI arg * wip: improving deprecations * maint: add type hints * fix: patch regression * maint: run pre-commit * fix: copy doctree node to avoid mutation * test: drop original_uri, translation_progress * test: fix tests * test: fix Sphinx 7 incompat * maint: run pre-commit
1 parent 9357fbb commit 26c7b27

21 files changed

+768
-157
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ jobs:
1212
pre-commit:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v2
16-
- name: Set up Python 3.9
17-
uses: actions/setup-python@v1
15+
- uses: actions/checkout@v4
16+
- name: Set up Python 3.11
17+
uses: actions/setup-python@v4
1818
with:
19-
python-version: 3.9
20-
- uses: pre-commit/action@v2.0.0
19+
python-version: "3.11"
20+
- uses: pre-commit/action@v3.0.1
2121

2222
tests:
2323
runs-on: ubuntu-latest
2424
strategy:
2525
matrix:
26-
python-version: [3.8, 3.9]
26+
python-version: ["3.9", "3.10", "3.11", "3.12"]
2727
steps:
28-
- uses: actions/checkout@v2
28+
- uses: actions/checkout@v4
2929
- name: Set up Python ${{ matrix.python-version }}
30-
uses: actions/setup-python@v1
30+
uses: actions/setup-python@v4
3131
with:
3232
python-version: ${{ matrix.python-version }}
3333
- name: Install dependencies
@@ -36,14 +36,14 @@ jobs:
3636
pip install -e.[testing]
3737
- name: Run pytest
3838
run: |
39-
pytest --duration=10 --cov=sphinx_exercise --cov-report=xml --cov-report=term-missing
39+
pytest --durations=10 --cov=sphinx_exercise --cov-report=xml --cov-report=term-missing
4040
- name: Create cov
4141
run: coverage xml
4242
- name: Upload to Codecov
43-
if: matrix.python-version == 3.8
44-
uses: codecov/codecov-action@v1
43+
if: matrix.python-version == '3.11'
44+
uses: codecov/codecov-action@v4
4545
with:
46-
name: sphinx-exercise-pytest-py3.8
46+
name: sphinx-exercise-pytest-py3.11
4747
flags: pytests
4848
file: ./coverage.xml
4949
fail_ci_if_error: true
@@ -52,11 +52,11 @@ jobs:
5252
name: Documentation build
5353
runs-on: ubuntu-latest
5454
steps:
55-
- uses: actions/checkout@v2
56-
- name: Set up Python 3.9
57-
uses: actions/setup-python@v1
55+
- uses: actions/checkout@v4
56+
- name: Set up Python 3.11
57+
uses: actions/setup-python@v4
5858
with:
59-
python-version: 3.9
59+
python-version: "3.11"
6060
- name: Install dependencies
6161
run: |
6262
python -m pip install --upgrade pip
@@ -74,15 +74,15 @@ jobs:
7474
runs-on: ubuntu-latest
7575
steps:
7676
- name: Checkout source
77-
uses: actions/checkout@v2
78-
- name: Set up Python 3.9
79-
uses: actions/setup-python@v1
77+
uses: actions/checkout@v4
78+
- name: Set up Python 3.11
79+
uses: actions/setup-python@v4
8080
with:
81-
python-version: 3.9
81+
python-version: "3.11"
8282
- name: Build package
8383
run: |
84-
pip install wheel
85-
python setup.py bdist_wheel sdist
84+
pip install wheel build
85+
python -m build
8686
- name: Publish
8787
uses: pypa/[email protected]
8888
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ dist/
1313
coverage.*
1414
coverage.xml
1515
.tox/
16+
.venv

.pre-commit-config.yaml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@ repos:
2222
- id: end-of-file-fixer
2323
- id: trailing-whitespace
2424

25-
- repo: https://github.com/PyCQA/flake8
26-
rev: 5.0.4
25+
- repo: https://github.com/astral-sh/ruff-pre-commit
26+
rev: v0.1.4
2727
hooks:
28-
- id: flake8
29-
30-
- repo: https://github.com/psf/black
31-
rev: 22.8.0
32-
hooks:
33-
- id: black
28+
- id: ruff
29+
args: ["--fix", "--show-fixes"]
30+
- id: ruff-format

MANIFEST.in

Lines changed: 0 additions & 11 deletions
This file was deleted.

pyproject.toml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "sphinx-exercise"
7+
dynamic = ["version"]
8+
description = "A Sphinx extension for producing exercises and solutions."
9+
readme = "README.md"
10+
license = { file = "LICENSE" }
11+
requires-python = ">=3.9"
12+
authors = [
13+
{ name = "QuantEcon", email = "[email protected]" },
14+
]
15+
classifiers = [
16+
"Development Status :: 4 - Beta",
17+
"Environment :: Plugins",
18+
"Environment :: Web Environment",
19+
"Framework :: Sphinx :: Extension",
20+
"Intended Audience :: Developers",
21+
"License :: OSI Approved :: MIT License",
22+
"Natural Language :: English",
23+
"Operating System :: OS Independent",
24+
"Programming Language :: Python",
25+
"Programming Language :: Python :: 3.9",
26+
"Programming Language :: Python :: 3.10",
27+
"Programming Language :: Python :: 3.11",
28+
"Programming Language :: Python :: 3.12",
29+
"Topic :: Documentation",
30+
"Topic :: Documentation :: Sphinx",
31+
"Topic :: Software Development :: Documentation",
32+
"Topic :: Text Processing",
33+
"Topic :: Utilities",
34+
]
35+
dependencies = [
36+
"sphinx-book-theme",
37+
"sphinx>=5",
38+
]
39+
40+
[project.optional-dependencies]
41+
all = [
42+
"sphinx-exercise[code_style]",
43+
"sphinx-exercise[rtd]",
44+
"sphinx-exercise[testing]"
45+
]
46+
code_style = [
47+
"black",
48+
"flake8<3.8.0,>=3.7.0",
49+
"pre-commit",
50+
]
51+
rtd = [
52+
"myst-nb~=1.0.0",
53+
"sphinx-book-theme",
54+
"sphinx>=5,<8",
55+
]
56+
testing = [
57+
"beautifulsoup4",
58+
"coverage",
59+
"matplotlib",
60+
"myst-nb~=1.0.0",
61+
"pytest-cov",
62+
"pytest-regressions",
63+
"pytest~=8.0.0",
64+
"sphinx>=5,<8",
65+
"texsoup",
66+
]
67+
68+
[project.urls]
69+
Homepage = "https://github.com/executablebooks/sphinx-exercise"
70+
Source = "https://github.com/executablebooks/sphinx-exercise"
71+
Tracker = "https://github.com/executablebooks/sphinx-exercise/issues"
72+
73+
[tool.hatch.version]
74+
path = "sphinx_exercise/__init__.py"

setup.py

Lines changed: 0 additions & 81 deletions
This file was deleted.

sphinx_exercise/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
:license: MIT, see LICENSE for details.
88
"""
99

10+
__version__ = "0.4.1"
11+
12+
1013
from pathlib import Path
1114
from typing import Any, Dict, Set, Union, cast
1215
from sphinx.config import Config
@@ -17,6 +20,7 @@
1720
from sphinx.util import logging
1821
from sphinx.util.fileutil import copy_asset
1922

23+
from ._compat import findall
2024
from .directive import (
2125
ExerciseDirective,
2226
ExerciseStartDirective,
@@ -129,7 +133,7 @@ def doctree_read(app: Sphinx, document: Node) -> None:
129133
domain = cast(StandardDomain, app.env.get_domain("std"))
130134

131135
# Traverse sphinx-exercise nodes
132-
for node in document.traverse():
136+
for node in findall(document):
133137
if is_extension_node(node):
134138
name = node.get("names", [])[0]
135139
label = document.nameids[name]
@@ -140,7 +144,6 @@ def doctree_read(app: Sphinx, document: Node) -> None:
140144

141145

142146
def setup(app: Sphinx) -> Dict[str, Any]:
143-
144147
app.add_config_value("hide_solutions", False, "env")
145148

146149
app.connect("config-inited", init_numfig) # event order - 1

sphinx_exercise/_compat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from docutils.nodes import Element
2+
from typing import Iterator
3+
4+
5+
def findall(node: Element, *args, **kwargs) -> Iterator[Element]:
6+
# findall replaces traverse in docutils v0.18
7+
# note a difference is that findall is an iterator
8+
impl = getattr(node, "findall", node.traverse)
9+
return iter(impl(*args, **kwargs))

sphinx_exercise/directive.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ class : str,
8888
}
8989

9090
def run(self) -> List[Node]:
91-
9291
self.defaults = {"title_text": "Exercise"}
9392
self.serial_number = self.env.new_serialno()
9493

@@ -160,7 +159,10 @@ def run(self) -> List[Node]:
160159
self.env.sphinx_exercise_registry[label] = {
161160
"type": self.name,
162161
"docname": self.env.docname,
163-
"node": node,
162+
# Copy the node so that the post transforms do not modify this original state
163+
# Prior to Sphinx 6.1.0, the doctree was not cached, and Sphinx loaded a new copy
164+
# c.f. https://github.com/sphinx-doc/sphinx/commit/463a69664c2b7f51562eb9d15597987e6e6784cd
165+
"node": node.deepcopy(),
164166
}
165167

166168
# TODO: Could tag this as Hidden to prevent the cell showing
@@ -214,7 +216,6 @@ class : str,
214216
solution_node = solution_node
215217

216218
def run(self) -> List[Node]:
217-
218219
self.defaults = {"title_text": "Solution to"}
219220
target_label = self.arguments[0]
220221
self.serial_number = self.env.new_serialno()

sphinx_exercise/latex.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class LaTeXMarkup(object):
5-
65
CR = "\n"
76

87
def visit_admonition(self):

0 commit comments

Comments
 (0)