blob: bb474a914567a699037533a45cc4a71ee5d5cf50 [file] [log] [blame]
Joey Armstrong4de98b72023-02-09 14:51:38 -05001# -*- 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-$(lint-flake8-mode)
36endif# NO-LINT-FLAKE8
37
38## -----------------------------------------------------------------------
39## Intent: exhaustive flake8 syntax checking
40## -----------------------------------------------------------------------
41lint-flake8-all: $(venv-activate-script)
42 $(HIDE)$(MAKE) --no-print-directory lint-flake8-install
43
44 $(activate)\
45 && find . \( -name '$(venv-name)' \) -prune -o -name '*.py' -print0 \
46 | $(xargs-n1) flake8 --max-line-length=99 --count
47
48## -----------------------------------------------------------------------
49## Intent: check deps for format and python3 cleanliness
50## Note:
51## pylint --py3k option no longer supported
52## -----------------------------------------------------------------------
53lint-flake8-modified: $(venv-activate-script)
54 $(HIDE)$(MAKE) --no-print-directory lint-flake8-install
55
56 $(activate)\
57 && flake8 --max-line-length=99 --count $(PYTHON_FILES)
58
59## -----------------------------------------------------------------------
60## Intent:
61## -----------------------------------------------------------------------
62.PHONY: lint-flake8-install
63lint-flake8-install: $(venv-activate-script)
64 @echo
65 @echo "** -----------------------------------------------------------------------"
66 @echo "** python flake8 syntax checking"
67 @echo "** -----------------------------------------------------------------------"
68 $(activate) && pip install --upgrade flake8
69 $(activate) && flake8 --version
70 @echo
71
72## -----------------------------------------------------------------------
73## Intent: Display command usage
74## -----------------------------------------------------------------------
75help::
76 @echo ' lint-flake8 Syntax check python using the flake8 command'
77 ifdef VERBOSE
78 @echo ' $(MAKE) lint-pylint PYTHON_FILES=...'
79 @echo ' lint-flake8-modified flake8 checking: only modified'
80 @echo ' lint-flake8-all flake8 checking: exhaustive'
81 endif
82
83$(if $(DEBUG),$(warning LEAVE))
84
85# [EOF]