Skip to content

Commit 4f23a60

Browse files
committed
feat: support CLI tool to install clang tools wheels
1 parent 7332611 commit 4f23a60

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,35 @@ repos:
7272
args: [--checks=.clang-tidy, --version=21] # Specifies version
7373
```
7474

75+
### Clang Tool Wheel CLI
76+
77+
This package also provides a CLI tool `clang-tools-wheel` to install specific versions of clang-format and clang-tidy wheels directly.
78+
79+
It can automatically resolve and install compatible versions even if no explicit version number is provided.
80+
81+
```bash
82+
# Install the package
83+
pip install cpp-linter-hooks
84+
85+
# Install specific version of clang-format
86+
clang-tools-wheel --tool clang-format --version 21
87+
clang-format installed at: /home/sxp/.local/bin/clang-format
88+
89+
# Check clang-format version
90+
/home/sxp/.local/bin/clang-format --version
91+
clang-format version 21.1.2
92+
93+
# Install specific version of clang-tidy
94+
clang-tools-wheel --tool clang-tidy --version 21
95+
clang-tidy installed at: /home/sxp/.local/bin/clang-tidy
96+
97+
# Check clang-tidy version
98+
/home/sxp/.local/bin/clang-tidy --version
99+
LLVM (http://llvm.org/):
100+
LLVM version 21.1.1
101+
Optimized build.
102+
```
103+
75104
## Output
76105

77106
### clang-format Output

cpp_linter_hooks/util.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import shutil
33
import subprocess
4+
from argparse import ArgumentParser
45
from pathlib import Path
56
import logging
67
from typing import Optional, List
@@ -86,3 +87,21 @@ def _resolve_install(tool: str, version: Optional[str]) -> Optional[Path]:
8687
)
8788

8889
return _install_tool(tool, user_version)
90+
91+
92+
def main():
93+
parser = ArgumentParser("Install specified clang tool wheel")
94+
parser.add_argument("--tool", default="clang-format")
95+
parser.add_argument("--version", default=None)
96+
args = parser.parse_args()
97+
path = _resolve_install(args.tool, args.version)
98+
if path:
99+
print(f"{args.tool} installed at: {path}")
100+
return 0
101+
else:
102+
print(f"Failed to install {args.tool} version {args.version}")
103+
return 1
104+
105+
106+
if __name__ == "__main__":
107+
raise SystemExit(main())

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ dependencies = [
4040
dynamic = ["version"]
4141

4242
[project.scripts]
43+
clang-tools-wheel = "cpp_linter_hooks.util:main"
4344
clang-format-hook = "cpp_linter_hooks.clang_format:main"
4445
clang-tidy-hook = "cpp_linter_hooks.clang_tidy:main"
4546

0 commit comments

Comments
 (0)