From 9429c93702c88a2d2ca506f30117258ba7fae61c Mon Sep 17 00:00:00 2001 From: Alan Mansour Date: Wed, 5 Nov 2025 17:47:45 +0100 Subject: [PATCH 1/2] Update formatting and linting process --- .github/workflows/format-lint.yml | 38 ++++++++++++++ .github/workflows/lint-format.yml | 84 ------------------------------- 2 files changed, 38 insertions(+), 84 deletions(-) create mode 100644 .github/workflows/format-lint.yml delete mode 100644 .github/workflows/lint-format.yml diff --git a/.github/workflows/format-lint.yml b/.github/workflows/format-lint.yml new file mode 100644 index 0000000..74bd3db --- /dev/null +++ b/.github/workflows/format-lint.yml @@ -0,0 +1,38 @@ +name: Lint and Format + +on: [push, pull_request] + +jobs: + python-format-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + - name: Install Ruff + run: pip install ruff + - name: Find Python Packages, and then Format and Lint + run: | + for pkg in $(find . -name pyproject.toml -exec dirname {} \;); do + echo "Processing Python package in $pkg" + ruff format "$pkg" + ruff check "$pkg" + done + cpp-format-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install clang-tidy and clang-format + run: sudo apt-get update && sudo apt-get install -y cmake clang + - name: Find C++ Packages, and then Format and Lint + run: | + for pkg in $(find . -name CMakeLists.txt -exec dirname {} \;); do + echo "Processing C++ package in $pkg" + clang-format -i $(find "$pkg" -name '*.cpp' -o -name '*.hpp') + cmake -S "$pkg" -B "$pkg/build" \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-header-filter=.;-checks=*" + cmake --build "$pkg/build" -j"$(nproc)" + done \ No newline at end of file diff --git a/.github/workflows/lint-format.yml b/.github/workflows/lint-format.yml deleted file mode 100644 index f6956bb..0000000 --- a/.github/workflows/lint-format.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: Lint and Format - -on: [push, pull_request] - -jobs: - python-lint-format: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - name: Install Ruff - run: pip install ruff - - name: Find and Lint Python Packages - run: | - for pkg in $(find . -name pyproject.toml -exec dirname {} \;); do - echo "Linting $pkg" - ruff check "$pkg" - ruff format "$pkg" - done - cpp-lint-format: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install clang-tidy and clang-format - run: sudo apt-get update && sudo apt-get install -y cmake clang - - name: Find and Process C++ Packages - run: | - for pkg in $(find . -name CMakeLists.txt -exec dirname {} \;); do - echo "Processing C++ package in $pkg" - cmake -S "$pkg" -B "$pkg/build" \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-header-filter=.;-checks=*" - cmake --build "$pkg/build" -j"$(nproc)" - clang-format -i $(find "$pkg" -name '*.cpp' -o -name '*.hpp') - done - -# name: Lint and Format - -# on: [push, pull_request] - -# jobs: -# python-lint-format: -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v4 -# - name: Set up Python -# uses: actions/setup-python@v5 -# with: -# python-version: '3.11' -# - name: Install Ruff -# run: pip install ruff -# - name: Run Ruff (lint) -# run: ruff check src/py_pkg -# - name: Run Ruff (format) -# run: ruff format src/py_pkg - -# cpp-lint-format: -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v4 - -# - name: Install clang-tidy and clang-format -# run: sudo apt-get update && sudo apt-get install -y cmake clang - -# - name: Configure (CMake) With clang-tidy -# run: | -# cmake -S src/cpp_pkg -B src/cpp_pkg/build \ -# -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -# -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-header-filter=.;-checks=*"; - -# - name: Build -# run: cmake --build src/cpp_pkg/build -j"$(nproc)" - -# # - name: Run clang-tidy -# # run: | -# # for file in $(find src/cpp_pkg -name '*.cpp' -o -name '*.hpp'); do -# # clang-tidy "$file" -p src/cpp_pkg/build -warnings-as-errors=* -# # done - -# - name: Run clang-format -# run: clang-format -i src/cpp_pkg/**/*.cpp src/cpp_pkg/**/*.hpp \ No newline at end of file From 1fd2c326342d3c31f52bddccf8a21895c7df6ebf Mon Sep 17 00:00:00 2001 From: Alan Mansour Date: Wed, 5 Nov 2025 17:53:29 +0100 Subject: [PATCH 2/2] Update README files about formatting and liniting --- README.md | 2 +- lib/README.md | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0e81a8a..517db29 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # C++/Python Project Template -This is a standardized C++/Python project template for DALSA projects that will be hosted on GitHub, designed to help project owners quickly set up new projects with a consistent structure and DevOps features. Its goal is to ensure maintainability and collaboration by enforcing standards that make future contributions and usage seamless. The template integrates **Sphinx** + **Doxygen** for unified documentation of both C++ and Python packages, and uses GitHub Actions to automate the generation of web-based documentation, code analysis (linting), code rewrites to follow a consistent style (formatting), and execution of tests. +This is a standardized C++/Python project template for DALSA projects that will be hosted on GitHub, designed to help project owners quickly set up new projects with a consistent structure and DevOps features. Its goal is to ensure maintainability and collaboration by enforcing standards that make future contributions and usage seamless. The template integrates **Sphinx** + **Doxygen** for unified documentation of both C++ and Python packages, and uses GitHub Actions to automate the generation of web-based documentation, code rewrites to follow a consistent style (formatting), code analysis (linting), and execution of tests. This template introduces a certain structure so that users and contributors can quickly understand your project. --- diff --git a/lib/README.md b/lib/README.md index 91c2bf4..34fd71a 100644 --- a/lib/README.md +++ b/lib/README.md @@ -80,28 +80,28 @@ Together, being **modular** and **self-contained** ensures that each package can - **Build System**: CMake - **Compiler**: Clang (installed via LLVM) - **Build Tool**: Ninja -- **Linting**: `clang-tidy` - **Formatting**: `clang-format` +- **Linting**: `clang-tidy` > If you want to use the same tools (CMake, Clang and Ninja), make sure to install them in your machine. Assuming you are in the root directory of the package: -To build (with liniting): +To format: ```bash -cmake -S . -B build -G "Ninja" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-header-filter=.;-checks=*;" -cmake --build build +clang-format -i src/*.cpp include/*.hpp ``` -To format: +To build (with linting): ```bash -clang-format -i src/*.cpp include/*.hpp +cmake -S . -B build -G "Ninja" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-header-filter=.;-checks=*;" +cmake --build build ``` ### Python (`py_pkg`) - **Packaging and Dependency Management Tool**: Poetry - **Configuration Tool**: pyproject.toml -- **Linting & Formatting**: Ruff +- **Formatting & Linting**: Ruff > Remember that with Python no build step is required. @@ -124,10 +124,10 @@ And then activate it (on Windows via CMD): "myenv/Scripts/activate.bat" ``` -To lint and format: +To format and lint: ```bash +ruff format . ruff check . -ruff check . --fix ``` You can also build your project into a distributable format (wheel and source tarball):