Skip to content

Commit ec51408

Browse files
[pylint] Add pylint in the continuous integration and pre-commit
1 parent ae3d8ca commit ec51408

File tree

6 files changed

+153
-271
lines changed

6 files changed

+153
-271
lines changed

.github/workflows/checks.yaml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Checks
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
env:
12+
CACHE_VERSION: 1
13+
KEY_PREFIX: base-venv
14+
DEFAULT_PYTHON: "3.11"
15+
PRE_COMMIT_CACHE: ~/.cache/pre-commit
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
19+
cancel-in-progress: true
20+
21+
permissions:
22+
contents: read
23+
24+
jobs:
25+
prepare-base:
26+
name: Prepare base dependencies
27+
runs-on: ubuntu-latest
28+
timeout-minutes: 10
29+
outputs:
30+
python-key: ${{ steps.generate-python-key.outputs.key }}
31+
pre-commit-key: ${{ steps.generate-pre-commit-key.outputs.key }}
32+
steps:
33+
- name: Check out code from GitHub
34+
uses: actions/[email protected]
35+
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
36+
id: python
37+
uses: actions/[email protected]
38+
with:
39+
python-version: ${{ env.DEFAULT_PYTHON }}
40+
check-latest: true
41+
- name: Generate partial Python venv restore key
42+
id: generate-python-key
43+
run: >-
44+
echo "key=${{ env.KEY_PREFIX }}-${{ env.CACHE_VERSION }}-${{
45+
hashFiles('pyproject.toml', 'requirements_test.txt',
46+
'requirements_test_min.txt', 'requirements_test_pre_commit.txt') }}" >>
47+
$GITHUB_OUTPUT
48+
- name: Restore Python virtual environment
49+
id: cache-venv
50+
uses: actions/[email protected]
51+
with:
52+
path: venv
53+
key: >-
54+
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
55+
steps.generate-python-key.outputs.key }}
56+
- name: Create Python virtual environment
57+
if: steps.cache-venv.outputs.cache-hit != 'true'
58+
run: |
59+
python -m venv venv
60+
. venv/bin/activate
61+
python -m pip install -U pip setuptools wheel
62+
pip install .
63+
pip install pre-commit
64+
- name: Generate pre-commit restore key
65+
id: generate-pre-commit-key
66+
run: >-
67+
echo "key=pre-commit-${{ env.CACHE_VERSION }}-${{
68+
hashFiles('.pre-commit-config.yaml') }}" >> $GITHUB_OUTPUT
69+
- name: Restore pre-commit environment
70+
id: cache-precommit
71+
uses: actions/[email protected]
72+
with:
73+
path: ${{ env.PRE_COMMIT_CACHE }}
74+
key: >-
75+
${{ runner.os }}-${{ steps.generate-pre-commit-key.outputs.key }}
76+
- name: Install pre-commit dependencies
77+
if: steps.cache-precommit.outputs.cache-hit != 'true'
78+
run: |
79+
. venv/bin/activate
80+
pre-commit install --install-hooks
81+
82+
pylint:
83+
name: pylint
84+
runs-on: ubuntu-latest
85+
timeout-minutes: 10
86+
needs: prepare-base
87+
steps:
88+
- name: Check out code from GitHub
89+
uses: actions/[email protected]
90+
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
91+
id: python
92+
uses: actions/[email protected]
93+
with:
94+
python-version: ${{ env.DEFAULT_PYTHON }}
95+
check-latest: true
96+
- name: Restore Python virtual environment
97+
id: cache-venv
98+
uses: actions/[email protected]
99+
with:
100+
path: venv
101+
fail-on-cache-miss: true
102+
key:
103+
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
104+
needs.prepare-base.outputs.python-key }}
105+
- name: Restore pre-commit environment
106+
id: cache-precommit
107+
uses: actions/[email protected]
108+
with:
109+
path: ${{ env.PRE_COMMIT_CACHE }}
110+
fail-on-cache-miss: true
111+
key: ${{ runner.os }}-${{ needs.prepare-base.outputs.pre-commit-key }}
112+
- name: Run pylint checks
113+
run: |
114+
. venv/bin/activate
115+
pip install .
116+
pre-commit run pylint --all-files

.pre-commit-config.yaml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
ci:
2+
skip: [pylint]
3+
14
repos:
25
- repo: https://github.com/pre-commit/pre-commit-hooks
36
rev: v4.5.0
@@ -42,12 +45,12 @@ repos:
4245
# rev: v1.6.0
4346
# hooks:
4447
# - id: mypy
45-
# - repo: local
46-
# hooks:
47-
# - id: pylint
48-
# name: pylint
49-
# entry: bash -c 'test -d .venv && . .venv/bin/activate ; pylint ${CI:+--reports=yes} "$@"' -
50-
# language: system
51-
# types: [ python ]
52-
# args:
53-
# - --disable=R,C
48+
- repo: local
49+
hooks:
50+
- id: pylint
51+
name: pylint
52+
entry: bash -c 'test -d .venv && . .venv/bin/activate ; pylint "$@"' -
53+
language: system
54+
types: [ python ]
55+
exclude: "tests/input/"
56+
args: ["-sn", "-rn"]

0 commit comments

Comments
 (0)