Skip to content

Commit

Permalink
Merge pull request #6 from executablebooks/agoose77/maint-update-build
Browse files Browse the repository at this point in the history
MAINT: update build backend to Hatch
  • Loading branch information
agoose77 committed Mar 22, 2024
2 parents 059b26c + 1290c49 commit b8ccde3
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 66 deletions.
24 changes: 15 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -9,12 +15,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
Expand All @@ -34,17 +40,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 }}
2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

54 changes: 54 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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/*"
]
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

48 changes: 0 additions & 48 deletions setup.py

This file was deleted.

8 changes: 7 additions & 1 deletion sphinx_remove_toctrees/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 14 additions & 4 deletions sphinx_remove_toctrees/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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()
Expand Down

0 comments on commit b8ccde3

Please sign in to comment.