Fix ImportError with conflicting clang-format packages and improve error handling #109
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR resolves the
ImportError: cannot import name 'clang_format' from 'clang_format'
issue that occurs when users have conflicting PyPI packages installed alongside cpp-linter-hooks.Root Cause
The error occurs when users have conflicting
clang-format
scripts from PyPI packages (likeclang-format==21.1.0
) that use incompatible import structures. These conflicts often stem from previous installations of version 1.0.0, which included clang tools as direct dependencies, leaving behind conflicting scripts in user environments.Solution
1. Comprehensive Documentation
Added a detailed troubleshooting section to the README with three solution approaches:
pip uninstall clang-format clang-tidy clang-tools
2. Intelligent Conflict Detection
Implemented smart conflict detection that:
clang-format
scripts that contain problematic importsCLANG_FORMAT_HOOK_DEBUG=1
is set (no noise in normal usage)# Enable debug mode to see conflict warnings CLANG_FORMAT_HOOK_DEBUG=1 clang-format-hook --help
3. Enhanced Error Handling
Improved error messages throughout the codebase:
FileNotFoundError
messages with helpful hintsclang_format.py
andclang_tidy.py
4. Version Consistency
Updated all README examples to consistently use the latest version
v1.1.1
.Testing
clang-format-hook
andclang-tidy-hook
entry points, avoiding namespace conflicts entirelyThis solution maintains backward compatibility while providing users clear paths to resolve conflicts.
Fixes #108.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.