Skip to content

Commit b8ccde3

Browse files
authored
Merge pull request #6 from executablebooks/agoose77/maint-update-build
MAINT: update build backend to Hatch
2 parents 059b26c + 1290c49 commit b8ccde3

7 files changed

Lines changed: 90 additions & 66 deletions

File tree

.github/workflows/tests.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: tests
22

3-
on: [push, pull_request]
3+
4+
on:
5+
push:
6+
branches: [main]
7+
tags:
8+
- "v[0-9]+.[0-9]+.[0-9]+*"
9+
pull_request:
410

511
jobs:
612

@@ -9,12 +15,12 @@ jobs:
915
runs-on: ubuntu-latest
1016
strategy:
1117
matrix:
12-
python-version: [3.7, 3.8, 3.9, "3.10"]
18+
python-version: ["3.9", "3.10", "3.11", "3.12"]
1319

1420
steps:
15-
- uses: actions/checkout@v2
21+
- uses: actions/checkout@v4
1622
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v2
23+
uses: actions/setup-python@v4
1824
with:
1925
python-version: ${{ matrix.python-version }}
2026
- name: Install dependencies
@@ -34,17 +40,17 @@ jobs:
3440
runs-on: ubuntu-latest
3541
steps:
3642
- name: Checkout source
37-
uses: actions/checkout@v2
38-
- name: Set up Python 3.7
39-
uses: actions/setup-python@v2
43+
uses: actions/checkout@v4
44+
- name: Set up Python 3.11
45+
uses: actions/setup-python@v4
4046
with:
41-
python-version: 3.7
47+
python-version: 3.11
4248
- name: Build package
4349
run: |
4450
pip install wheel
4551
python setup.py sdist bdist_wheel
4652
- name: Publish
47-
uses: pypa/gh-action-pypi-publish@v1.4.2
53+
uses: pypa/gh-action-pypi-publish@v1.8.14
4854
with:
4955
user: __token__
5056
password: ${{ secrets.PYPI_API_TOKEN }}

MANIFEST.in

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

pyproject.toml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "sphinx-remove-toctrees"
7+
dynamic = ["version"]
8+
description = "Reduce your documentation build size by selectively removing toctrees from pages."
9+
readme = "README.md"
10+
license = { file = "LICENSE" }
11+
requires-python = ">=3.9"
12+
authors = [
13+
{ name = "Executable Book Project" },
14+
]
15+
classifiers = [
16+
"License :: OSI Approved :: MIT License",
17+
"Programming Language :: Python :: 3",
18+
"Programming Language :: Python :: 3 :: Only",
19+
"Programming Language :: Python :: 3.9",
20+
"Programming Language :: Python :: 3.10",
21+
"Programming Language :: Python :: 3.11",
22+
"Programming Language :: Python :: 3.12",
23+
24+
]
25+
dependencies = [
26+
"sphinx>=5",
27+
]
28+
29+
[project.optional-dependencies]
30+
code_style = [
31+
"pre-commit>=2.12",
32+
]
33+
docs = [
34+
"ipython",
35+
"myst-parser",
36+
"sphinx-book-theme",
37+
]
38+
tests = [
39+
"ipython",
40+
"myst-parser",
41+
"pytest",
42+
"sphinx-book-theme",
43+
]
44+
45+
[project.urls]
46+
Homepage = "https://github.com/executablebooks/sphinx-remove-toctrees"
47+
48+
[tool.hatch.version]
49+
path = "sphinx_remove_toctrees/__init__.py"
50+
51+
[tool.hatch.build.targets.wheel]
52+
exclude = [
53+
"/sphinx_remove_toctrees/tests/*"
54+
]

setup.cfg

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

setup.py

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

sphinx_remove_toctrees/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
logger = logging.getLogger(__name__)
1111

1212

13+
def findall(node):
14+
# findall replaces traverse in docutils v0.18
15+
# note a difference is that findall is an iterator
16+
return getattr(node, "findall", node.traverse)
17+
18+
1319
def remove_toctrees(app, env):
1420
"""Remove toctrees from pages a user provides.
1521
@@ -37,7 +43,7 @@ def remove_toctrees(app, env):
3743

3844
# Loop through all tocs and remove the ones that match our pattern
3945
for _, tocs in env.tocs.items():
40-
for toctree in tocs.traverse(addnodes.toctree):
46+
for toctree in findall(tocs)(addnodes.toctree):
4147
new_entries = []
4248
for entry in toctree.attributes.get("entries", []):
4349
if entry[1] not in to_remove:

sphinx_remove_toctrees/tests/test_build.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from shutil import copytree
44

55
from bs4 import BeautifulSoup
6-
from sphinx.testing.path import path as sphinx_path
7-
from sphinx.testing.util import SphinxTestApp
6+
from sphinx import version_info as sphinx_version_info
87

98
pytest_plugins = "sphinx.testing.fixtures"
109

@@ -13,8 +12,19 @@
1312

1413
def test_build_html(make_app, tmp_path):
1514
"""Test building the base html template and config."""
16-
copytree(path_test_doc, tmp_path / "test_doc")
17-
app = make_app(srcdir=sphinx_path(tmp_path / "test_doc"))
15+
src_dir = tmp_path / "test_doc"
16+
copytree(path_test_doc, src_dir)
17+
18+
# For compatibility with multiple versions of sphinx, convert pathlib.Path to
19+
# sphinx.testing.path.path here.
20+
if sphinx_version_info >= (7, 2):
21+
app_src_dir = src_dir
22+
else:
23+
from sphinx.testing.path import path
24+
25+
app_src_dir = path(os.fspath(src_dir))
26+
27+
app = make_app(srcdir=app_src_dir)
1828
app.build()
1929
index = tmp_path / "test_doc" / "_build" / "html" / "index.html"
2030
assert index.exists()

0 commit comments

Comments
 (0)