Skip to content

Commit c7335c2

Browse files
committed
Merge branch 'main' of github.com:shenxianpeng/clang-tools-pip into main
2 parents ac96e0e + 790eb44 commit c7335c2

File tree

6 files changed

+68
-40
lines changed

6 files changed

+68
-40
lines changed

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# clang-tools
22

3-
[![PyPI](https://img.shields.io/pypi/v/clang-tools)](https://pypi.org/project/clang-tools/) [![Python test](https://github.com/shenxianpeng/clang-tools-pip/actions/workflows/python-test.yml/badge.svg)](https://github.com/shenxianpeng/clang-tools-pip/actions/workflows/python-test.yml) [![codecov](https://codecov.io/gh/shenxianpeng/clang-tools-pip/branch/master/graph/badge.svg?token=40G5ZOIRRR)](https://codecov.io/gh/shenxianpeng/clang-tools-pip) [![Platfrom](https://img.shields.io/badge/platform-linux--64%20%7C%20win--64%20%7C%20osx--64%20-blue)](https://pypi.org/project/clang-tools/)
3+
[![PyPI](https://img.shields.io/pypi/v/clang-tools)](https://pypi.org/project/clang-tools/) [![Python test](https://github.com/shenxianpeng/clang-tools-pip/actions/workflows/python-test.yml/badge.svg)](https://github.com/shenxianpeng/clang-tools-pip/actions/workflows/python-test.yml) [![codecov](https://codecov.io/gh/shenxianpeng/clang-tools-pip/branch/master/graph/badge.svg?token=40G5ZOIRRR)](https://codecov.io/gh/shenxianpeng/clang-tools-pip) [![Platfrom](https://img.shields.io/badge/platform-linux--64%20%7C%20win--64%20%7C%20osx--64%20-blue)](https://pypi.org/project/clang-tools/) ![PyPI - Downloads](https://img.shields.io/pypi/dw/clang-tools)
4+
45

56
Install clang-tools binaries (clang-format, clang-tidy) with pip.
67

@@ -45,7 +46,21 @@ LLVM (http://llvm.org/):
4546

4647
## Supported versions
4748

48-
| verions | 14 | 13 | 12.0.1 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3.9 |
49-
|:------------:|:--:|:--:|:------:|:--:|:--:|:--:|:-:|:-:|:-:|:-:|:-:|:-:|:---:|
50-
| clang-format | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
51-
| clang-tidy || ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
49+
### clang-format
50+
| Version | 14 | 13 | 12.0.1 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3.9 |
51+
|:-------:|:--:|:--:|:------:|:--:|:--:|:--:|:-:|:-:|:-:|:-:|:-:|:-:|:---:|
52+
| Linux | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
53+
| Windows | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
54+
| macOS | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
55+
56+
### clang-tidy
57+
58+
| Version | 14 | 13 | 12.0.1 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3.9 |
59+
|:-------:|:--:|:--:|:------:|:--:|:--:|:--:|:-:|:-:|:-:|:-:|:-:|:-:|:---:|
60+
| Linux || ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
61+
| Windows | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
62+
| macOS | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
63+
64+
Know issue: clang-tidy version 14 has Segmentation fault (core dumped).
65+
66+
Thanks to the project [clang-tools-static-binaries](https://github.com/muttleyxd/clang-tools-static-binaries) for all the binaries.

clang_tools/install.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ def move_and_chmod_binary(old_file_name, new_file_name, directory) -> None:
6767
if directory:
6868
install_dir = directory
6969
else:
70-
install_os = check_install_os()
71-
if install_os not in ['linux', 'macosx', 'windows']:
72-
raise SystemExit(f"Not support {install_os}")
7370
install_dir = os.path.dirname(sys.executable)
7471
try:
7572
if not os.path.isdir(install_dir):

clang_tools/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def parse_args(args):
99
parser.add_argument(
1010
"-i",
1111
"--install",
12-
default="12",
13-
help="Install clang-tools with specific version. default is 12.",
12+
default="13",
13+
help="Install clang-tools with specific version. default is 13.",
1414
)
1515

1616
parser.add_argument(

clang_tools/util.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import string
22
import subprocess
3-
from urllib.error import HTTPError
43
import urllib.request
54
import platform
65

@@ -9,23 +8,20 @@ def check_install_os() -> string:
98
os = platform.system().lower()
109
if os == "darwin":
1110
os = "macosx"
11+
if os not in ['linux', 'macosx', 'windows']:
12+
raise SystemExit(f"Not support {os}")
1213
return os
1314

1415

15-
def download_file(url, file_name) -> None:
16+
def download_file(url, file_name) -> string:
1617
try:
17-
urllib.request.urlretrieve(url, file_name)
18-
except HTTPError:
19-
raise SystemExit(f"Not found {file_name}, exit!")
18+
file, _ = urllib.request.urlretrieve(url, file_name)
19+
except ValueError:
20+
return None
21+
return file
2022

2123

2224
def unpack_file(file_name) -> int:
2325
command = ["tar", "-xvf", file_name]
2426
result = subprocess.run(command, stdout=subprocess.PIPE)
2527
return result.returncode
26-
27-
28-
def cmake_and_build():
29-
command = []
30-
result = subprocess.run(command, stdout=subprocess.PIPE)
31-
print(result.stdout.decode("utf-8"))

tests/test_install.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
from clang_tools.install import check_install_os
3+
from clang_tools.install import clang_format_exist
4+
from clang_tools.install import clang_tidy_exist
5+
from clang_tools.install import clang_tools_binary_url
6+
7+
8+
@pytest.mark.parametrize(('version', 'expected'), (('12', True), ('100', False)))
9+
def test_clang_tools_exist(version, expected):
10+
assert clang_format_exist(version) == expected
11+
assert clang_tidy_exist(version) == expected
12+
13+
14+
def test_clang_tools_binary_url():
15+
tools = ['clang-format', 'clang-tidy']
16+
version = 12
17+
os = check_install_os()
18+
for tool in tools:
19+
ret = clang_tools_binary_url(tool, version)
20+
if os == 'windows':
21+
assert(f"{tool}-{version}_{os}-amd64.exe" in ret)
22+
else:
23+
assert(f"{tool}-{version}_{os}-amd64" in ret)

tests/test_util.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
import os
2-
import shutil
1+
from unittest import mock
32
from clang_tools.util import check_install_os, download_file, unpack_file
43

5-
TEST_REPO = "https://github.com/shenxianpeng/clang-tools-pip"
6-
74

85
def test_check_install_os():
96
install_os = check_install_os()
107
assert install_os in ("linux", "windos", "macosx")
118

129

13-
def test_download_file():
14-
url = f"{TEST_REPO}/blob/master/README.md"
15-
file_name = "test_file"
16-
download_file(url, file_name)
17-
assert os.path.exists(file_name)
18-
os.remove(file_name)
19-
assert not os.path.exists(file_name)
10+
@mock.patch('clang_tools.util.urllib.request.urlretrieve')
11+
def test_fail_download_file(mock_request):
12+
mock_result = mock.MagicMock()
13+
attrs = {'mock_result.return_value': 'file.tar.gz'}
14+
mock_result.configure_mock(**attrs)
15+
mock_request.return_value = mock_result
16+
file_name = download_file('https://www.google.com', 'file.tar.gz')
17+
assert file_name is None
2018

2119

22-
def test_unpack_file():
23-
url = f"{TEST_REPO}/archive/refs/tags/v0.1.0.tar.gz"
24-
file_name = "test_file.tar.gz"
25-
download_file(url, file_name)
26-
status = unpack_file(file_name)
27-
assert status == 0
28-
os.remove(file_name)
29-
shutil.rmtree("clang-tools-pip-0.1.0")
20+
@mock.patch('clang_tools.util.subprocess.run')
21+
def test_unpack_file(mock_run):
22+
mock_stdout = mock.Mock()
23+
mock_stdout.configure_mock(**{"returncode": '0'})
24+
mock_run.return_value = mock_stdout
25+
result = unpack_file('file.tar.gz')
26+
assert result == '0'

0 commit comments

Comments
 (0)