From 17c0adeb135fe25be47f0db172d37cb01f47ffc9 Mon Sep 17 00:00:00 2001 From: Manikantasai1724 Date: Sat, 28 Feb 2026 17:10:54 +0530 Subject: [PATCH] Improve CI quality gates with pre-commit, Ruff, and smoke test --- .github/CONTRIBUTING.md | 12 ++++++ .github/workflows/linters.yaml | 48 +++++++++++++++++++++ .pre-commit-config.yaml | 21 ++++++++++ .ruff.toml | 5 +++ azure-pipelines.yml | 77 ++++++++++++++++++++++++++++++++++ 5 files changed, 163 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100644 .ruff.toml diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index abb069923fc..1e9fa2525d3 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -16,3 +16,15 @@ If you're contributing code, please check out [How to contribute](https://www.md MDAnalysis devs are most easily reached through the [development list](https://groups.google.com/forum/#!forum/mdnalysis-devel). +#### Local quality checks + +Before opening a pull request, please run the same style checks locally using pre-commit: + +```bash +python -m pip install pre-commit +pre-commit install +pre-commit run --all-files +``` + +Running these checks before pushing helps keep pull requests focused and reduces CI turnaround time. + diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index 0427d46b747..83f892f83e7 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -16,6 +16,54 @@ defaults: shell: bash -l {0} jobs: + precommit: + if: "github.repository == 'MDAnalysis/mdanalysis'" + runs-on: ubuntu-latest + timeout-minutes: 10 + env: + PRE_COMMIT_HOME: ~/.cache/pre-commit + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: cache pre-commit + uses: actions/cache@v4 + with: + path: ~/.cache/pre-commit + key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }} + + - name: install pre-commit + run: | + python -m pip install --upgrade pip pre-commit + + - name: run pre-commit + run: | + pre-commit run --all-files + + ruff_check: + if: "github.repository == 'MDAnalysis/mdanalysis'" + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: install ruff + run: | + python -m pip install --upgrade pip ruff + + - name: run ruff + run: | + ruff check package testsuite + black: if: "github.repository == 'MDAnalysis/mdanalysis'" runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000000..9fc78a19f16 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-ast + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.9.10 + hooks: + - id: ruff + files: ^(package|testsuite)/ + + - repo: https://github.com/psf/black + rev: 24.10.0 + hooks: + - id: black + files: ^(package|testsuite)/ + args: [--line-length=88] diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 00000000000..27bda73ba98 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,5 @@ +line-length = 88 +target-version = "py311" + +[lint] +select = ["E9", "F63", "F7", "F82"] diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 659eeff70d0..decf8617a52 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -15,7 +15,84 @@ pr: jobs: +- job: Precommit_Lint + displayName: 'Pre-commit checks' + pool: + vmImage: 'ubuntu-latest' + variables: + PRE_COMMIT_HOME: '$(Pipeline.Workspace)/.pre-commit-cache' + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.11' + addToPath: true + architecture: 'x64' + - task: Cache@2 + inputs: + key: 'pre-commit | "$(Agent.OS)" | .pre-commit-config.yaml' + path: '$(PRE_COMMIT_HOME)' + restoreKeys: | + pre-commit | "$(Agent.OS)" + - script: python -m pip install --upgrade pip pre-commit + displayName: 'Install pre-commit' + - script: PRE_COMMIT_HOME=$(PRE_COMMIT_HOME) pre-commit run --all-files + displayName: 'Run pre-commit hooks' + +- job: Ruff_Lint + displayName: 'Ruff lint checks' + pool: + vmImage: 'ubuntu-latest' + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.11' + addToPath: true + architecture: 'x64' + - script: python -m pip install --upgrade pip ruff + displayName: 'Install ruff' + - script: ruff check package testsuite + displayName: 'Run ruff checks' + +- job: Smoke_Tests + displayName: 'Smoke tests' + pool: + vmImage: 'ubuntu-latest' + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.11' + addToPath: true + architecture: 'x64' + - script: python -m pip install --upgrade pip setuptools wheel + displayName: 'Install tools' + - script: >- + python -m pip install --only-binary=scipy,h5py + cython + h5py>=2.10 + matplotlib + numpy + packaging + pytest + tqdm + threadpoolctl + filelock + displayName: 'Install smoke dependencies' + - script: >- + python -m pip install + ./package + ./testsuite + displayName: 'Install package and testsuite' + - script: >- + pytest testsuite/MDAnalysisTests/test_api.py + --disable-pytest-warnings + -q + displayName: 'Run smoke tests' + - job: Azure_Tests + dependsOn: + - Precommit_Lint + - Ruff_Lint + - Smoke_Tests condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/develop')) # skip for PR merges variables: MPLBACKEND: agg