- Notifications
You must be signed in to change notification settings - Fork 3
Install clang-tools into current pre-commit venv #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits Select commit Hold shift + click to select a range
c4b0f9e Install clang-tools into current pre-commit venv
maxnoe 610e14b Always use versioned executable
maxnoe e17a7a9 Use two test configs, one with version given, one with default version
maxnoe a69a996 Improve installing, add back tests for util
maxnoe 3a0b256 Improve testing
maxnoe 8b89dc0 Remove unused stuff
maxnoe 2a1b8de Remove superflous argument
maxnoe bf164c6 Merge branch 'main' into fix_install
shenxianpeng e003a0c Merge branch 'main' into fix_install
shenxianpeng d58e54f fixed failure of running pre-commit
shenxianpeng 9e365e4 skip failed tests
shenxianpeng 48450ba Merge branch 'main' into fix_install
shenxianpeng e3d0c49 upgrade python enviroment to 3.12
shenxianpeng d7dca0d skip failed test
shenxianpeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Install clang-tools into current pre-commit venv
- Loading branch information
commit c4b0f9e60fad2be3698b144be1bedcefc90809f9
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +0,0 @@ | ||
| import sys | ||
| | ||
| from cpp_linter_hooks.util import check_installed | ||
| from cpp_linter_hooks.util import get_expect_version | ||
| | ||
| | ||
| clang_tools = ['clang-format', 'clang-tidy'] | ||
| args = list(sys.argv[1:]) | ||
| | ||
| expect_version = get_expect_version(args) | ||
| | ||
| for tool in clang_tools: | ||
| if expect_version: | ||
| retval = check_installed(tool, version=expect_version) | ||
| else: | ||
| retval = check_installed(tool) | ||
| | ||
| if retval != 0: | ||
| raise SystemError("clang_tools not found. exit!") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,23 @@ | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
| from typing import Optional | ||
| import logging | ||
| | ||
| from clang_tools.install import is_installed, install_tool | ||
| | ||
| def check_installed(tool: str, version="") -> int: | ||
| if version: | ||
| check_version_cmd = [f'{tool}-{version} ', '--version'] | ||
| else: | ||
| check_version_cmd = [tool, '--version'] | ||
| try: | ||
| subprocess.run(check_version_cmd, stdout=subprocess.PIPE) | ||
| retval = 0 | ||
| except FileNotFoundError: | ||
| retval = install_clang_tools(version) | ||
| return retval | ||
| | ||
| LOG = logging.getLogger(__name__) | ||
| | ||
| def install_clang_tools(version: str) -> int: | ||
| if version: | ||
| # clang-tools exist because install_requires=['clang-tools'] in setup.py | ||
| install_tool_cmd = ['clang-tools', '-i', version] | ||
| else: | ||
| # install version 13 by default if clang-tools not exist. | ||
| install_tool_cmd = ['clang-tools', '-i', '13'] | ||
| try: | ||
| subprocess.run(install_tool_cmd, stdout=subprocess.PIPE) | ||
| retval = 0 | ||
| except Exception: | ||
| retval = 1 | ||
| return retval | ||
| | ||
| def ensure_installed(tool_name: str, version: Optional[str] = None): | ||
| # install version 13 by default if clang-tools not exist. | ||
| if version is None: | ||
| version = "13" | ||
| | ||
| def get_expect_version(args) -> str: | ||
| for arg in args: | ||
| if arg.startswith("--version"): # expect specific clang-tools version. | ||
| # If --version is passed in as 2 arguments, the second is version | ||
| if arg == "--version" and args.index(arg) != len(args) - 1: | ||
| # when --version 14 | ||
| expect_version = args[args.index(arg) + 1] | ||
| else: | ||
| # when --version=14 | ||
| expect_version = arg.replace(" ", "").replace("=", "").replace("--version", "") | ||
| return expect_version | ||
| return "" | ||
| LOG.info("Checking for %s, version %s", tool_name, version) | ||
| if not is_installed(tool_name, version): | ||
| LOG.info("Installing %s, version %s", tool_name, version) | ||
| directory = Path(sys.executable).parent | ||
| install_tool(tool_name, version, directory=str(directory), no_progress_bar=True) | ||
| else: | ||
| LOG.info("%s, version %s is already installed", tool_name, version) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.
Uh oh!
There was an error while loading. Please reload this page.