Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf build: Add pylint build tests

If PYLINT=1 is passed to the build then run pylint over python code in
perf. Unlike shellcheck this isn't default on as there are currently
too many errors.

An example of an error:
```
************* Module setup
util/setup.py:19:0: C0301: Line too long (127/100) (line-too-long)
util/setup.py:20:0: C0301: Line too long (138/100) (line-too-long)
util/setup.py:63:0: C0301: Line too long (106/100) (line-too-long)
util/setup.py:1:0: C0114: Missing module docstring (missing-module-docstring)
util/setup.py:24:4: W0622: Redefining built-in 'vars' (redefined-builtin)
util/setup.py:11:4: C0103: Constant name "cc_options" doesn't conform to UPPER_CASE naming style (invalid-name)
util/setup.py:13:4: C0103: Constant name "cc_options" doesn't conform to UPPER_CASE naming style (invalid-name)
util/setup.py:15:34: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
util/setup.py:18:0: C0116: Missing function or method docstring (missing-function-docstring)
util/setup.py:19:16: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
util/setup.py:44:0: C0413: Import "from setuptools import setup, Extension" should be placed at the top of the module (wrong-import-position)
util/setup.py:46:0: C0413: Import "from setuptools.command.build_ext import build_ext as _build_ext" should be placed at the top of the module (wrong-import-position)
util/setup.py:47:0: C0413: Import "from setuptools.command.install_lib import install_lib as _install_lib" should be placed at the top of the module (wrong-import-position)
util/setup.py:49:0: C0115: Missing class docstring (missing-class-docstring)
util/setup.py:49:0: C0103: Class name "build_ext" doesn't conform to PascalCase naming style (invalid-name)
util/setup.py:52:8: W0201: Attribute 'build_lib' defined outside __init__ (attribute-defined-outside-init)
util/setup.py:53:8: W0201: Attribute 'build_temp' defined outside __init__ (attribute-defined-outside-init)
util/setup.py:55:0: C0115: Missing class docstring (missing-class-docstring)
util/setup.py:55:0: C0103: Class name "install_lib" doesn't conform to PascalCase naming style (invalid-name)
util/setup.py:58:8: W0201: Attribute 'build_dir' defined outside __init__ (attribute-defined-outside-init)

*-----------------------------------------------------------------
Your code has been rated at 6.67/10 (previous run: 6.51/10, +0.16)

make[4]: *** [util/Build:442: util/setup.py.pylint_log] Error 1
```

Reviewed-by: James Clark <james.clark@linaro.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250311213628.569562-5-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
8a54784e 168910d0

