Skip to content

Commit

Permalink
CI: Add Pylint check for selected files (#2198)
Browse files Browse the repository at this point in the history
This adds Pylint check job in a new workflow. It uses the current latest Pylint and latest Python. It uses Pylint to check for minimal supported Python version.

The check runs for the grass package (python/grass) and for wxGUI (gui/wxpython). However, most of the files are ignored. Each of the directories has its own .pylintrc file.

Pylint runs for grass.jupyter and grass.benchmark with only slightly modified configuration after fixes in targeted files (#2199, #2200, #2201, #2206). The approach for future compliance is that the other sub-packages should also eventually comply with default or almost default configuration.

For wxGUI, many Pylint messages are disabled and numbers driving coding standard limits, such as max number of local variables, are greatly loosened. Many of the disabled messages show real errors, but ignoring these for now allowed for enabling the check right away at least for the least problematic directories. The approach for future compliance is that new directories can be added (removed from ignore paths) and new issues can be checked (removed from disable) when fixed.

This compiles the code. Just testing Python functions from the grass package in the python directory does not require compiled code and package on path when started from the python directory, but checking other files requires packages on path.

The config file is in the python directory because that's the focus of this PR. (In the future, GUI may have a different config file, e.g., due to different naming conventions. On the other hand, in an ideal case, the whole source code will use this file or even a more strict version of this file in the future.)

Pylint should produce warning for disabled warnings which are not generated, although that seems to not be the case right now (useless-suppression).

The only code change here is that Pylint disable comment needs to be on the same line or inside ().

It needs to install also all optional Python dependencies because Pylint checks (can check unless disabled) all imports. This change is applied also to pytest workflow.

Using workflow on settings to run on push only to main and release branches and semver tags.

It uses strategy.matrix.include to get job-level config variables without using environmental variables.
  • Loading branch information
wenzeslaus committed Feb 15, 2022
1 parent 74aac0a commit 5c34325
Show file tree
Hide file tree
Showing 8 changed files with 1,385 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/optional_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
folium
jupyter
PyVirtualDisplay
82 changes: 82 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Python Pylint Code Quality

on:
push:
branches:
- main
- releasebranch_*
tags:
- "*.*.*"
pull_request:

jobs:
pylint:
name: "Pylint ${{ matrix.pylint-version }}"

# Using matrix just to get variables which are not environmental variables
# and also to sync with other workflows which use matrix.
strategy:
matrix:
include:
- os: ubuntu-20.04
python-version: "3.10"
min-python-version: "3.6"
pylint-version: "2.12.2"

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install non-Python dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y wget git gawk findutils
xargs -a <(awk '! /^ *(#|$)/' ".github/workflows/apt.txt") -r -- \
sudo apt-get install -y --no-install-recommends --no-install-suggests
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r .github/workflows/python_requirements.txt
pip install -r .github/workflows/optional_requirements.txt
pip install pylint==${{ matrix.pylint-version }}
- name: Create installation directory
run: |
mkdir $HOME/install
- name: Set number of cores for compilation
run: |
echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV
- name: Set LD_LIBRARY_PATH for compilation
run: |
echo "LD_LIBRARY_PATH=$HOME/install/lib" >> $GITHUB_ENV
- name: Build
run: .github/workflows/build_${{ matrix.os }}.sh $HOME/install

- name: Add the bin directory to PATH
run: |
echo "$HOME/install/bin" >> $GITHUB_PATH
- name: Test executing of the grass command
run: .github/workflows/test_simple.sh

- name: Run Pylint on grass package
run: |
export PYTHONPATH=`grass --config python_path`:$PYTHONPATH
cd python
pylint --persistent=no --py-version=${{ matrix.min-python-version }} --jobs=$(nproc) grass
- name: Run Pylint on wxGUI
run: |
export PYTHONPATH=`grass --config python_path`:$PYTHONPATH
cd gui/wxpython
pylint --persistent=no --py-version=${{ matrix.min-python-version }} --jobs=$(nproc) *
1 change: 1 addition & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r .github/workflows/python_requirements.txt
pip install -r .github/workflows/optional_requirements.txt
pip install pytest
- name: Create installation directory
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/python_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ matplotlib
numpy
Pillow
ply
PyVirtualDisplay

0 comments on commit 5c34325

Please sign in to comment.