From 736e69265a13763044d30cd04a3280b4d95c9df8 Mon Sep 17 00:00:00 2001 From: Roman Cattaneo <1116746+romanc@users.noreply.github.com> Date: Fri, 28 Feb 2025 10:36:26 +0100 Subject: [PATCH 1/2] [to be reverted] turn off all CI except new linting --- .github/workflows/fpga-ci.yml | 2 +- .github/workflows/general-ci.yml | 2 +- .github/workflows/gpu-ci.yml | 2 +- .github/workflows/heterogeneous-ci.yml | 2 +- .github/workflows/pyFV3-ci.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/fpga-ci.yml b/.github/workflows/fpga-ci.yml index 2d6d42514f..581d8d4e98 100644 --- a/.github/workflows/fpga-ci.yml +++ b/.github/workflows/fpga-ci.yml @@ -13,7 +13,7 @@ env: jobs: test-fpga: - if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-ci') }} + if: False # ${{ !contains(github.event.pull_request.labels.*.name, 'no-ci') }} runs-on: [self-hosted, linux, intel-fpga, xilinx-fpga] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/general-ci.yml b/.github/workflows/general-ci.yml index 8d622f758f..930ac95b23 100644 --- a/.github/workflows/general-ci.yml +++ b/.github/workflows/general-ci.yml @@ -10,7 +10,7 @@ on: jobs: test: - if: "!contains(github.event.pull_request.labels.*.name, 'no-ci')" + if: False # "!contains(github.event.pull_request.labels.*.name, 'no-ci')" runs-on: ubuntu-latest strategy: matrix: diff --git a/.github/workflows/gpu-ci.yml b/.github/workflows/gpu-ci.yml index b3af9c8c05..c4f83bebb7 100644 --- a/.github/workflows/gpu-ci.yml +++ b/.github/workflows/gpu-ci.yml @@ -16,7 +16,7 @@ env: jobs: test-gpu: - if: "!contains(github.event.pull_request.labels.*.name, 'no-ci')" + if: False # "!contains(github.event.pull_request.labels.*.name, 'no-ci')" runs-on: [self-hosted, gpu] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/heterogeneous-ci.yml b/.github/workflows/heterogeneous-ci.yml index 62887ad208..781cdc2467 100644 --- a/.github/workflows/heterogeneous-ci.yml +++ b/.github/workflows/heterogeneous-ci.yml @@ -16,7 +16,7 @@ env: jobs: test-heterogeneous: - if: "!contains(github.event.pull_request.labels.*.name, 'no-ci')" + if: False # "!contains(github.event.pull_request.labels.*.name, 'no-ci')" runs-on: [self-hosted, linux] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/pyFV3-ci.yml b/.github/workflows/pyFV3-ci.yml index 2f587e9894..8419293314 100644 --- a/.github/workflows/pyFV3-ci.yml +++ b/.github/workflows/pyFV3-ci.yml @@ -19,7 +19,7 @@ defaults: jobs: build_and_validate_pyFV3: - if: "!contains(github.event.pull_request.labels.*.name, 'no-ci')" + if: False # "!contains(github.event.pull_request.labels.*.name, 'no-ci')" runs-on: ubuntu-latest strategy: matrix: From 4c3bc67e3f56421c9a726587d4fedbde4fcc7b44 Mon Sep 17 00:00:00 2001 From: Roman Cattaneo <1116746+romanc@users.noreply.github.com> Date: Fri, 28 Feb 2025 11:53:32 +0100 Subject: [PATCH 2/2] PoC: automated linting on CI This PR is to support the discussion on enforcing consistent formatting on the CI [1]. [1] https://github.com/spcl/dace/discussions/1804 --- .github/workflows/linting.yml | 29 +++++++++++++++++++++++++++++ .pre-commit-config.yaml | 20 ++++++++++++++++++++ CONTRIBUTING.md | 23 +++++++++++++++++++++-- setup.py | 3 ++- 4 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/linting.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 0000000000..2a39be2030 --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,29 @@ +name: Code Quality + +on: + push: + branches: [ main, ci-fix ] + pull_request: + branches: [ main, ci-fix ] + +jobs: + linting: + if: "!contains(github.event.pull_request.labels.*.name, 'no-ci')" + name: pre-commit + runs-on: ubuntu-latest + + steps: + - name: Check repository + uses: actions/checkout@v4 + + - name: Setup Python 3.13 + uses: actions/setup-python@v5 + with: + python-version: '3.13' + cache: 'pip' + + - name: Install linting tools + run: pip install pre-commit yapf + + - name: Run linting tools + run: pre-commit run --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..23b22cbce4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +default_language_version: + python: python3 + +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-merge-conflict + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace +- repo: https://github.com/google/yapf + rev: v0.43.0 + hooks: + - id: yapf + name: yapf + language: python + entry: yapf + args: [-i] + types: [python] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 313b3f0f21..6e8c62cace 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,9 +38,28 @@ def example_function(param_a: str, *args: Optional[SDFG]) -> bool: ... ``` +For automatic styling, we rely on [pre-commit](https://pre-commit.com/) and use the [yapf](https://github.com/google/yapf) file formatter. +**Please run `pre-commit` before making your pull request ready for review.** -For automatic styling, we use the [yapf](https://github.com/google/yapf) file formatter. -**Please run `yapf` before making your pull request ready for review.** +```bash +pre-commit run --all-files +``` + +Formatting will be evaluated as part of CI and you won't be able to merge unless formatting issues are resolved. To get `pre-commit` and `yapf`, be sure to install the `linting` extra, e.g. for contributors we recommend + +```bash +pip install -e ".[testing,linting]" +``` + +to get testing and linting extras in an editable install. + +One way to always ensure consistency with our coding standards is to install pre-commit hooks, which will check formatting issues of changed files before every commit. If you wish to do so, run + +```bash +pre-commit install +``` + +to install the `git` hooks for this repository. ## Tests diff --git a/setup.py b/setup.py index fbe95715cb..54507c39a1 100644 --- a/setup.py +++ b/setup.py @@ -79,7 +79,8 @@ ] + cmake_requires, extras_require={ 'testing': ['coverage', 'pytest-cov', 'scipy', 'absl-py', 'opt_einsum', 'pymlir', 'click'], - 'docs': ['jinja2<3.2.0', 'sphinx-autodoc-typehints', 'sphinx-rtd-theme>=0.5.1'] + 'docs': ['jinja2<3.2.0', 'sphinx-autodoc-typehints', 'sphinx-rtd-theme>=0.5.1'], + 'linting': ['pre-commit', 'yapf'], }, entry_points={ 'console_scripts': [