@@ -20,11 +20,29 @@ PYCODESTYLE_FLAGS ?= \
2020
2121# TARGETS #
2222
23+ # Check for pycodestyle.
24+ #
25+ # This target checks if pycodestyle is installed.
26+
27+ check-pycodestyle :
28+ ifeq (, $(shell command -v $(PYCODESTYLE ) 2>/dev/null) )
29+ $(QUIET) echo ''
30+ $(QUIET) echo 'pycodestyle is not installed. Please install pycodestyle and try again.'
31+ $(QUIET) echo 'For install instructions, see https://github.com/PyCQA/pycodestyle.'
32+ $(QUIET) echo ''
33+ $(QUIET) exit 1
34+ else
35+ $(QUIET) echo 'pycodestyle is installed.'
36+ $(QUIET) exit 0
37+ endif
38+
39+ .PHONY : check-pycodestyle
40+
2341# Check source code style.
2442#
2543# This target lints only Python source files.
2644
27- pycodestyle-src :
45+ pycodestyle-src : check-pycodestyle
2846 $(QUIET ) $(FIND_PYTHON_SOURCES_CMD ) | grep ' ^\/' | while read -r file; do \
2947 echo ' ' ; \
3048 echo " Linting file: $$ file" ; \
@@ -38,7 +56,7 @@ pycodestyle-src:
3856#
3957# This target lints only Python test fixture files.
4058
41- pycodestyle-tests-fixtures :
59+ pycodestyle-tests-fixtures : check-pycodestyle
4260 $(QUIET ) $(FIND_PYTHON_TESTS_FIXTURES_CMD ) | grep ' ^\/' | while read -r file; do \
4361 echo ' ' ; \
4462 echo " Linting file: $$ file" ; \
@@ -52,7 +70,7 @@ pycodestyle-tests-fixtures:
5270#
5371# This target lints only Python example files.
5472
55- pycodestyle-examples :
73+ pycodestyle-examples : check-pycodestyle
5674 $(QUIET ) $(FIND_PYTHON_EXAMPLES_CMD ) | grep ' ^\/' | while read -r file; do \
5775 echo ' ' ; \
5876 echo " Linting file: $$ file" ; \
@@ -66,7 +84,7 @@ pycodestyle-examples:
6684#
6785# This target lints only Python benchmark files.
6886
69- pycodestyle-benchmarks :
87+ pycodestyle-benchmarks : check-pycodestyle
7088 $(QUIET ) $(FIND_PYTHON_BENCHMARKS_CMD ) | grep ' ^\/' | while read -r file; do \
7189 echo ' ' ; \
7290 echo " Linting file: $$ file" ; \
@@ -78,10 +96,10 @@ pycodestyle-benchmarks:
7896
7997# Check Python code style.
8098#
81- # This target lints Python files. Note that we expect `$FILES ` to be a Python file list.
99+ # This target lints Python files. Note that we expect `$PYTHON_FILES ` to be a Python file list.
82100
83- pycodestyle-files :
84- $(QUIET ) for file in $( FILES ) ; do \
101+ pycodestyle-files : check-pycodestyle
102+ $(QUIET ) for file in $( PYTHON_FILES ) ; do \
85103 echo ' ' ; \
86104 echo " Linting file: $$ file" ; \
87105 $(PYCODESTYLE ) $(PYCODESTYLE_FLAGS ) $$ file || exit 1; \
0 commit comments