From 41e7389ce9ed7b9acc0032e6d58ae835cb4d1ed0 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Tue, 17 Dec 2024 08:05:50 +0200 Subject: [PATCH] feat: support testing on diff python versions (#56) * feat: test.yml to support test on diff python versions * feat: update python versions * feat: update python versions * feat: update README.md and add requires-python --- .github/workflows/test.yml | 10 ++++++++-- .gitignore | 1 + README.md | 23 ++++++++++++++--------- pyproject.toml | 10 +++++++++- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 48e31d3..442ef69 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,13 +10,18 @@ on: jobs: test: runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.14.0-alpha.2", "3.13", "3.12", "3.11", "3.10", "3.9", "3.8"] steps: - name: Checkout uses: actions/checkout@v4 - - name: Set up Python 3.12 + + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: - python-version: "3.12" + python-version: ${{ matrix.python-version }} + - name: Install dependencies run: | python -m pip install --upgrade pip @@ -29,6 +34,7 @@ jobs: coverage report coverage xml - uses: codecov/codecov-action@v5 + if: matrix.python-version == '3.13' with: token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage.xml diff --git a/.gitignore b/.gitignore index 63a7452..1a7fa37 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ tests/__pycache__ coverage.xml __pycache__ venv +.venv result.txt testing/main.c */*compile_commands.json diff --git a/README.md b/README.md index fe81048..922260d 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,23 @@ # cpp-linter-hooks -[![PyPI](https://img.shields.io/pypi/v/cpp-linter-hooks)](https://pypi.org/project/cpp-linter-hooks/) +[![PyPI](https://img.shields.io/pypi/v/cpp-linter-hooks?color=blue)](https://pypi.org/project/cpp-linter-hooks/) +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cpp-linter-hooks)](https://pypi.org/project/cpp-linter-hooks/) [![codecov](https://codecov.io/gh/cpp-linter/cpp-linter-hooks/branch/main/graph/badge.svg?token=L74Z3HZ4Y5)](https://codecov.io/gh/cpp-linter/cpp-linter-hooks) [![Test](https://github.com/cpp-linter/cpp-linter-hooks/actions/workflows/test.yml/badge.svg)](https://github.com/cpp-linter/cpp-linter-hooks/actions/workflows/test.yml) [![CodeQL](https://github.com/cpp-linter/cpp-linter-hooks/actions/workflows/codeql.yml/badge.svg)](https://github.com/cpp-linter/cpp-linter-hooks/actions/workflows/codeql.yml) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) -cpp-linter-hooks is a [pre-commit](https://pre-commit.com/) hook that uses clang-format and clang-tidy to check your C/C++ code. +cpp-linter-hooks is a [pre-commit](https://pre-commit.com/) hook that uses `clang-format` and `clang-tidy` to format C/C++ code. > [!NOTE] -> This hook automatically downloads a specific version of `clang-format` or `clang-tidy` [binaries](https://github.com/cpp-linter/clang-tools-static-binaries) and installs it on the system. +> This hook automatically downloads specific versions of `clang-format` or `clang-tidy` [binaries](https://github.com/cpp-linter/clang-tools-static-binaries) and installs them on your system. ## Usage -Add the following configuration to your `.pre-commit-config.yaml`: +To use cpp-linter-hooks, add the following configuration to your `.pre-commit-config.yaml`: + +### Basic Configuration ```yaml repos: @@ -27,6 +30,8 @@ repos: args: [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*'] ``` +### Custom Configuration + To use custom configurations like `.clang-format` and `.clang-tidy`: ```yaml @@ -55,7 +60,7 @@ repos: ## Output -### clang-format output +### clang-format Example ```bash clang-format.............................................................Failed @@ -63,7 +68,7 @@ clang-format.............................................................Failed - files were modified by this hook ``` -The diff between the modified file is as follows: +Here’s a sample diff showing the formatting applied: ```diff --- a/testing/main.c @@ -106,7 +111,7 @@ int main() {for (;;) break; printf("Hello world!\n");return 0;} ^ ``` -### clang-tidy output +### clang-tidy Example ```bash clang-tidy...............................................................Failed @@ -125,8 +130,8 @@ Use -header-filter=.* to display errors from all non-system headers. Use -system ## Contributing -Contributions are very welcome, including submitting issues, PRs, etc. +We welcome contributions! Whether it's fixing issues, suggesting improvements, or submitting pull requests, your support is greatly appreciated. ## License -[MIT](LICENSE) +cpp-linter-hooks is licensed under the [MIT License](LICENSE) diff --git a/pyproject.toml b/pyproject.toml index 0be470c..428692e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,8 @@ requires = ["setuptools>=45", "setuptools-scm"] build-backend = "setuptools.build_meta" +requires-python = ">=3.8" + [project] name = "cpp_linter_hooks" description = "Automatically check c/c++ code with clang-format and clang-tidy" @@ -21,7 +23,13 @@ classifiers = [ "Operating System :: Microsoft :: Windows", "Operating System :: POSIX :: Linux", "Operating System :: MacOS", - "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", "Topic :: Software Development :: Build Tools", ] dependencies = [