Skip to content

Commit 90a453d

Browse files
authored
Migration: From Clang Tools Binaries to Python Wheels (#87)
* Migrate from clang-tools binaries to wheels * allow run in parallel and pin clang-tools version * update run.sh * fix utils.py tests and others * fix: add missing package * revert mian.c change * docs: update docs * add @pytest.mark.benchmark to test * pre-commit autoupdate * update docs * increase test coverage
1 parent 0134570 commit 90a453d

File tree

11 files changed

+696
-93
lines changed

11 files changed

+696
-93
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ result.txt
1313
testing/main.c
1414
*/*compile_commands.json
1515

16-
# Ignore clang-tools binaries
16+
# Ignore Python wheel packages (clang-format, clang-tidy)
1717
clang-tidy-1*
1818
clang-tidy-2*
1919
clang-format-1*

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
hooks:
1515
- id: pyupgrade
1616
- repo: https://github.com/astral-sh/ruff-pre-commit
17-
rev: v0.12.1
17+
rev: v0.12.2
1818
hooks:
1919
- id: ruff
2020
- id: ruff-format

.pre-commit-hooks.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
entry: clang-format-hook
55
language: python
66
files: \.(h\+\+|h|hh|hxx|hpp|c|cc|cpp|c\+\+|cxx)$
7-
require_serial: true
7+
require_serial: false
88

99
- id: clang-tidy
1010
name: clang-tidy
1111
description: Automatically install any specific version of clang-tidy and diagnose/fix typical programming errors
1212
entry: clang-tidy-hook
1313
language: python
1414
files: \.(h\+\+|h|hh|hxx|hpp|c|cc|cpp|c\+\+|cxx)$
15-
require_serial: true
15+
require_serial: false

MIGRATION.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Migration: From Clang Tools Binaries to Python Wheels
2+
3+
## Overview
4+
5+
Starting from version **v1.0.0**, `cpp-linter-hooks` has migrated from using the `clang-tools` package to using Python wheel packages for `clang-format` and `clang-tidy`. This change provides:
6+
7+
- **Better cross-platform compatibility**
8+
- **Easier installation and dependency management**
9+
- **Improved performance and reliability**
10+
11+
## What Changed
12+
13+
### Core Changes
14+
15+
| Aspect | Before (< v1.0.0) | After (≥ v1.0.0) |
16+
|--------|-------------------|-------------------|
17+
| **Installation** | Install from GitHub release | Install with from PyPI |
18+
| **Distribution** | Binary packages | Python wheel packages |
19+
| **Performance** | Run serially | Run in parallel |
20+
21+
### Implementation Details
22+
23+
- **Dependencies**: Updated to use separate `clang-format==20.1.7` and `clang-tidy==20.1.0` Python wheels
24+
- **Installation Logic**: Enhanced with pip-based installation and runtime version checks
25+
- **Performance**: Pre-commit hooks can now run in parallel for better speed
26+
27+
## Breaking Changes
28+
29+
**No breaking changes for end users**
30+
31+
- Your existing `.pre-commit-config.yaml` files will continue to work without modification
32+
- All hook configurations remain backward compatible
33+
- No changes required to your workflow
34+
35+
## Migration Steps
36+
37+
**No action required!** Your existing configuration will continue to work seamlessly.
38+
39+
However, we recommend updating to the latest version for:
40+
- Better performance
41+
- Enhanced reliability
42+
- Latest features and bug fixes
43+
44+
## Support
45+
46+
If you encounter issues after migration:
47+
48+
1. **Check this guide**: Review the troubleshooting section above
49+
2. **Search existing issues**: [GitHub Issues](https://github.com/cpp-linter/cpp-linter-hooks/issues)
50+
3. **Report new issues**: Include the following information:
51+
- Operating system and version
52+
- Python version
53+
- `cpp-linter-hooks` version
54+
- Complete error message/stack trace
55+
- Your `.pre-commit-config.yaml` configuration
56+
57+
## References
58+
59+
### Official Packages
60+
- [clang-format Python wheel](https://pypi.org/project/clang-format/) - PyPI package
61+
- [clang-tidy Python wheel](https://pypi.org/project/clang-tidy/) - PyPI package
62+
63+
### Source Repositories
64+
- [clang-format wheel source](https://github.com/ssciwr/clang-format-wheel) - GitHub repository
65+
- [clang-tidy wheel source](https://github.com/ssciwr/clang-tidy-wheel) - GitHub repository
66+
67+
### Documentation
68+
- [cpp-linter-hooks Documentation](https://github.com/cpp-linter/cpp-linter-hooks) - Main repository
69+
- [Pre-commit Framework](https://pre-commit.com/) - Pre-commit documentation
70+
71+
---
72+
73+
**Happy linting!**

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Add this configuration to your `.pre-commit-config.yaml` file:
2929
```yaml
3030
repos:
3131
- repo: https://github.com/cpp-linter/cpp-linter-hooks
32-
rev: v0.8.3 # Use the tag or commit you want
32+
rev: v1.0.0 # Use the tag or commit you want
3333
hooks:
3434
- id: clang-format
3535
args: [--style=Google] # Other coding style: LLVM, GNU, Chromium, Microsoft, Mozilla, WebKit.
@@ -44,7 +44,7 @@ To use custom configurations like `.clang-format` and `.clang-tidy`:
4444
```yaml
4545
repos:
4646
- repo: https://github.com/cpp-linter/cpp-linter-hooks
47-
rev: v0.8.3
47+
rev: v1.0.0
4848
hooks:
4949
- id: clang-format
5050
args: [--style=file] # Loads style from .clang-format file
@@ -54,19 +54,22 @@ repos:
5454

5555
### Custom Clang Tool Version
5656

57-
To use specific versions of [clang-tools](https://github.com/cpp-linter/clang-tools-pip?tab=readme-ov-file#supported-versions):
57+
To use specific versions of clang-format and clang-tidy (using Python wheel packages):
5858

5959
```yaml
6060
repos:
6161
- repo: https://github.com/cpp-linter/cpp-linter-hooks
62-
rev: v0.8.3
62+
rev: v1.0.0
6363
hooks:
6464
- id: clang-format
6565
args: [--style=file, --version=18] # Specifies version
6666
- id: clang-tidy
6767
args: [--checks=.clang-tidy, --version=18] # Specifies version
6868
```
6969

70+
> [!NOTE]
71+
> Starting from version v1.0.0, this package uses Python wheel packages ([clang-format](https://pypi.org/project/clang-format/) and [clang-tidy](https://pypi.org/project/clang-tidy/)) instead of the previous clang-tools binaries. The wheel packages provide better cross-platform compatibility and easier installation. For more details, see the [Migration Guide](MIGRATION.md).
72+
7073
## Output
7174

7275
### clang-format Output
@@ -141,12 +144,12 @@ Use -header-filter=.* to display errors from all non-system headers. Use -system
141144

142145
### Performance Optimization
143146

144-
> [!WARNING]
147+
> [!TIP]
145148
> If your `pre-commit` runs longer than expected, it is highly recommended to add `files` in `.pre-commit-config.yaml` to limit the scope of the hook. This helps improve performance by reducing the number of files being checked and avoids unnecessary processing. Here's an example configuration:
146149

147150
```yaml
148151
- repo: https://github.com/cpp-linter/cpp-linter-hooks
149-
rev: v0.8.3
152+
rev: v1.0.0
150153
hooks:
151154
- id: clang-format
152155
args: [--style=file, --version=18]
@@ -172,7 +175,7 @@ This approach ensures that only modified files are checked, further speeding up
172175
```yaml
173176
repos:
174177
- repo: https://github.com/cpp-linter/cpp-linter-hooks
175-
rev: v0.8.3
178+
rev: v1.0.0
176179
hooks:
177180
- id: clang-format
178181
args: [--style=file, --version=18, --verbose] # Add -v or --verbose for detailed output

cpp_linter_hooks/clang_format.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
from argparse import ArgumentParser
44
from typing import Tuple
55

6-
from .util import ensure_installed, DEFAULT_CLANG_VERSION
6+
from .util import ensure_installed, DEFAULT_CLANG_FORMAT_VERSION
77

88

99
parser = ArgumentParser()
10-
parser.add_argument("--version", default=DEFAULT_CLANG_VERSION)
10+
parser.add_argument("--version", default=DEFAULT_CLANG_FORMAT_VERSION)
1111
parser.add_argument(
1212
"-v", "--verbose", action="store_true", help="Enable verbose output"
1313
)
1414

1515

1616
def run_clang_format(args=None) -> Tuple[int, str]:
1717
hook_args, other_args = parser.parse_known_args(args)
18-
path = ensure_installed("clang-format", hook_args.version)
19-
command = [str(path), "-i"]
18+
tool_name = ensure_installed("clang-format", hook_args.version)
19+
command = [tool_name, "-i"]
2020

2121
# Add verbose flag if requested
2222
if hook_args.verbose:

cpp_linter_hooks/clang_tidy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
from argparse import ArgumentParser
33
from typing import Tuple
44

5-
from .util import ensure_installed, DEFAULT_CLANG_VERSION
5+
from .util import ensure_installed, DEFAULT_CLANG_TIDY_VERSION
66

77

88
parser = ArgumentParser()
9-
parser.add_argument("--version", default=DEFAULT_CLANG_VERSION)
9+
parser.add_argument("--version", default=DEFAULT_CLANG_TIDY_VERSION)
1010

1111

1212
def run_clang_tidy(args=None) -> Tuple[int, str]:
1313
hook_args, other_args = parser.parse_known_args(args)
14-
path = ensure_installed("clang-tidy", hook_args.version)
15-
command = [str(path)]
14+
tool_name = ensure_installed("clang-tidy", hook_args.version)
15+
command = [tool_name]
1616
command.extend(other_args)
1717

1818
retval = 0

0 commit comments

Comments
 (0)