Skip to content

Commit 055f429

Browse files
2bndy5shenxianpeng
andauthored
Pro revision (#16)
* re-write source - adds a feature to create a symlink and a new CLI option (`-f`) to overwrite an existing symlink. - added docstrings along the way, but most docstrings are still incomplete. * improve test coverage * only create symlink if tool was not previously installed * warn if install dir not in PATH * run pre-commit (without tests) * create docs with sphinx * update workflows and build binary wheel Switch installation config to pyproject.toml. The setup.py file remains as a dummy until it's usage is completely deprecated. * add a tip about using a venv * remove dead code and adjust tests accordingly Co-authored-by: Peter Shen <xianpeng.shen@gmail.com>
1 parent a63ca48 commit 055f429

25 files changed

+851
-324
lines changed

.coveragerc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[run]
2+
dynamic_context = test_function
3+
omit =
4+
# don't include tests in coverage
5+
tests/*
6+
7+
[json]
8+
pretty_print=true
9+
10+
[html]
11+
show_contexts=true
12+
13+
[report]
14+
# Regexes for lines to exclude from consideration
15+
exclude_lines =
16+
# Have to re-enable the standard pragma
17+
pragma: no cover
18+
19+
# ignore any branch that makes the module executable
20+
if __name__ == "__main__"
21+
22+
# we test parts of the install algorithm separately
23+
def install_clang_tools
24+
def main

.github/workflows/python-publish.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,29 @@ jobs:
2323

2424
steps:
2525
- uses: actions/checkout@v3
26+
# use fetch --all for setuptools_scm to work
27+
with:
28+
fetch-depth: 0
2629
- name: Set up Python
2730
uses: actions/setup-python@v3
2831
with:
2932
python-version: '3.x'
3033
- name: Install dependencies
31-
run: |
32-
python -m pip install --upgrade pip
33-
pip install build
34-
- name: Build package
35-
run: python -m build
36-
- name: Publish package
37-
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
38-
with:
39-
user: __token__
40-
password: ${{ secrets.PYPI_API_TOKEN }}
34+
run: python -m pip install --upgrade pip twine
35+
- name: Build wheel
36+
run: python -m pip wheel -w dist .
37+
- name: Check distribution
38+
run: twine check dist/*
39+
- name: Publish package (to TestPyPI)
40+
if: github.event_name == 'workflow_dispatch' && github.repository == 'cpp-linter/clang-tools-pip'
41+
env:
42+
TWINE_USERNAME: __token__
43+
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
44+
run: twine upload --repository testpypi dist/*
45+
- name: Publish package (to PyPI)
46+
if: github.event_name == 'release' && github.repository == 'cpp-linter/clang-tools-pip' && github.ref == 'refs/heads/main'
47+
env:
48+
TWINE_USERNAME: __token__
49+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
50+
run: twine upload dist/*
51+

.github/workflows/python-test.yml

Lines changed: 98 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,43 @@ jobs:
2020
build:
2121
runs-on: ubuntu-latest
2222
steps:
23-
- uses: actions/checkout@v3
24-
- name: Set up Python 3.10
25-
uses: actions/setup-python@v3
26-
with:
27-
python-version: "3.10"
28-
- name: Install dependencies
29-
run: |
30-
python3 -m pip install --upgrade pip
31-
pip install .
32-
pip install -r requirements-dev.txt
33-
- name: Collect coverage
34-
run: |
35-
coverage run --source=tests,clang_tools -m pytest
36-
coverage report -m
37-
coverage html
38-
- name: Upload coverage reports to Codecov
39-
run: |
40-
# Replace `linux` below with the appropriate OS
41-
# Options are `alpine`, `linux`, `macos`, `windows`
42-
curl -Os https://uploader.codecov.io/latest/linux/codecov
43-
chmod +x codecov
44-
./codecov -t ${CODECOV_TOKEN}
23+
- uses: actions/checkout@v3
24+
25+
- name: Set up Python 3.10
26+
uses: actions/setup-python@v3
27+
with:
28+
python-version: "3.10"
29+
30+
- name: Install dependencies
31+
run: |
32+
python3 -m pip install --upgrade pip
33+
python3 -m pip install . -r requirements-dev.txt
34+
35+
- run: pre-commit run
36+
37+
- name: Collect coverage
38+
run: |
39+
coverage run -m pytest -vv
40+
coverage report -m
41+
coverage xml
42+
43+
- name: Upload coverage reports to Codecov
44+
uses: codecov/codecov-action@v3
45+
with:
46+
files: ./coverage.xml
47+
verbose: true # optional (default = false)
48+
49+
- name: build wheel
50+
run: python -m pip wheel -w dist .
51+
52+
- name: upload wheel as artifact
53+
uses: actions/upload-artifact@v3
54+
with:
55+
name: "clang-tools-pip_wheel"
56+
path: ${{ github.workspace }}/dist/*.whl
57+
4558
install:
59+
needs: [build]
4660
strategy:
4761
matrix:
4862
# skip version 14 because it failed on ubuntu.
@@ -51,27 +65,65 @@ jobs:
5165
fail-fast: false
5266
runs-on: ${{ matrix.os }}
5367
steps:
54-
- name: Set up Python 3.8
55-
uses: actions/setup-python@v4
56-
with:
57-
python-version: "3.8"
58-
- name: Install clang-tools of push event
59-
run: pip install git+https://github.com/cpp-linter/clang-tools-pip.git@${{ github.ref }}
60-
- name: Install clang-tools of pull_request event
61-
if: github.event_name == 'pull_request'
62-
run: pip install git+https://github.com/cpp-linter/clang-tools-pip.git@${{ github.head_ref }}
63-
- name: Install clang-tools
64-
run: |
65-
clang-tools --install ${{ matrix.version }}
66-
which clang-format-${{ matrix.version }}
67-
which clang-tidy-${{ matrix.version }}
68-
- name: Check clang-tools on Windows
69-
if: matrix.os == 'windows-latest'
70-
run: |
71-
clang-format-${{ matrix.version }}.exe --version
72-
clang-tidy-${{ matrix.version }}.exe --version
73-
- name: Check clang-tools on Unix
74-
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
75-
run: |
76-
clang-format-${{ matrix.version }} --version
77-
clang-tidy-${{ matrix.version }} --version
68+
- name: Set up Python 3.8
69+
uses: actions/setup-python@v4
70+
with:
71+
python-version: "3.8"
72+
73+
- name: download wheel artifact
74+
uses: actions/download-artifact@v2
75+
with:
76+
name: clang-tools-pip_wheel
77+
path: dist
78+
79+
- name: Install pkg from wheel
80+
# using a wildcard as filename on Windows requires a bash shell
81+
shell: bash
82+
run: pip install dist/*.whl
83+
84+
- name: Install clang-tools
85+
run: |
86+
clang-tools --install ${{ matrix.version }}
87+
which clang-format-${{ matrix.version }}
88+
which clang-tidy-${{ matrix.version }}
89+
90+
- name: Check clang-tools on Windows
91+
if: matrix.os == 'windows-latest'
92+
run: |
93+
clang-format-${{ matrix.version }}.exe --version
94+
clang-tidy-${{ matrix.version }}.exe --version
95+
96+
- name: Check clang-tools on Unix
97+
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
98+
run: |
99+
clang-format-${{ matrix.version }} --version
100+
clang-tidy-${{ matrix.version }} --version
101+
102+
docs:
103+
runs-on: ubuntu-latest
104+
steps:
105+
- uses: actions/checkout@v3
106+
107+
- uses: actions/setup-python@v3
108+
with:
109+
python-version: "3.10"
110+
111+
- run: python -m pip install . -r docs/requirements.txt
112+
113+
- name: Build docs
114+
working-directory: docs
115+
run: sphinx-build -E -W -b html . _build/html
116+
117+
- name: Save built docs as artifact
118+
uses: actions/upload-artifact@v3
119+
with:
120+
name: "clang-tools-pip_docs"
121+
path: ${{ github.workspace }}/docs/_build/html
122+
123+
- name: upload to github pages
124+
# only publish doc changes from main branch
125+
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
126+
uses: peaceiris/actions-gh-pages@v3
127+
with:
128+
github_token: ${{ secrets.GITHUB_TOKEN }}
129+
publish_dir: ./docs/_build/html

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
.pytest_cache
2-
build
2+
*build
33
clang_tools.egg-info
44
clang_tools/__pycache__
55
dist
66
clang_tools/llvm-project*
77
.coverage
8-
.vscode/settings.json
8+
htmlcov/
9+
.vscode/
910
tests/pytestdebug.log
1011
tests/__pycache__/
1112
.eggs
13+
.mypy_cache/

.pre-commit-config.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ repos:
2525
hooks:
2626
- id: flake8
2727
args: [--max-line-length=120]
28-
- repo: local
29-
hooks:
30-
- id: tests
31-
name: tests
32-
entry: bash -c "pip install . && pytest -v tests"
33-
description: Run all tests
34-
language: system
35-
types: [python]
28+
# - repo: local
29+
# hooks:
30+
# - id: pytest
31+
# name: tests
32+
# entry: pytest
33+
# description: Run all tests
34+
# language: python
35+
# exclude: "^(docs/|setup.py$)"
36+
# types: [python]
37+
# additional_dependencies: [".", "pytest"]
38+
# args: ["-vv", "tests"]

README.md

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)