Skip to content

Commit 3fafbd0

Browse files
De-funkdankurankan
andauthored
Adding flake8 checks in linting checks for modified python files (pgmpy#2176)
* Adding flake8 checks for modified python files in PRs * added flake8 config file for pre-commit and github actions to borrow from * Move flake8 checks to the linting workflow * Fixes branch name in flake8 checks * Fix branch name * Fetch the dev branhc * Fix linting and cancel any running workflow if a new commit is pushed --------- Co-authored-by: Ankur Ankan <ankurankan@gmail.com>
1 parent 36154b9 commit 3fafbd0

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max-line-length = 120
3+
ignore = E231,E241,E222,E221,W503
4+
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Build and Run Test Suite
22

3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
5+
cancel-in-progress: true
6+
37
on: [push, pull_request]
48

59
jobs:

.github/workflows/lint.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313
steps:
1414
- name: Checkout code
1515
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
1618

1719
- name: Setup Python ${{ matrix.python-version }}
1820
uses: actions/setup-python@v5
@@ -23,7 +25,7 @@ jobs:
2325
- name: Install linting tools
2426
run: |
2527
pip install --upgrade pip
26-
pip install black blackdoc
28+
pip install black blackdoc flake8
2729
2830
- name: Check code formatting
2931
run: |
@@ -34,3 +36,21 @@ jobs:
3436
run: |
3537
blackdoc --diff pgmpy
3638
blackdoc --check pgmpy
39+
40+
- name: Fetch dev branch
41+
run: git fetch origin dev:dev
42+
43+
- name: Get modified Python files
44+
id: files
45+
run: |
46+
FILES=$(git diff --name-only dev...HEAD | grep '\.py$' | paste -sd' ' -)
47+
echo "files=$FILES" >> "$GITHUB_OUTPUT"
48+
49+
- name: Flake8
50+
run: |
51+
if [ -n "${{ steps.files.outputs.files }}" ]; then
52+
echo "Running flake8 on: ${{ steps.files.outputs.files }}"
53+
flake8 --config=.flake8 ${{ steps.files.outputs.files }}
54+
else
55+
echo "No Python files changed."
56+
fi

.pre-commit-config.yaml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.6.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
88
- repo: https://github.com/pycqa/isort
9-
rev: 5.13.2
9+
rev: 6.0.1
1010
hooks:
1111
- id: isort
1212
args: ["--profile", "black", "--filter-files"]
1313
- repo: https://github.com/psf/black
14-
rev: 24.8.0
14+
rev: 25.1.0
1515
hooks:
1616
- id: black
17+
- repo: https://github.com/Pycqa/flake8
18+
rev: 7.2.0
19+
hooks:
20+
- id: flake8
1721
- repo: https://github.com/keewis/blackdoc
1822
rev: v0.4.0
1923
hooks:
2024
- id: blackdoc
21-
additional_dependencies: ["black==24.8.0"]
22-
- repo: https://github.com/PyCQA/flake8
23-
rev: 7.2.0
24-
hooks:
25-
- id: flake8
26-
args: ["--max-line-length=120", "--ignore=E231,E241,E222,E221,W503"]
25+
additional_dependencies: ["black==24.8.0"]

0 commit comments

Comments
 (0)