From 0aeef21a8088d84b46c31bf916aed02a999edc1b Mon Sep 17 00:00:00 2001 From: shenxianpeng <3353385+shenxianpeng@users.noreply.github.com> Date: Sat, 30 Aug 2025 08:28:41 +0000 Subject: [PATCH 1/5] chore: bump clang-tools-static-binaries to master-6e612956 --- clang_tools/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang_tools/__init__.py b/clang_tools/__init__.py index fd3dd3b..7034f54 100644 --- a/clang_tools/__init__.py +++ b/clang_tools/__init__.py @@ -9,4 +9,4 @@ suffix = ".exe" if install_os == "windows" else "" # tag of https://github.com/cpp-linter/clang-tools-static-binaries/releases -release_tag = "master-b35c5633" +release_tag = "master-6e612956" From 6b0bf8945f19b4a4627ce76a6c29ac2b22a9ab7c Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sun, 31 Aug 2025 15:33:28 +0300 Subject: [PATCH 2/5] chore: drop v8 and add v21 --- .github/workflows/python-test.yml | 4 ++-- README.rst | 2 +- clang_tools/__init__.py | 7 +++++-- clang_tools/install.py | 9 +++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 39438cc..2f1009c 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -77,7 +77,7 @@ jobs: needs: [build] strategy: matrix: - version: [ 8, 9, 10, 11, 12, 12.0.1, 13, 14, 15, 16, 17, 18, 19, 20 ] + version: [ 9, 10, 11, 12, 12.0.1, 13, 14, 15, 16, 17, 18, 19, 20, 21 ] os: [ ubuntu-latest, macos-13, windows-latest ] fail-fast: false runs-on: ${{ matrix.os }} @@ -121,7 +121,7 @@ jobs: shell: bash run: | case "${{ matrix.version }}" in - 15|16|18|20) + 15|16|18|20|21) clang-format.exe --version clang-tidy.exe --version clang-query.exe --version diff --git a/README.rst b/README.rst index ab32f42..1117701 100644 --- a/README.rst +++ b/README.rst @@ -132,7 +132,7 @@ Supported versions clang-format, clang-tidy, clang-query, clang-apply-replacements *************************************************************** .. csv-table:: - :header: "Version", "20", "19", "18", "17", "16", "15", "14", "13", "12", "11", "10", "9", "8" + :header: "Version", "21", "20", "19", "18", "17", "16", "15", "14", "13", "12", "11", "10", "9" :stub-columns: 1 Linux,✔️,✔️,✔️,✔️,✔️,✔️,✔️,✔️,✔️,✔️,✔️,✔️,✔️ diff --git a/clang_tools/__init__.py b/clang_tools/__init__.py index 7034f54..91edc70 100644 --- a/clang_tools/__init__.py +++ b/clang_tools/__init__.py @@ -1,5 +1,6 @@ """The clang-tools package's base module.""" +import os from .util import check_install_os @@ -8,5 +9,7 @@ install_os = check_install_os() suffix = ".exe" if install_os == "windows" else "" -# tag of https://github.com/cpp-linter/clang-tools-static-binaries/releases -release_tag = "master-6e612956" +binary_repo = os.getenv( + "CLANG_TOOLS_REPO", "https://github.com/cpp-linter/clang-tools-static-binaries" +) +binary_tag = os.getenv("CLANG_TOOLS_TAG", "master-6e612956") diff --git a/clang_tools/install.py b/clang_tools/install.py index d3162d7..18e5624 100644 --- a/clang_tools/install.py +++ b/clang_tools/install.py @@ -13,7 +13,7 @@ import sys from typing import Optional, cast -from . import release_tag, install_os, RESET_COLOR, suffix, YELLOW +from . import binary_repo, binary_tag, install_os, RESET_COLOR, suffix, YELLOW from .util import download_file, verify_sha512, get_sha_checksum, Version @@ -63,7 +63,7 @@ def is_installed(tool_name: str, version: Version) -> Optional[Path]: return path -def clang_tools_binary_url(tool: str, version: str, tag: str = release_tag) -> str: +def clang_tools_binary_url(tool: str, version: str) -> str: """Assemble the URL to the binary. :param tool: The name of the tool to download. @@ -72,10 +72,7 @@ def clang_tools_binary_url(tool: str, version: str, tag: str = release_tag) -> s :returns: The URL used to download the specified tool. """ - base_url = ( - "https://github.com/cpp-linter/clang-tools-static-binaries/releases/download/" - + tag - ) + base_url = f"{binary_repo}/releases/download/" + binary_tag download_url = f"{base_url}/{tool}-{version}_{install_os}-amd64{suffix}" return download_url.replace(" ", "") From b463b762e5de4103a72406453ec15016dcd16ba3 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sun, 31 Aug 2025 15:59:16 +0300 Subject: [PATCH 3/5] feat: add noxfile.py and docs --- .github/workflows/bump-version.yml | 6 ++-- .github/workflows/python-test.yml | 12 +++---- .gitignore | 1 + docs/index.rst | 2 ++ docs/usage.rst | 20 +++++++++++ noxfile.py | 33 +++++++++++++++++++ pyproject.toml | 5 +++ tests/clang-format-12_linux-amd64.sha512sum | 1 - tests/clang-format-12_macosx-amd64.sha512sum | 1 - tests/clang-format-12_windows-amd64.sha512sum | 1 - tests/clang-format-21_linux-amd64.sha512sum | 1 + tests/clang-format-21_macosx-amd64.sha512sum | 1 + tests/clang-format-21_windows-amd64.sha512sum | 1 + tests/test_util.py | 12 +++---- 14 files changed, 79 insertions(+), 18 deletions(-) create mode 100644 docs/usage.rst create mode 100644 noxfile.py delete mode 100644 tests/clang-format-12_linux-amd64.sha512sum delete mode 100644 tests/clang-format-12_macosx-amd64.sha512sum delete mode 100644 tests/clang-format-12_windows-amd64.sha512sum create mode 100644 tests/clang-format-21_linux-amd64.sha512sum create mode 100644 tests/clang-format-21_macosx-amd64.sha512sum create mode 100644 tests/clang-format-21_windows-amd64.sha512sum diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml index 794a0d6..3881a05 100644 --- a/.github/workflows/bump-version.yml +++ b/.github/workflows/bump-version.yml @@ -9,10 +9,10 @@ jobs: bump_version: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5 - name: Set up Python - uses: actions/setup-python@v5 + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 #v5 with: python-version: '3.x' @@ -34,7 +34,7 @@ jobs: fi - name: Create Pull Request - uses: peter-evans/create-pull-request@v7 + uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e #v7 with: add-paths: "clang_tools/__init__.py" commit-message: "chore: bump clang-tools-static-binaries to ${{ steps.bump.outputs.bump_tag }}" diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 2f1009c..9094467 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -27,10 +27,10 @@ jobs: fail-fast: false runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5 - name: Set up Python 3.10 - uses: actions/setup-python@v5 + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 #v5 with: python-version: "3.10" @@ -60,7 +60,7 @@ jobs: - uses: actions/checkout@v5 - name: Set up Python 3.10 - uses: actions/setup-python@v5 + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 #v5 with: python-version: "3.10" @@ -68,7 +68,7 @@ jobs: run: python -m pip wheel -w dist . - name: Upload wheel as artifact - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 #v4 with: name: clang-tools-pip_wheel path: dist/*.whl @@ -83,12 +83,12 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Set up Python 3.10 - uses: actions/setup-python@v5 + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 #v5 with: python-version: "3.10" - name: Download wheel artifact - uses: actions/download-artifact@v5 + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 #v5 with: name: clang-tools-pip_wheel path: dist/ diff --git a/.gitignore b/.gitignore index 36f9b81..efabeef 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *build clang_tools.egg-info clang_tools/__pycache__ +__pycache__ dist clang_tools/llvm-project* .coverage* diff --git a/docs/index.rst b/docs/index.rst index 271e116..03b61da 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -5,6 +5,8 @@ self + usage + .. toctree:: :hidden: diff --git a/docs/usage.rst b/docs/usage.rst new file mode 100644 index 0000000..7fb9428 --- /dev/null +++ b/docs/usage.rst @@ -0,0 +1,20 @@ +Using a Custom Binary Repository +-------------------------------- + +You can override the default source for downloading **clang-tools** by setting the following environment variables: + +- ``CLANG_TOOLS_REPO`` – The URL of the binary repository + (default: ``https://github.com/cpp-linter/clang-tools-static-binaries``) +- ``CLANG_TOOLS_TAG`` – The release tag to download binaries from + (default: ``master-6e612956``) + +**Example:** + +If you want to use the repository at +``https://github.com/muttleyxd/clang-tools-static-binaries``, +configure your environment like this: + +.. code-block:: bash + + export CLANG_TOOLS_REPO=https://github.com/muttleyxd/clang-tools-static-binaries + export CLANG_TOOLS_TAG=master-6e612956 # Replace with the tag you need diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000..bc907bc --- /dev/null +++ b/noxfile.py @@ -0,0 +1,33 @@ +import nox + +# Default tag for docker images +TAG = "latest" + + +@nox.session +def lint(session: nox.Session) -> None: + """Run linter""" + session.install("pre-commit") + session.run("pre-commit", "run", "--all-files", external=True) + + +@nox.session +def test(session: nox.Session) -> None: + """Run tests""" + session.install("--upgrade", "pip") + session.install("-e", ".[dev]") + session.run("coverage", "run", "-m", "pytest", "tests/", external=True) + + +@nox.session +def docs(session: nox.Session) -> None: + """Build docs""" + session.install("--upgrade", "pip") + session.install(".[docs]") + session.run("sphinx-build", "-b", "html", "docs/", "docs/_build/html") + + +@nox.session(name="docs-live") +def docs_live(session: nox.Session) -> None: + session.install(".[docs]") + session.run("sphinx-autobuild", "docs/", "docs/_build/html", external=True) diff --git a/pyproject.toml b/pyproject.toml index 02842de..cfd75a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,6 +44,11 @@ dev = [ "pre-commit", "pytest", ] +docs = [ + "sphinx", + "sphinx-autobuild", + "sphinx_immaterial", +] [tool.setuptools] zip-safe = false diff --git a/tests/clang-format-12_linux-amd64.sha512sum b/tests/clang-format-12_linux-amd64.sha512sum deleted file mode 100644 index 6c5362f..0000000 --- a/tests/clang-format-12_linux-amd64.sha512sum +++ /dev/null @@ -1 +0,0 @@ -79afa99481f071bee2be3e72d2b1641b60427cc202360e44cf4e5dc6f977c4e4223e5a29430a15c9c80720dd6f75801f4811d2848ee52fe014fc232a99a589af clang-format-12_linux-amd64 diff --git a/tests/clang-format-12_macosx-amd64.sha512sum b/tests/clang-format-12_macosx-amd64.sha512sum deleted file mode 100644 index 1499a9b..0000000 --- a/tests/clang-format-12_macosx-amd64.sha512sum +++ /dev/null @@ -1 +0,0 @@ -9be1e20c5b418e6100fb39f45ea43a0a653cb8457abd942d167187d4493028fbd0993cbf6fc574bc4158d1ec76a076c617596cc6c2a6a0135e51d0e0617a7655 clang-format-12_macosx-amd64 diff --git a/tests/clang-format-12_windows-amd64.sha512sum b/tests/clang-format-12_windows-amd64.sha512sum deleted file mode 100644 index a699963..0000000 --- a/tests/clang-format-12_windows-amd64.sha512sum +++ /dev/null @@ -1 +0,0 @@ -7c00dc5d2f715ee7f022121335f10896f092bbb8bd91c304010241fb11926b459a6995b2d79fc2171f7523b748455c53d009d69f88c81da0841ca57114fbbdce *clang-format-12_windows-amd64 diff --git a/tests/clang-format-21_linux-amd64.sha512sum b/tests/clang-format-21_linux-amd64.sha512sum new file mode 100644 index 0000000..3b26c17 --- /dev/null +++ b/tests/clang-format-21_linux-amd64.sha512sum @@ -0,0 +1 @@ +c399d13b5cd5b7cb718773009ec656cf1e402e6a95eb931b5db0cc71235fa18e6fcfe63519393d977d0457de1737f5c9f5a7d6cff57eb1e678780b85768d67b7 clang-format-21_linux-amd64 diff --git a/tests/clang-format-21_macosx-amd64.sha512sum b/tests/clang-format-21_macosx-amd64.sha512sum new file mode 100644 index 0000000..bfc6f1f --- /dev/null +++ b/tests/clang-format-21_macosx-amd64.sha512sum @@ -0,0 +1 @@ +8084fbc7638c687983606a1ae0973720fe7fc068a9d94f88212b8c220fe3dcf0770a887a46b9eaa3818ac1dad81e62cc98822970df68d1fb7dec323c1be89007 clang-format-21_macosx-amd64 diff --git a/tests/clang-format-21_windows-amd64.sha512sum b/tests/clang-format-21_windows-amd64.sha512sum new file mode 100644 index 0000000..ee0fb06 --- /dev/null +++ b/tests/clang-format-21_windows-amd64.sha512sum @@ -0,0 +1 @@ +40c290a38318fcaa28c83bc86fb8f465f1c748f7f93405ec19653fe99e58b54d71eab228065be36b7bd031dd63a8ed595ff6a909a883f06cad9300b6cb632a2e *clang-format-21_windows-amd64 diff --git a/tests/test_util.py b/tests/test_util.py index 414f5cb..47c6099 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -5,7 +5,7 @@ from clang_tools import install_os from clang_tools.install import clang_tools_binary_url from clang_tools.util import check_install_os, download_file, get_sha_checksum, Version -from clang_tools import release_tag +from clang_tools import binary_tag def test_check_install_os(): @@ -15,12 +15,12 @@ def test_check_install_os(): @pytest.mark.parametrize( - "tag", [release_tag, pytest.param("latest", marks=pytest.mark.xfail)] + "tag", [binary_tag, pytest.param("latest", marks=pytest.mark.xfail)] ) -def test_download_file(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, tag: str): +def test_download_file(monkeypatch: pytest.MonkeyPatch, tmp_path: Path): """Test that deliberately fails to download a file.""" monkeypatch.chdir(str(tmp_path)) - url = clang_tools_binary_url("clang-format", "12", tag=tag) + url = clang_tools_binary_url("clang-format", "21") file_name = download_file(url, "file.tar.gz", True) assert file_name is not None @@ -29,10 +29,10 @@ def test_get_sha(monkeypatch: pytest.MonkeyPatch): """Test the get_sha() function used to fetch the releases' corresponding SHA512 checksum.""" monkeypatch.chdir(PurePath(__file__).parent.as_posix()) - expected = Path(f"clang-format-12_{install_os}-amd64.sha512sum").read_text( + expected = Path(f"clang-format-21_{install_os}-amd64.sha512sum").read_text( encoding="utf-8" ) - url = clang_tools_binary_url("clang-format", "12", tag=release_tag) + url = clang_tools_binary_url("clang-format", "21", tag=binary_tag) assert get_sha_checksum(url) == expected From 5c1d331a04c2fb606517a89943eafc42c70fe251 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sun, 31 Aug 2025 16:18:49 +0300 Subject: [PATCH 4/5] fix: remove tag --- tests/test_util.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test_util.py b/tests/test_util.py index 47c6099..5965030 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -14,9 +14,6 @@ def test_check_install_os(): assert current_os in ("linux", "windows", "macosx") -@pytest.mark.parametrize( - "tag", [binary_tag, pytest.param("latest", marks=pytest.mark.xfail)] -) def test_download_file(monkeypatch: pytest.MonkeyPatch, tmp_path: Path): """Test that deliberately fails to download a file.""" monkeypatch.chdir(str(tmp_path)) From 2087a33c8bb6a5d93b18c2854d42f778531c2b0a Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sun, 31 Aug 2025 16:21:45 +0300 Subject: [PATCH 5/5] fix: cleanup --- noxfile.py | 3 --- tests/test_util.py | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/noxfile.py b/noxfile.py index bc907bc..e9f9258 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,8 +1,5 @@ import nox -# Default tag for docker images -TAG = "latest" - @nox.session def lint(session: nox.Session) -> None: diff --git a/tests/test_util.py b/tests/test_util.py index 5965030..6ec102a 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -5,7 +5,6 @@ from clang_tools import install_os from clang_tools.install import clang_tools_binary_url from clang_tools.util import check_install_os, download_file, get_sha_checksum, Version -from clang_tools import binary_tag def test_check_install_os(): @@ -29,7 +28,7 @@ def test_get_sha(monkeypatch: pytest.MonkeyPatch): expected = Path(f"clang-format-21_{install_os}-amd64.sha512sum").read_text( encoding="utf-8" ) - url = clang_tools_binary_url("clang-format", "21", tag=binary_tag) + url = clang_tools_binary_url("clang-format", "21") assert get_sha_checksum(url) == expected