Skip to content

Commit 29569e2

Browse files
committed
fix: restrict WHEEL_TOOLS to clang-format and clang-tidy only
clang-query and clang-apply-replacements are binary-only and not available as wheels via cpp-linter-hooks. Add validation in --wheel path and new test for unsupported tool error.
1 parent d023586 commit 29569e2

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

clang_tools/main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def _is_version_like(target: str) -> bool:
2929

3030

3131
#: Known tool names supported by wheel installs
32-
WHEEL_TOOLS = {
33-
"clang-format", "clang-tidy", "clang-query", "clang-apply-replacements",
34-
}
32+
WHEEL_TOOLS = {"clang-format", "clang-tidy"}
3533

3634

3735
def _wheel_install(tools: list[str], version: Optional[str]) -> int:
@@ -178,6 +176,14 @@ def main() -> int:
178176
return _wheel_install(args.tool, target)
179177
else:
180178
# ``clang-tools install clang-format --wheel``
179+
if target not in WHEEL_TOOLS:
180+
print(
181+
f"{YELLOW}Error: '{target}' is not available as a"
182+
f" wheel. Supported: "
183+
f"{', '.join(sorted(WHEEL_TOOLS))}{RESET_COLOR}",
184+
file=sys.stderr,
185+
)
186+
return 1
181187
return _wheel_install([target], args.explicit_version)
182188

183189
# ---- Case: --binary (target must be a version) --------------

tests/test_main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,21 @@ def test_main_install_wheel_success(monkeypatch: pytest.MonkeyPatch, capsys):
200200
assert result.err == ""
201201

202202

203+
def test_main_install_wheel_unsupported_tool(
204+
monkeypatch: pytest.MonkeyPatch, capsys
205+
):
206+
"""``--wheel`` with a binary-only tool name shows error."""
207+
monkeypatch.setattr(
208+
sys,
209+
"argv",
210+
["clang-tools", "install", "clang-query", "--wheel"],
211+
)
212+
exit_code = main()
213+
result = capsys.readouterr()
214+
assert "is not available as a wheel" in result.err
215+
assert exit_code == 1
216+
217+
203218
def test_main_install_wheel_failure(monkeypatch: pytest.MonkeyPatch, capsys):
204219
"""``--wheel`` with a failing _wheel_install returns 1."""
205220
monkeypatch.setattr(

0 commit comments

Comments
 (0)