Skip to content

Commit 4d40401

Browse files
committed
Code format with flake8
1 parent 0edd282 commit 4d40401

File tree

9 files changed

+51
-40
lines changed

9 files changed

+51
-40
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
exclude = .git,__pycache__,build,dist,*env
3+
max-complexity = 10
4+
max-line-length = 127

.github/workflows/python-test.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ jobs:
2626
python -m pip install --upgrade pip
2727
pip install .
2828
pip install -r requirements-dev.txt
29-
# - name: Lint with flake8
30-
# run: |
31-
# # stop the build if there are Python syntax errors or undefined names
32-
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
33-
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
34-
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
29+
- name: Lint with flake8
30+
run: flake8 .
3531
- name: Run tests and collect coverage
3632
run: pytest --cov .
3733
- name: Upload coverage reports to Codecov

CONTRIBUTING.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,25 @@ When you're finished with the changes, create a pull request, also known as a PR
1717
Install `clang-tools` from source code
1818

1919
```bash
20-
git clone [email protected]:shenxianpeng/clang-tools-pip.git
20+
$ git clone [email protected]:shenxianpeng/clang-tools-pip.git
2121
# Need root permission
22-
sudo python3 setup.py install
22+
$ sudo python3 setup.py install
2323
# Install clang-tools version 13
24-
sudo python3 main.py --install true --version 13
24+
$ sudo python3 main.py --install true --version 13
2525
```
2626

2727
### Test
2828

2929
```bash
3030
# run test
31-
pytest
31+
$ pytest
3232
# run test with code covarege
33-
coverage run -m pytest
33+
$ coverage run -m pytest
34+
```
35+
36+
## Code format
37+
38+
```bash
39+
# check code format with flake8
40+
$ flake8 .
3441
```

clang_tools/install.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from clang_tools.util import check_install_os
77
from clang_tools.util import download_file
88

9+
910
def clang_format_exist(version) -> bool:
1011
if version:
1112
command = [f'clang-format-{version}', '--version']
@@ -18,6 +19,7 @@ def clang_format_exist(version) -> bool:
1819
exist = False
1920
return exist
2021

22+
2123
def clang_tidy_exist(version) -> bool:
2224
if version:
2325
command = [f'clang-tidy-{version}', '--version']
@@ -30,9 +32,12 @@ def clang_tidy_exist(version) -> bool:
3032
exist = False
3133
return exist
3234

35+
3336
def clang_tools_binary_url(tool, version) -> string:
3437
install_os = check_install_os()
35-
return f"https://github.com/muttleyxd/clang-tools-static-binaries/releases/download/master-208096c1/{tool}-{version}_{install_os}-amd64"
38+
return f"https://github.com/muttleyxd/clang-tools-static-binaries/ \
39+
releases/download/master-208096c1/{tool}-{version}_{install_os}-amd64"
40+
3641

3742
def install_clang_format(version) -> None:
3843
if clang_format_exist(version):
@@ -42,6 +47,7 @@ def install_clang_format(version) -> None:
4247
download_file(clang_format_binary_url, clang_format_binary)
4348
install_clang_binary(clang_format_binary, f"clang-format-{version}")
4449

50+
4551
def install_clang_tidy(version) -> None:
4652
if clang_tidy_exist(version):
4753
return
@@ -50,6 +56,7 @@ def install_clang_tidy(version) -> None:
5056
download_file(clang_tidy_binary_url, clang_tidy_binary)
5157
install_clang_binary(clang_tidy_binary, f"clang-tidy-{version}")
5258

59+
5360
def install_clang_binary(old_file_name, new_file_name) -> None:
5461
"""Move download clang-tools binary and move to bin dir with right permission."""
5562
install_os = check_install_os()
@@ -61,7 +68,8 @@ def install_clang_binary(old_file_name, new_file_name) -> None:
6168
raise Exception(f"Not support {install_os}")
6269
shutil.move(old_file_name, f"{clang_tools_dir}/{new_file_name}")
6370
os.chmod(os.path.join(clang_tools_dir, new_file_name), 0o777)
64-
71+
72+
6573
def install_clang_tools(version) -> None:
6674
install_clang_format(version)
6775
install_clang_tidy(version)

clang_tools/main.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
import argparse
22
from clang_tools.install import install_clang_tools
33

