From 53c79754e2d85edc448b3516c793b3c588c42a74 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Aug 2026 16:39:41 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v6.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.5.0...v6.0.0) - [github.com/astral-sh/ruff-pre-commit: v0.1.7 → v0.16.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.7...v0.16.1) - [github.com/pre-commit/mirrors-mypy: v1.7.1 → v2.3.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.7.1...v2.3.0) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index df8e78c..2938ca7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ exclude: > repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v6.0.0 hooks: - id: check-json - id: check-yaml @@ -19,13 +19,13 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.7 + rev: v0.16.1 hooks: - id: ruff args: ["--fix", "--show-fixes"] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.7.1 + rev: v2.3.0 hooks: - id: mypy From a95e4f25a7db67026c113ba02ad3ef37b1c0035c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Aug 2026 16:41:41 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sphinx_external_toc/_compat.py | 5 +++-- sphinx_external_toc/api.py | 4 ++-- sphinx_external_toc/collectors.py | 3 ++- sphinx_external_toc/parsing.py | 4 ++-- sphinx_external_toc/tools.py | 15 ++++++++------- tests/test_cli.py | 2 +- tests/test_collectors.py | 18 ++++++++++-------- tests/test_compat.py | 3 ++- 8 files changed, 30 insertions(+), 24 deletions(-) diff --git a/sphinx_external_toc/_compat.py b/sphinx_external_toc/_compat.py index 1c99f25..c2428f1 100644 --- a/sphinx_external_toc/_compat.py +++ b/sphinx_external_toc/_compat.py @@ -4,8 +4,9 @@ import dataclasses as dc import re +from re import Pattern import sys -from typing import Any, Callable, Pattern, Type +from typing import Any, Callable, Type from docutils.nodes import Element @@ -93,7 +94,7 @@ def matches_re(regex: str | Pattern, flags: int = 0) -> ValidatorType: if fullmatch: match_func = pattern.fullmatch else: # Python 2 fullmatch emulation (https://bugs.python.org/issue16203) - pattern = re.compile(r"(?:{})\Z".format(pattern.pattern), pattern.flags) + pattern = re.compile(rf"(?:{pattern.pattern})\Z", pattern.flags) match_func = pattern.match def _validator(inst, attr, value): diff --git a/sphinx_external_toc/api.py b/sphinx_external_toc/api.py index 3072292..347d317 100644 --- a/sphinx_external_toc/api.py +++ b/sphinx_external_toc/api.py @@ -1,8 +1,8 @@ """Defines the `SiteMap` object, for storing the parsed ToC.""" -from collections.abc import MutableMapping +from collections.abc import Iterator, MutableMapping from dataclasses import asdict, dataclass -from typing import Any, Dict, Iterator, List, Optional, Set, Union +from typing import Any, Dict, List, Optional, Set, Union from ._compat import ( DC_SLOTS, diff --git a/sphinx_external_toc/collectors.py b/sphinx_external_toc/collectors.py index ac58d11..273410b 100644 --- a/sphinx_external_toc/collectors.py +++ b/sphinx_external_toc/collectors.py @@ -1,5 +1,6 @@ -import gc import copy +import gc + from docutils import nodes from sphinx import addnodes as sphinxnodes from sphinx.environment.collectors.toctree import TocTreeCollector diff --git a/sphinx_external_toc/parsing.py b/sphinx_external_toc/parsing.py index 64bfa0f..674903a 100644 --- a/sphinx_external_toc/parsing.py +++ b/sphinx_external_toc/parsing.py @@ -1,9 +1,9 @@ """Parse the ToC to a `SiteMap` object.""" -from collections.abc import Mapping +from collections.abc import Mapping, Sequence from dataclasses import dataclass, fields from pathlib import Path -from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Union +from typing import Any, Dict, List, Optional, Set, Tuple, Union import yaml diff --git a/sphinx_external_toc/tools.py b/sphinx_external_toc/tools.py index a47342f..d61795b 100644 --- a/sphinx_external_toc/tools.py +++ b/sphinx_external_toc/tools.py @@ -1,9 +1,10 @@ -import re -import shutil +from collections.abc import Mapping, Sequence from fnmatch import fnmatch from itertools import chain from pathlib import Path, PurePosixPath -from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union +import re +import shutil +from typing import Any, Dict, List, Optional, Tuple, Union import yaml @@ -61,11 +62,11 @@ def create_site_from_toc( for docname in chain(site_map, additional_files): # create document filename = docname - if not any(docname.endswith(ext) for ext in {".rst", ".md"}): + if not any(docname.endswith(ext) for ext in (".rst", ".md")): filename += default_ext docpath = root_path.joinpath(PurePosixPath(filename)) if docpath.exists() and not overwrite: - raise IOError(f"Path already exists: {docpath}") + raise OSError(f"Path already exists: {docpath}") docpath.parent.mkdir(parents=True, exist_ok=True) content = [] @@ -116,7 +117,7 @@ def create_site_map_from_path( root_path, suffixes, default_index, ignore_matches ) if not root_index: - raise IOError(f"path does not contain a root file: {root_path}") + raise OSError(f"path does not contain a root file: {root_path}") # create root item and child folders root_item, indexed_folders = _doc_item_from_path( @@ -232,7 +233,7 @@ def _assess_folder( :returns: (index file name, other file names, folders) """ if not folder.is_dir(): - raise IOError(f"path must be a directory: {folder}") + raise OSError(f"path must be a directory: {folder}") def _strip_suffix(name: str) -> str: for suffix in suffixes: diff --git a/tests/test_cli.py b/tests/test_cli.py index a8f3e1a..b86577f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2,8 +2,8 @@ from pathlib import Path from typing import List -import pytest from click.testing import CliRunner +import pytest from sphinx_external_toc import __version__ from sphinx_external_toc.cli import ( diff --git a/tests/test_collectors.py b/tests/test_collectors.py index 9c7fd7c..9f346ac 100644 --- a/tests/test_collectors.py +++ b/tests/test_collectors.py @@ -1,10 +1,12 @@ -import pytest from unittest.mock import Mock, patch + +import pytest +from sphinx.environment.collectors.toctree import TocTreeCollector + from sphinx_external_toc.collectors import ( TocTreeCollectorWithStyles, disable_builtin_toctree_collector, ) -from sphinx.environment.collectors.toctree import TocTreeCollector class TestDisableBuiltinToctreeCollector: @@ -343,9 +345,9 @@ def test_to_roman_comprehensive(self, collector): ] for num, expected in test_cases: result = collector._TocTreeCollectorWithStyles__to_roman(num) - assert ( - result == expected - ), f"Failed for {num}: got {result}, expected {expected}" + assert result == expected, ( + f"Failed for {num}: got {result}, expected {expected}" + ) def test_to_alpha_comprehensive(self, collector): """Test alphabetical conversion comprehensively.""" @@ -364,9 +366,9 @@ def test_to_alpha_comprehensive(self, collector): ] for num, expected in test_cases: result = collector._TocTreeCollectorWithStyles__to_alpha(num) - assert ( - result == expected - ), f"Failed for {num}: got {result}, expected {expected}" + assert result == expected, ( + f"Failed for {num}: got {result}, expected {expected}" + ) def test_disable_builtin_multiple_collectors(self): """Test disabling with multiple collectors in memory.""" diff --git a/tests/test_compat.py b/tests/test_compat.py index 5f91006..831e460 100644 --- a/tests/test_compat.py +++ b/tests/test_compat.py @@ -1,6 +1,7 @@ """Tests for sphinx_external_toc._compat module.""" import pytest + from sphinx_external_toc import _compat @@ -248,8 +249,8 @@ def test_compat_module_dict(self): def test_compat_import_error_handling(self): """Test that import errors are handled gracefully.""" - import sys import importlib + import sys if "sphinx_external_toc._compat" in sys.modules: del sys.modules["sphinx_external_toc._compat"]