Skip to content

Commit

Permalink
make: replace flake8 with ruff
Browse files Browse the repository at this point in the history
Ruff (https://github.com/astral-sh/ruff) is a Python linter
written in Rust, designed to replace Flake8. It is significantly
faster and actively maintained.

In addition to replacing flake8 with ruff, this patch also
creates separate makefile targets for ruff, shellcheck and
codespell, so that they can be tested independently.

RUFF_FLAGS can be used to specify options such as '--fix'.
Example:
	make lint
	make ruff RUFF_FLAGS=--fix

Signed-off-by: Radostin Stoyanov <[email protected]>
  • Loading branch information
rst0git authored and avagin committed Feb 13, 2024
1 parent cac03be commit 8a22b15
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ task:
ln -sf /usr/include/google/protobuf/descriptor.proto images/google/protobuf/descriptor.proto
dnf config-manager --set-enabled crb # Same as CentOS 8 powertools
dnf -y install epel-release epel-next-release
dnf -y install --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python-devel python-PyYAML python-protobuf python-junit_xml python3-importlib-metadata python-flake8 xmlto libdrm-devel
dnf -y install --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python-devel python-PyYAML python-protobuf python-junit_xml python3-importlib-metadata xmlto libdrm-devel
# The image has a too old version of nettle which does not work with gnutls.
# Just upgrade to the latest to make the error go away.
dnf -y upgrade nettle nettle-devel
Expand Down Expand Up @@ -111,7 +111,7 @@ task:
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm || :
yum install -y dnf-plugins-core
yum config-manager --set-enabled powertools
yum install -y --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python3-devel python3-flake8 python3-PyYAML python3-protobuf python3-importlib-metadata python3-junit_xml xmlto libdrm-devel
yum install -y --allowerasing asciidoc gcc git gnutls-devel libaio-devel libasan libcap-devel libnet-devel libnl3-devel libbsd-devel libselinux-devel make protobuf-c-devel protobuf-devel python3-devel python3-PyYAML python3-protobuf python3-importlib-metadata python3-junit_xml xmlto libdrm-devel
alternatives --set python /usr/bin/python3
systemctl stop sssd
# Even with selinux in permissive mode the selinux tests will be executed
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
image: registry.fedoraproject.org/fedora:latest
steps:
- name: Install tools
run: sudo dnf -y install git make python3-flake8 xz clang-tools-extra which codespell git-clang-format ShellCheck
run: sudo dnf -y install git make ruff xz clang-tools-extra which codespell git-clang-format ShellCheck

- uses: actions/checkout@v2

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Other conventions can be learned from the source code itself. In short, make sur

Important: These tools are there to advise you, but should not be considered as a "source of truth", as tools also make nasty mistakes from time to time which can completely break code readability.

The following command can be used to automatically run a code linter for Python files (flake8), Shell scripts (shellcheck),
The following command can be used to automatically run a code linter for Python files (ruff), Shell scripts (shellcheck),
text spelling (codespell), and a number of CRIU-specific checks (usage of print macros and EOL whitespace for C files).

```
Expand Down
37 changes: 22 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -436,20 +436,23 @@ help:
@echo ' amdgpu_plugin - Make AMD GPU plugin'
.PHONY: help

lint:
flake8 --version
flake8 --config=scripts/flake8.cfg test/zdtm.py
flake8 --config=scripts/flake8.cfg test/inhfd/*.py
flake8 --config=scripts/flake8.cfg test/others/rpc/config_file.py
flake8 --config=scripts/flake8.cfg lib/pycriu/images/pb2dict.py
flake8 --config=scripts/flake8.cfg lib/pycriu/images/images.py
flake8 --config=scripts/flake8.cfg scripts/criu-ns
flake8 --config=scripts/flake8.cfg test/others/criu-ns/run.py
flake8 --config=scripts/flake8.cfg crit/*.py
flake8 --config=scripts/flake8.cfg crit/crit/*.py
flake8 --config=scripts/flake8.cfg scripts/uninstall_module.py
flake8 --config=scripts/flake8.cfg coredump/ coredump/coredump
flake8 --config=scripts/flake8.cfg scripts/github-indent-warnings.py
ruff:
@ruff --version
ruff ${RUFF_FLAGS} --config=scripts/ruff.toml \
test/zdtm.py \
test/inhfd/*.py \
test/others/rpc/config_file.py \
lib/pycriu/images/pb2dict.py \
lib/pycriu/images/images.py \
scripts/criu-ns \
test/others/criu-ns/run.py \
crit/*.py \
crit/crit/*.py \
scripts/uninstall_module.py \
coredump/ coredump/coredump \
scripts/github-indent-warnings.py

shellcheck:
shellcheck --version
shellcheck scripts/*.sh
shellcheck scripts/ci/*.sh scripts/ci/apt-install
Expand All @@ -458,7 +461,11 @@ lint:
shellcheck -x test/others/crit/*.sh test/others/criu-coredump/*.sh
shellcheck -x test/others/config-file/*.sh
shellcheck -x test/others/action-script/*.sh

codespell:
codespell -S tags

lint: ruff shellcheck codespell
# Do not append \n to pr_perror, pr_pwarn or fail
! git --no-pager grep -E '^\s*\<(pr_perror|pr_pwarn|fail)\>.*\\n"'
# Do not use %m with pr_* or fail
Expand All @@ -469,7 +476,7 @@ lint:
! git --no-pager grep -En '^\s*\<pr_(err|warn|msg|info|debug)\>.*);$$' | grep -v '\\n'
# No EOL whitespace for C files
! git --no-pager grep -E '\s+$$' \*.c \*.h
.PHONY: lint
.PHONY: lint ruff shellcheck codespell

codecov: SHELL := $(shell which bash)
codecov:
Expand Down
1 change: 0 additions & 1 deletion scripts/build/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ RUN apk add \
go \
e2fsprogs \
py-yaml \
py3-flake8 \
py3-importlib-metadata \
asciidoctor

Expand Down
1 change: 0 additions & 1 deletion scripts/build/Dockerfile.archlinux
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ RUN pacman -Syu --noconfirm \
bash \
go \
python-yaml \
flake8 \
asciidoctor \
python-junit-xml \
python-importlib-metadata \
Expand Down
1 change: 0 additions & 1 deletion scripts/build/Dockerfile.centos8
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ RUN yum install -y --allowerasing \
protobuf-c-devel \
protobuf-devel \
python3-devel \
python3-flake8 \
python3-PyYAML \
python3-protobuf \
python3-pip \
Expand Down
1 change: 0 additions & 1 deletion scripts/ci/prepare-for-fedora-rawhide.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ dnf install -y \
procps-ng \
protobuf-c-devel \
protobuf-devel \
python3-flake8 \
python3-PyYAML \
python3-protobuf \
python3-junit_xml \
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/run-ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -x -e
CI_PKGS=(protobuf-c-compiler libprotobuf-c-dev libaio-dev libgnutls28-dev
libgnutls30 libprotobuf-dev protobuf-compiler libcap-dev
libnl-3-dev gdb bash libnet-dev util-linux asciidoctor
libnl-route-3-dev time flake8 libbsd-dev python3-yaml
libnl-route-3-dev time libbsd-dev python3-yaml
libperl-dev pkg-config python3-protobuf python3-pip
python3-importlib-metadata python3-junit.xml libdrm-dev)

Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/vagrant.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ setup() {
ssh default sudo dnf upgrade -y
ssh default sudo dnf install -y gcc git gnutls-devel nftables-devel libaio-devel \
libasan libcap-devel libnet-devel libnl3-devel libbsd-devel make protobuf-c-devel \
protobuf-devel python3-flake8 python3-protobuf python3-importlib-metadata \
python3-junit_xml rubygem-asciidoctor iptables libselinux-devel libbpf-devel
protobuf-devel python3-protobuf python3-importlib-metadata python3-junit_xml \
rubygem-asciidoctor iptables libselinux-devel libbpf-devel
# Disable sssd to avoid zdtm test failures in pty04 due to sssd socket
ssh default sudo systemctl mask sssd
ssh default cat /proc/cmdline
Expand Down
4 changes: 4 additions & 0 deletions scripts/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore `E401` (import violations) in all `__init__.py` files
[lint.per-file-ignores]
"__init__.py" = ["F401"]

0 comments on commit 8a22b15

Please sign in to comment.