4+
45
def main() -> int:
56
parser = argparse.ArgumentParser(prog='clang-tools')
6-
# parser.add_argument(
7-
# "-b",
8-
# "--build",
9-
# default="false",
10-
# help="Build clang-tools.",
11-
# )
7+
128
parser.add_argument(
139
"-i",
1410
"--install",
1511
default="12",
1612
help="Install clang-tools with specific version. default is 12.",
1713
)
18-
# parser.add_argument(
19-
# "-v",
20-
# "--version",
21-
# default="12",
22-
# help="The version of clang-tools. default is 12.",
23-
# )
14+
2415
# parser.add_argument(
2516
# "-d",
26-
# "--directory",
17+
# "--directory",
2718
# default="/usr/bin/",
28-
# help="The directory where is the clang-tools install.",
19+
# help="The directory where is the clang-tools install.",
2920
# )
3021
args = parser.parse_args()
3122

@@ -35,8 +26,6 @@ def main() -> int:
3526
if install_version:
3627
install_clang_tools(install_version)
3728

38-
# if build:
39-
# TODO
4029

4130
if __name__ == '__main__':
4231
raise SystemExit(main())

clang_tools/util.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,26 @@ def check_install_os() -> string:
88
os = platform.system().lower()
99
return os
1010

11+
1112
def download_file(url, file_name) -> None:
1213
urllib.request.urlretrieve(url, file_name)
1314

15+
1416
def unpack_file(file_name) -> int:
1517
command = ["tar", "-xvf", file_name]
1618
result = subprocess.run(command, stdout=subprocess.PIPE)
1719
return result.returncode
1820

21+
1922
def cmake_and_build():
2023
command = [
21-
"cmake",
22-
"-S" "llvm-project-12.0.1.src/llvm",
23-
"-B", "llvm-project-12.0.1.src/build",
24-
"-DBUILD_SHARED_LIBS=OFF",
25-
"-DLLVM_ENABLE_PROJECTS=\"clang;clang-tools-extra\"",
26-
"-DLLVM_BUILD_STATIC=ON",
27-
"-DCMAKE_CXX_FLAGS=\"-s -flto\"",
24+
"cmake",
25+
"-S" "llvm-project-12.0.1.src/llvm",
26+
"-B", "llvm-project-12.0.1.src/build",
27+
"-DBUILD_SHARED_LIBS=OFF",
28+
"-DLLVM_ENABLE_PROJECTS=\"clang;clang-tools-extra\"",
29+
"-DLLVM_BUILD_STATIC=ON",
30+
"-DCMAKE_CXX_FLAGS=\"-s -flto\"",
2831
"-DCMAKE_BUILD_TYPE=MinSizeRel",
2932
"-DCMAKE_CXX_COMPILER=g++-10",
3033
"-DCMAKE_C_COMPILER=gcc-10",

requirements-dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pytest
22
pytest-cov
3-
coverage
3+
coverage
4+
flake8

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
setup(
77
name="clang_tools",
8-
version = "0.0.1",
8+
version="0.0.1",
99
description="Install clang-tools (clang-format, clang-tidy) with pip",
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",
1212
author="Peter Shen",
1313
author_email="[email protected]",
1414
keywords=["clang", "clang-tools", "clang-extra", "clang-tidy", "clang-format"],
1515
license="MIT License",
16-
packages = find_packages(),
16+
packages=find_packages(),
1717
project_urls={
1818
"Source": "https://github.com/shenxianpeng/clang-tools-pip",
1919
"Tracker": "https://github.com/shenxianpeng/clang-tools-pip/issues"
@@ -34,4 +34,4 @@
3434
"clang-tools=clang_tools.main:main"
3535
]
3636
},
37-
)
37+
)

tests/test_util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
TEST_REPO = "https://github.com/cpp-linter/cpp-linter-action"
66

7+
78
def test_check_install_os():
89
install_os = check_install_os()
910
assert install_os in ("linux", "windos", "macosx")
1011

12+
1113
def test_download_file():
1214
url = f"{TEST_REPO}/blob/master/README.md"
1315
file_name = "test_file"
@@ -16,6 +18,7 @@ def test_download_file():
1618
os.remove(file_name)
1719
assert not os.path.exists(file_name)
1820

21+
1922
def test_unpack_file():
2023
url = f"{TEST_REPO}/archive/refs/tags/v1.4.4.tar.gz"
2124
file_name = "test_file.tar.gz"

0 commit comments

Comments
 (0)