1
0
forked from drath/libratbag

build: add Ruff for Python code linting

This commit is contained in:
Yaroslav Chvanov
2023-03-01 17:08:53 +03:00
parent 49146638a6
commit 3aa82d2b35
5 changed files with 59 additions and 1 deletions

View File

@@ -8,7 +8,7 @@ env:
libjson-glib-dev libsystemd-dev libudev-dev libunistring-dev
python3-dev python3-evdev swig python3-sphinx
UBUNTU_DEP_TEST: check python3-gi python3-lxml valgrind
PIP_PACKAGES: meson ninja libevdev pyudev pytest sphinx_rtd_theme black
PIP_PACKAGES: meson ninja libevdev pyudev pytest sphinx_rtd_theme black ruff
jobs:
build-and-dist:

View File

@@ -649,4 +649,21 @@ test(
env: env_test,
)
#### code linting #####
run_target(
'python-ruff',
command : 'tools/python-ruff.sh',
)
python_ruff_check = find_program(join_paths(meson.source_root(), 'test/python-ruff-check.sh'))
run_target(
'python-ruff-check',
command : python_ruff_check,
)
test(
'python-ruff-check',
python_ruff_check,
env: env_test,
)
subdir('doc')

View File

@@ -1,2 +1,23 @@
[tool.black]
target-version = ["py37"]
[tool.ruff]
target-version = "py37"
select = [
# pycodestyle
"E",
"W",
# pyflakes
"F",
# pyupgrade
# Use modern Python features for the best possible develop experience.
"UP",
# flake8-bugbear
# Find obvious bugs.
"B",
]
ignore = [
# Line too long.
# We have some places where it's just impossible to make it fit,
"E501",
]

10
test/python-ruff-check.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
if [ -z "$MESON_SOURCE_ROOT" ]; then
echo "Expected \$MESON_SOURCE_ROOT to be set. Are you sure you are running this through ninja?"
exit 100
fi
cd "$MESON_SOURCE_ROOT" || exit 101
ruff check $(git ls-files "*.py" "*.py.in")

10
tools/python-ruff.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
if [ -z "$MESON_SOURCE_ROOT" ]; then
echo "Expected \$MESON_SOURCE_ROOT to be set. Are you sure you are running this through ninja?"
exit 100
fi
cd "$MESON_SOURCE_ROOT" || exit 101
ruff check --fix $(git ls-files "*.py" "*.py.in")