blob: cf1bc2b38e5e034090dd2729dbeccb1f20a8d777 [file] [log] [blame]
Joey Armstrongdd334492023-07-09 17:59:02 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
4#
5# Licensed under the Apache License, Version 2.0 (the "License")
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16# -----------------------------------------------------------------------
17
18$(if $(DEBUG),$(warning ENTER))
19
20##-------------------##
21##---] GLOBALS [---##
22##-------------------##
23.PHONY: lint-flake8 lint-flake8-all lint-flake8-modified
24
25PYTHON_FILES ?= $(error PYTHON_FILES= required)
26
27## -----------------------------------------------------------------------
28## Intent: Use the flake8 command to perform syntax checking.
29## Usage:
30## % make lint
31## % make lint-flake8-all
32## -----------------------------------------------------------------------
33ifndef NO-LINT-FLAKE8
34 lint-flake8-mode := $(if $(have-python-files),modified,all)
35 lint : lint-flake8
36 lint-flake8 : lint-flake8-$(lint-flake8-mode)
37endif# NO-LINT-FLAKE8
38
39## -----------------------------------------------------------------------
40## Intent: exhaustive flake8 syntax checking
41## -----------------------------------------------------------------------
42# Construct: find . \( -name '__ignored__' -o -name dir -o name dir \)
43# flake8-find-filter := $(null)
44# flake8-find-filter += -name '__ignored__'# # for alignment
45# flake8-find-filter += $(foreach dir,$(onf-excl-dirs),-o -name $(dir)))
46
47lint-flake8-all: $(venv-activate-script)
48 $(HIDE)$(MAKE) --no-print-directory lint-flake8-install
49
50 $(activate) && $(call gen-python-find-cmd) \
51 | $(xargs-n1) flake8 --max-line-length=99 --count
52
53# && find . \( $(flake8-find-filter) \) -prune -o -name '*.py' -print0 \
54# | $(xargs-n1) flake8 --max-line-length=99 --count
55
56## -----------------------------------------------------------------------
57## Intent: check deps for format and python3 cleanliness
58## Note:
59## pylint --py3k option no longer supported
60## -----------------------------------------------------------------------
61lint-flake8-modified: $(venv-activate-script)
62 $(HIDE)$(MAKE) --no-print-directory lint-flake8-install
63
64 $(activate)\
65 && flake8 --max-line-length=99 --count $(PYTHON_FILES)
66
67## -----------------------------------------------------------------------
68## Intent:
69## -----------------------------------------------------------------------
70.PHONY: lint-flake8-install
71lint-flake8-install: $(venv-activate-script)
72 @echo
73 @echo "** -----------------------------------------------------------------------"
74 @echo "** python flake8 syntax checking"
75 @echo "** -----------------------------------------------------------------------"
76 $(activate) && pip install --upgrade flake8
77 $(activate) && flake8 --version
78 @echo
79
80## -----------------------------------------------------------------------
81## Intent: Display command usage
82## -----------------------------------------------------------------------
83help::
84 @echo ' lint-flake8 Syntax check python using the flake8 command'
85 ifdef VERBOSE
86 @echo ' $(MAKE) lint-pylint PYTHON_FILES=...'
87 @echo ' lint-flake8-modified flake8 checking: only modified'
88 @echo ' lint-flake8-all flake8 checking: exhaustive'
89 @echo ' lint-flake8-install Install the flake8 command'
90 endif
91
92$(if $(DEBUG),$(warning LEAVE))
93
94# [EOF]