+69 -2
+13
tools/perf/Build
··· 89 89 $(Q)$(call echo-cmd,test)mypy "$<" > $@ || (cat $@ && rm $@ && false) 90 90 91 91 perf-y += $(MYPY_TEST_LOGS) 92 + 93 + ifdef PYLINT 94 + PY_TESTS := $(shell find python -type f -name '*.py') 95 + PYLINT_TEST_LOGS := $(PY_TESTS:python/%=python/%.pylint_log) 96 + else 97 + PYLINT_TEST_LOGS := 98 + endif 99 + 100 + $(OUTPUT)%.pylint_log: % 101 + $(call rule_mkdir) 102 + $(Q)$(call echo-cmd,test)pylint "$<" > $@ || (cat $@ && rm $@ && false) 103 + 104 + perf-y += $(PYLINT_TEST_LOGS)
+6 -1
tools/perf/Makefile.perf
··· 311 311 MYPY := $(shell which mypy 2> /dev/null) 312 312 endif 313 313 314 + # Runs pylint on perf python files 315 + ifeq ($(PYLINT),1) 316 + PYLINT := $(shell which pylint 2> /dev/null) 317 + endif 318 + 314 319 export srctree OUTPUT RM CC CXX LD AR CFLAGS CXXFLAGS V BISON FLEX AWK 315 - export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY 320 + export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT 316 321 317 322 include $(srctree)/tools/build/Makefile.include 318 323
+12 -1
tools/perf/pmu-events/Build
··· 52 52 $(call rule_mkdir) 53 53 $(Q)$(call echo-cmd,test)mypy "$<" > $@ || (cat $@ && rm $@ && false) 54 54 55 + ifdef PYLINT 56 + PMU_EVENTS_PY_TESTS := $(wildcard *.py) 57 + PMU_EVENTS_PYLINT_TEST_LOGS := $(JEVENTS_PY_TESTS:%=%.pylint_log) 58 + else 59 + PMU_EVENTS_PYLINT_TEST_LOGS := 60 + endif 61 + 62 + $(OUTPUT)%.pylint_log: % 63 + $(call rule_mkdir) 64 + $(Q)$(call echo-cmd,test)pylint "$<" > $@ || (cat $@ && rm $@ && false) 65 + 55 66 $(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_LOG) \ 56 - $(EMPTY_PMU_EVENTS_TEST_LOG) $(PMU_EVENTS_MYPY_TEST_LOGS) 67 + $(EMPTY_PMU_EVENTS_TEST_LOG) $(PMU_EVENTS_MYPY_TEST_LOGS) $(PMU_EVENTS_PYLINT_TEST_LOGS) 57 68 $(call rule_mkdir) 58 69 $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@ 59 70 endif
+13
tools/perf/scripts/Build
··· 15 15 $(Q)$(call echo-cmd,test)mypy "$<" > $@ || (cat $@ && rm $@ && false) 16 16 17 17 perf-y += $(MYPY_TEST_LOGS) 18 + 19 + ifdef PYLINT 20 + PY_TESTS := $(shell find python -type f -name '*.py') 21 + PYLINT_TEST_LOGS := $(PY_TESTS:python/%=python/%.pylint_log) 22 + else 23 + PYLINT_TEST_LOGS := 24 + endif 25 + 26 + $(OUTPUT)%.pylint_log: % 27 + $(call rule_mkdir) 28 + $(Q)$(call echo-cmd,test)pylint "$<" > $@ || (cat $@ && rm $@ && false) 29 + 30 + perf-y += $(PYLINT_TEST_LOGS)
+13
tools/perf/tests/Build
··· 104 104 $(Q)$(call echo-cmd,test)mypy "$<" > $@ || (cat $@ && rm $@ && false) 105 105 106 106 perf-test-y += $(MYPY_TEST_LOGS) 107 + 108 + ifdef PYLINT 109 + PY_TESTS := $(shell find tests/shell -type f -name '*.py') 110 + PYLINT_TEST_LOGS := $(PY_TESTS:tests/shell/%=shell/%.pylint_log) 111 + else 112 + PYLINT_TEST_LOGS := 113 + endif 114 + 115 + $(OUTPUT)%.pylint_log: % 116 + $(call rule_mkdir) 117 + $(Q)$(call echo-cmd,test)pylint "$<" > $@ || (cat $@ && rm $@ && false) 118 + 119 + perf-test-y += $(PYLINT_TEST_LOGS)
+12
tools/perf/util/Build
··· 430 430 $(Q)$(call echo-cmd,test)mypy "$<" > $@ || (cat $@ && rm $@ && false) 431 431 432 432 perf-util-y += $(MYPY_TEST_LOGS) 433 + 434 + ifdef PYLINT 435 + PYLINT_TEST_LOGS := $(PY_TESTS:%=%.pylint_log) 436 + else 437 + PYLINT_TEST_LOGS := 438 + endif 439 + 440 + $(OUTPUT)%.pylint_log: % 441 + $(call rule_mkdir) 442 + $(Q)$(call echo-cmd,test)pylint "$<" > $@ || (cat $@ && rm $@ && false) 443 + 444 + perf-util-y += $(PYLINT_TEST_LOGS)