Skip to content

Commit 24eb2e7

Browse files
committed
feat: support install python wheels
1 parent 327e2a9 commit 24eb2e7

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

README.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
clang-tools CLI
22
===============
33

4-
**Install clang-format, clang-tidy, clang-query, and clang-apply-replacements binaries with clang-tools CLI.**
4+
**Install clang-format, clang-tidy, clang-query, and clang-apply-replacements binaries and Python wheels with clang-tools CLI.**
55

66
.. |latest-version| image:: https://img.shields.io/pypi/v/clang-tools?color=blue
77
:target: https://pypi.org/project/clang-tools/
@@ -29,6 +29,8 @@ clang-tools CLI
2929
are installed using this package's executable script. It does not intend to change or
3030
modify any binary executable installed from other sources (like LLVM releases).
3131

32+
For Python wheels, this CLI only support clang-format and clang-tidy tools.
33+
3234
Features
3335
--------
3436

clang_tools/wheel.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from argparse import ArgumentParser
2+
from cpp_linter_hooks.util import _resolve_install
3+
4+
5+
def main() -> int:
6+
parser = ArgumentParser(description="Install specified clang tool wheel")
7+
parser.add_argument(
8+
"--tool",
9+
default="clang-format",
10+
choices=["clang-format", "clang-tidy"],
11+
help="Tool to install (clang-format or clang-tidy)",
12+
)
13+
parser.add_argument(
14+
"--version",
15+
default=None,
16+
help="Version to install (e.g., 21 or 21.1.2). Defaults to latest compatible version.",
17+
)
18+
args = parser.parse_args()
19+
path = _resolve_install(args.tool, args.version)
20+
if path:
21+
print(f"{args.tool} installed at: {path}")
22+
return 0
23+
else:
24+
print(f"Failed to install {args.tool} version {args.version}")
25+
return 1
26+
27+
28+
if __name__ == "__main__":
29+
raise SystemExit(main())

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ classifiers = [
3030
"Programming Language :: Python :: 3.14",
3131
"Topic :: Software Development :: Build Tools",
3232
]
33+
34+
dependencies = [
35+
"cpp-linter-hooks>=1.1.6",
36+
]
37+
3338
dynamic = ["version"]
3439

3540
[project.scripts]
3641
clang-tools = "clang_tools.main:main"
42+
clang-tools-binary = "clang_tools.main:main"
43+
clang-tools-wheel = "clang_tools.wheel:main"
3744

3845
[project.urls]
3946
source = "https://github.com/cpp-linter/clang-tools-pip"

tests/test_wheel.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import sys
2+
from clang_tools.wheel import main
3+
4+
5+
def test_main_success(monkeypatch):
6+
# Patch _resolve_install to simulate success
7+
monkeypatch.setattr(
8+
"clang_tools.wheel._resolve_install",
9+
lambda tool, version: "/usr/bin/clang-format",
10+
)
11+
monkeypatch.setattr(
12+
sys, "argv", ["util.py", "--tool", "clang-format", "--version", "15.0.7"]
13+
)
14+
exit_code = main()
15+
assert exit_code == 0
16+
17+
18+
def test_main_failure(monkeypatch):
19+
# Patch _resolve_install to simulate failure
20+
monkeypatch.setattr(
21+
"clang_tools.wheel._resolve_install", lambda tool, version: None
22+
)
23+
monkeypatch.setattr(
24+
sys, "argv", ["util.py", "--tool", "clang-format", "--version", "99.99.99"]
25+
)
26+
exit_code = main()
27+
assert exit_code == 1
28+
29+
30+
def test_main_default_tool(monkeypatch):
31+
# Patch _resolve_install to simulate success for default tool
32+
monkeypatch.setattr(
33+
"clang_tools.wheel._resolve_install",
34+
lambda tool, version: "/usr/bin/clang-format",
35+
)
36+
monkeypatch.setattr(sys, "argv", ["util.py"])
37+
exit_code = main()
38+
assert exit_code == 0

0 commit comments

Comments
 (0)