Skip to content

Commit 33aeacc

Browse files
committed
feat: support CLI tool to install clang tool wheels
1 parent 7332611 commit 33aeacc

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ A pre-commit hook that automatically formats and lints your C/C++ code using `cl
1313
- [Quick Start](#quick-start)
1414
- [Custom Configuration Files](#custom-configuration-files)
1515
- [Custom Clang Tool Version](#custom-clang-tool-version)
16+
- [Clang Tool Wheel CLI](#clang-tool-wheel-cli)
1617
- [Output](#output)
1718
- [clang-format Output](#clang-format-output)
1819
- [clang-tidy Output](#clang-tidy-output)
@@ -72,6 +73,35 @@ repos:
7273
args: [--checks=.clang-tidy, --version=21] # Specifies version
7374
```
7475

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

77107
### 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)