From 2eb2317dc883799f61fc03301da651e4fcb75d95 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Fri, 22 Mar 2024 10:35:37 +0000 Subject: [PATCH 1/5] chore: update build backend --- MANIFEST.in | 2 -- setup.cfg | 2 -- setup.py | 48 ------------------------------------------------ 3 files changed, 52 deletions(-) delete mode 100644 MANIFEST.in delete mode 100755 setup.cfg delete mode 100644 setup.py diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 4c90285..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -graft docs/ -prune docs/_build diff --git a/setup.cfg b/setup.cfg deleted file mode 100755 index 0c9e0fc..0000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[metadata] -license_file = LICENSE diff --git a/setup.py b/setup.py deleted file mode 100644 index ce8594c..0000000 --- a/setup.py +++ /dev/null @@ -1,48 +0,0 @@ -import os -from pathlib import Path - -from setuptools import setup, find_packages - -with open("./README.md") as ff: - readme_text = ff.read() - -# Parse version -init = Path(__file__).parent.joinpath("sphinx_remove_toctrees", "__init__.py") -for line in init.read_text().split("\n"): - if line.startswith("__version__ ="): - break -version = line.split(" = ")[-1].strip('"') - -docs_requirements = [ - "ipython", - "sphinx-book-theme", - "myst-parser", -] - -setup( - name="sphinx-remove-toctrees", - version=version, - description="Reduce your documentation build size by selectively removing toctrees from pages.", - long_description=readme_text, - long_description_content_type="text/markdown", - author="Executable Book Project", - url="https://github.com/executablebooks/sphinx-remove-toctrees", - license="MIT License", - packages=find_packages(), - classifiers=[ - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3 :: Only", - ], - python_requires=">=3.6", - install_requires=["sphinx>=1.8"], - extras_require={ - "code_style": ["pre-commit==2.12.1"], - "docs": docs_requirements, - "tests": docs_requirements + ["pytest",], - }, -) From 690884535b306201a0813212faaabc7de197c6d0 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Fri, 22 Mar 2024 10:40:41 +0000 Subject: [PATCH 2/5] fix: sphinx 7 --- sphinx_remove_toctrees/__init__.py | 8 +++++++- sphinx_remove_toctrees/tests/test_build.py | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/sphinx_remove_toctrees/__init__.py b/sphinx_remove_toctrees/__init__.py index 8db6def..a1882ac 100644 --- a/sphinx_remove_toctrees/__init__.py +++ b/sphinx_remove_toctrees/__init__.py @@ -10,6 +10,12 @@ logger = logging.getLogger(__name__) +def findall(node): + # findall replaces traverse in docutils v0.18 + # note a difference is that findall is an iterator + return getattr(node, "findall", node.traverse) + + def remove_toctrees(app, env): """Remove toctrees from pages a user provides. @@ -37,7 +43,7 @@ def remove_toctrees(app, env): # Loop through all tocs and remove the ones that match our pattern for _, tocs in env.tocs.items(): - for toctree in tocs.traverse(addnodes.toctree): + for toctree in findall(tocs)(addnodes.toctree): new_entries = [] for entry in toctree.attributes.get("entries", []): if entry[1] not in to_remove: diff --git a/sphinx_remove_toctrees/tests/test_build.py b/sphinx_remove_toctrees/tests/test_build.py index 5d7ee71..feee9cd 100644 --- a/sphinx_remove_toctrees/tests/test_build.py +++ b/sphinx_remove_toctrees/tests/test_build.py @@ -3,8 +3,7 @@ from shutil import copytree from bs4 import BeautifulSoup -from sphinx.testing.path import path as sphinx_path -from sphinx.testing.util import SphinxTestApp +from sphinx import version_info as sphinx_version_info pytest_plugins = "sphinx.testing.fixtures" @@ -13,8 +12,19 @@ def test_build_html(make_app, tmp_path): """Test building the base html template and config.""" - copytree(path_test_doc, tmp_path / "test_doc") - app = make_app(srcdir=sphinx_path(tmp_path / "test_doc")) + src_dir = tmp_path / "test_doc" + copytree(path_test_doc, src_dir) + + # For compatibility with multiple versions of sphinx, convert pathlib.Path to + # sphinx.testing.path.path here. + if sphinx_version_info >= (7, 2): + app_src_dir = src_dir + else: + from sphinx.testing.path import path + + app_src_dir = path(os.fspath(src_dir)) + + app = make_app(srcdir=app_src_dir) app.build() index = tmp_path / "test_doc" / "_build" / "html" / "index.html" assert index.exists() From 64ab67ee209fbc4fab3989c51a5a491ec776520d Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Fri, 22 Mar 2024 10:43:24 +0000 Subject: [PATCH 3/5] ci: fix workflows --- .github/workflows/tests.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fdcd698..6fd362c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,12 +9,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9, "3.10"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Install dependencies @@ -34,17 +34,17 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout source - uses: actions/checkout@v2 - - name: Set up Python 3.7 - uses: actions/setup-python@v2 + uses: actions/checkout@v4 + - name: Set up Python 3.11 + uses: actions/setup-python@v4 with: - python-version: 3.7 + python-version: 3.11 - name: Build package run: | pip install wheel python setup.py sdist bdist_wheel - name: Publish - uses: pypa/gh-action-pypi-publish@v1.4.2 + uses: pypa/gh-action-pypi-publish@v1.8.14 with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} From 6c841697ad8b1bb6ceabd4f99353e3612ff04aa4 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Fri, 22 Mar 2024 10:44:12 +0000 Subject: [PATCH 4/5] chore: add pyproject.toml --- pyproject.toml | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f88f6e9 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,54 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "sphinx-remove-toctrees" +dynamic = ["version"] +description = "Reduce your documentation build size by selectively removing toctrees from pages." +readme = "README.md" +license = { file = "LICENSE" } +requires-python = ">=3.9" +authors = [ + { name = "Executable Book Project" }, +] +classifiers = [ + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + +] +dependencies = [ + "sphinx>=5", +] + +[project.optional-dependencies] +code_style = [ + "pre-commit>=2.12", +] +docs = [ + "ipython", + "myst-parser", + "sphinx-book-theme", +] +tests = [ + "ipython", + "myst-parser", + "pytest", + "sphinx-book-theme", +] + +[project.urls] +Homepage = "https://github.com/executablebooks/sphinx-remove-toctrees" + +[tool.hatch.version] +path = "sphinx_remove_toctrees/__init__.py" + +[tool.hatch.build.targets.wheel] +exclude = [ + "/sphinx_remove_toctrees/tests/*" +] From 1290c49935ff2b0040999625ee8d9a889981a981 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Fri, 22 Mar 2024 10:44:50 +0000 Subject: [PATCH 5/5] ci: run on push to main, release tag, or PR --- .github/workflows/tests.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6fd362c..348e7cf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,6 +1,12 @@ name: tests -on: [push, pull_request] + +on: + push: + branches: [main] + tags: + - "v[0-9]+.[0-9]+.[0-9]+*" + pull_request: jobs: