Skip to content

Commit 229e3e3

Browse files
committed
Fix pre-commit warnings
1 parent 16e0160 commit 229e3e3

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

src/extensions/score_any_folder/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
Misconfigured pairs (absolute paths, non-symlink path at the target location)
3636
are logged as errors and skipped.
3737
"""
38+
3839
from pathlib import Path
3940

4041
from sphinx.application import Sphinx
4142
from sphinx.util.logging import getLogger
4243

4344
logger = getLogger(__name__)
4445

46+
_APP_ATTRIBUTE = "_score_any_folder_created_links"
4547

4648
def setup(app: Sphinx) -> dict[str, str | bool]:
4749
app.add_config_value("score_any_folder_mapping", default={}, rebuild="env")
@@ -102,13 +104,13 @@ def _create_symlinks(app: Sphinx) -> None:
102104
created_links.add(link)
103105
logger.debug("score_any_folder: created symlink %s -> %s", link, source)
104106

105-
setattr(app, "_score_any_folder_created_links", created_links)
107+
setattr(app, _APP_ATTRIBUTE, created_links)
106108

107109

108110
def _cleanup_symlinks(app: Sphinx, exception: Exception | None) -> None:
109111
del exception
110112

111-
created_links = getattr(app, "_score_any_folder_created_links", set())
113+
created_links: set[Path] = getattr(app, _APP_ATTRIBUTE, set())
112114
for link in created_links:
113115
if not link.is_symlink():
114116
continue

src/extensions/score_any_folder/tests/test_score_any_folder.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def make_sphinx_app(
5454

5555
def _factory(mapping: dict[str, str]) -> SphinxTestApp:
5656
(docs_dir / "conf.py").write_text(
57-
f'extensions = ["score_any_folder"]\n'
57+
'extensions = ["score_any_folder"]\n'
5858
f"score_any_folder_mapping = {mapping!r}\n"
5959
)
6060
(docs_dir / "index.rst").write_text("Root\n====\n")
@@ -69,7 +69,9 @@ def _factory(mapping: dict[str, str]) -> SphinxTestApp:
6969

7070

7171
def test_symlink_exposes_files_at_target_path(
72-
make_sphinx_app: Callable, docs_dir: Path, tmp_path: Path
72+
make_sphinx_app: Callable[[dict[str, str]], SphinxTestApp],
73+
docs_dir: Path,
74+
tmp_path: Path,
7375
) -> None:
7476
"""Files in the source directory are readable via the symlinked target path."""
7577
src_docs = tmp_path / "src" / "module_docs"
@@ -83,7 +85,9 @@ def test_symlink_exposes_files_at_target_path(
8385

8486

8587
def test_symlink_is_idempotent(
86-
make_sphinx_app: Callable, docs_dir: Path, tmp_path: Path
88+
make_sphinx_app: Callable[[dict[str, str]], SphinxTestApp],
89+
docs_dir: Path,
90+
tmp_path: Path,
8791
) -> None:
8892
"""Build cleanup removes temporary links and a second build still succeeds."""
8993
src_docs = tmp_path / "external"
@@ -99,7 +103,9 @@ def test_symlink_is_idempotent(
99103

100104

101105
def test_stale_symlink_is_replaced(
102-
make_sphinx_app: Callable, docs_dir: Path, tmp_path: Path
106+
make_sphinx_app: Callable[[dict[str, str]], SphinxTestApp],
107+
docs_dir: Path,
108+
tmp_path: Path,
103109
) -> None:
104110
"""A symlink pointing to a stale target is replaced with the correct one."""
105111
correct_src = tmp_path / "correct"
@@ -114,21 +120,23 @@ def test_stale_symlink_is_replaced(
114120

115121

116122
def test_existing_non_symlink_logs_error_and_skips(
117-
make_sphinx_app: Callable, docs_dir: Path, tmp_path: Path
123+
make_sphinx_app: Callable[[dict[str, str]], SphinxTestApp],
124+
docs_dir: Path,
125+
tmp_path: Path,
118126
) -> None:
119127
"""A real directory at the target path is left untouched and an error is logged."""
120128
(tmp_path / "external").mkdir()
121129
real_dir = docs_dir / "module"
122130
real_dir.mkdir()
123131

124-
app = make_sphinx_app({"../external": "module"})
132+
app: SphinxTestApp = make_sphinx_app({"../external": "module"})
125133

126134
assert real_dir.is_dir() and not real_dir.is_symlink()
127135
assert "not a symlink" in app.warning.getvalue()
128136

129137

130138
def test_empty_mapping_is_a_no_op(
131-
make_sphinx_app: Callable, docs_dir: Path
139+
make_sphinx_app: Callable[[dict[str, str]], SphinxTestApp], docs_dir: Path
132140
) -> None:
133141
"""An empty mapping produces no symlinks and no errors."""
134142
make_sphinx_app({}).build()
@@ -137,7 +145,9 @@ def test_empty_mapping_is_a_no_op(
137145

138146

139147
def test_multiple_mappings(
140-
make_sphinx_app: Callable, docs_dir: Path, tmp_path: Path
148+
make_sphinx_app: Callable[[dict[str, str]], SphinxTestApp],
149+
docs_dir: Path,
150+
tmp_path: Path,
141151
) -> None:
142152
"""Multiple mapping entries each produce their own symlink."""
143153
for name in ("alpha", "beta"):
@@ -152,7 +162,9 @@ def test_multiple_mappings(
152162

153163

154164
def test_target_in_subfolder(
155-
make_sphinx_app: Callable, docs_dir: Path, tmp_path: Path
165+
make_sphinx_app: Callable[[dict[str, str]], SphinxTestApp],
166+
docs_dir: Path,
167+
tmp_path: Path,
156168
) -> None:
157169
"""A target path with intermediate directories creates the parent dirs."""
158170
src_docs = tmp_path / "external"

src/extensions/score_source_code_linker/xml_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def build_test_needs_from_files(
234234
tcns: list[DataOfTestCase] = []
235235
for file in xml_paths:
236236
# Last value can be ignored. The 'is_valid' function already prints infos
237-
test_cases, tests_missing_all_props,_ = read_test_xml_file(file)
237+
test_cases, tests_missing_all_props, _ = read_test_xml_file(file)
238238
non_prop_tests = ", ".join(n for n in tests_missing_all_props)
239239
if non_prop_tests:
240240
logger.info(f"Tests missing all properties: {non_prop_tests}")

src/helper_lib/test_helper_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
class _FakeConfig:
3030
"""Minimal stand-in for sphinx.config.Config."""
3131

32-
def __init__(self, raw: dict):
32+
def __init__(self, raw: dict[str, object]):
3333
self._raw_config = raw
3434

3535

0 commit comments

Comments
 (0)