mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
build: add Python code formatting with black
NOTE: this will fail tests as of this commit, as the code is not formatted yet. We didn't explicitly specify a minimum Python version before that, so I used v3.7 here, because it's the minimal version Ruff - a Python linter I will add in the next commit - supports.
This commit is contained in:
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@@ -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
|
||||
PIP_PACKAGES: meson ninja libevdev pyudev pytest sphinx_rtd_theme black
|
||||
|
||||
jobs:
|
||||
build-and-dist:
|
||||
|
||||
19
meson.build
19
meson.build
@@ -556,6 +556,8 @@ configure_file(input : 'tools/ratbagctl.test.py.in',
|
||||
|
||||
env_test = environment()
|
||||
env_test.set('LIBRATBAG_DATA_DIR', libratbag_data_dir_devel)
|
||||
# See: https://github.com/mesonbuild/meson/issues/3306.
|
||||
env_test.set('MESON_SOURCE_ROOT', meson.source_root())
|
||||
ratbagctl_test = find_program(join_paths(meson.build_root(), 'ratbagctl.test'))
|
||||
test('ratbagctl-test', ratbagctl_test, args: ['-v'], env : env_test)
|
||||
|
||||
@@ -630,4 +632,21 @@ custom_target('ratbag-command',
|
||||
#### output files ####
|
||||
configure_file(output: 'config.h', install: false, configuration: config_h)
|
||||
|
||||
#### code formatting #####
|
||||
run_target(
|
||||
'python-black',
|
||||
command : 'tools/python-black.sh',
|
||||
)
|
||||
|
||||
python_black_check = find_program(join_paths(meson.source_root(), 'test/python-black-check.sh'))
|
||||
run_target(
|
||||
'python-black-check',
|
||||
command : python_black_check,
|
||||
)
|
||||
test(
|
||||
'python-black-check',
|
||||
python_black_check,
|
||||
env: env_test,
|
||||
)
|
||||
|
||||
subdir('doc')
|
||||
|
||||
2
pyproject.toml
Normal file
2
pyproject.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
[tool.black]
|
||||
target-version = ["py37"]
|
||||
10
test/python-black-check.sh
Executable file
10
test/python-black-check.sh
Executable 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
|
||||
|
||||
black --check $(git ls-files "*.py" "*.py.in")
|
||||
10
tools/python-black.sh
Executable file
10
tools/python-black.sh
Executable 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
|
||||
|
||||
black $(git ls-files "*.py" "*.py.in")
|
||||
@@ -26,7 +26,10 @@ import sys
|
||||
import argparse
|
||||
import re
|
||||
|
||||
# This must be on a single line, as we replace it using merge_ratbagd.py while building.
|
||||
# fmt: off
|
||||
from ratbagd import Ratbagd, RatbagdDevice, RatbagdProfile, RatbagdMacro, RatbagdResolution, RatbagdButton, RatbagdLed, RatbagdUnavailable, RatbagError, RatbagErrorCode, RatbagErrorCapability, RatbagDeviceType # NOQA
|
||||
# fmt: on
|
||||
|
||||
|
||||
RATBAGD_API_VERSION = int("@RATBAGD_API_VERSION@")
|
||||
|
||||
Reference in New Issue
Block a user