diff --git a/make/project.conf b/make/project.conf index 71fa0347..13d178fa 100644 --- a/make/project.conf +++ b/make/project.conf @@ -21,7 +21,7 @@ devel = jw-pkg-run = VERSION-REVISION run = bash, python3 build = make, time, xdg-utils, coreutils, cpio, xdg-utils, git-core devel = sudo, gawk, pkg-config -release = python3-isort, python3-yapf, python3-ruff, python3-pyright +release = mypy, python3-isort, python3-yapf, python3-pyright [pkg.requires.centos] run = hostname, python @@ -36,11 +36,11 @@ build = realpath [pkg.requires.suse] run = python3 -release = rpmbuild, python3-base +release = rpmbuild, python3-base, python3-yapf [pkg.requires.debian] run = python3 -release = devscripts, debhelper, dput, libparse-debcontrol-perl, fakeroot, build-essential:native +release = devscripts, debhelper, dput, libparse-debcontrol-perl, fakeroot, build-essential:native, yapf3 [pkg.requires.yocto] run = python3-core diff --git a/make/py-topdir.mk b/make/py-topdir.mk index 951762f1..377bad28 100644 --- a/make/py-topdir.mk +++ b/make/py-topdir.mk @@ -4,6 +4,14 @@ TD_GENERATE_FILES += pyrightconfig.json PY_CHECK_EXCLUDE ?= PY_SRC_ROOT += $(wildcard $(TOPDIR)/src $(TOPDIR)/tools) +ifndef PY_CHECK_RUFF + PY_CHECK_RUFF := $(shell which ruff 2>/dev/null) +endif + +ifndef PY_CHECK_YAPF + PY_CHECK_YAPF := $(firstword $(wildcard /usr/bin/yapf /usr/bin/yapf3)) +endif + all: format: py-format @@ -12,17 +20,23 @@ check-format: py-check-format py-check: py-check-syntax py-check-format py-check-syntax: - ruff check $(addprefix --exclude ,$(PY_CHECK_EXCLUDE)) $(PY_SRC_ROOT) +ifneq ($(PY_CHECK_RUFF),) + $(PY_CHECK_RUFF) check $(addprefix --exclude ,$(PY_CHECK_EXCLUDE)) $(PY_SRC_ROOT) +endif mypy $(addprefix --exclude ,$(PY_CHECK_EXCLUDE)) $(PY_SRC_ROOT) pyright py-check-format: - yapf --diff --recursive . +ifneq ($(PY_CHECK_YAPF),) + $(PY_CHECK_YAPF) --diff --recursive . +endif py-format: find . -type f -name '*.py' -print0 | \ xargs -0 sed -i -E '1{/^# -\*- coding: utf-8 -\*-$$/{:a;N;/\n[[:space:]]*$$/ba;s/^# -\*- coding: utf-8 -\*-\n([[:space:]]*\n)*/ /;s/^ //}}' - yapf --in-place --recursive . +ifneq ($(PY_CHECK_YAPF),) + $(PY_CHECK_YAPF) --in-place --recursive . +endif py-format-assignments: find . \