blob: d8c503dcb0fff8e2d5bdbcab25f547bb05b3b82c [file] [log] [blame]
Joey Armstrong7f8436c2023-07-09 20:23:27 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrong9cdee9f2024-01-03 04:56:14 -05003# Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrong7f8436c2023-07-09 20:23:27 -04004#
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## -----------------------------------------------------------------------
42lint-flake8-all: $(venv-activate-script)
43 $(call banner-enter,Target $@)
44 $(HIDE)$(MAKE) --no-print-directory lint-flake8-install
45
46 $(activate) && $(call gen-python-find-cmd) \
47 | $(xargs-n1) flake8 --max-line-length=99 --count
48 $(call banner-leave,Target $@)
49
50## -----------------------------------------------------------------------
51## Intent: check deps for format and python3 cleanliness
52## Note:
53## pylint --py3k option no longer supported
54## -----------------------------------------------------------------------
55lint-flake8-modified: $(venv-activate-script)
56 $(call banner-enter,Target $@)
57 $(HIDE)$(MAKE) --no-print-directory lint-flake8-install
58
59 $(activate) && flake8 --max-line-length=99 --count $(PYTHON_FILES)
60 $(call banner-leave,Target $@)
61
62## -----------------------------------------------------------------------
63## Intent: Install the flake8 tool for checking
64## Todo:
65## o Update to use file dependencies VS generic target always called
66## -----------------------------------------------------------------------
67.PHONY: lint-flake8-install
68lint-flake8-install: $(venv-activate-script)
69 $(call banner-enter,Target $@)
70 $(activate) && pip install --upgrade flake8
71 $(activate) && flake8 --version
72 $(call banner-leave,Target $@)
73 @echo
74
75## -----------------------------------------------------------------------
76## Intent: Display command usage
77## -----------------------------------------------------------------------
78help::
79 @echo ' lint-flake8 Syntax check python using the flake8 command'
80 ifdef VERBOSE
81 @echo ' $(MAKE) lint-pylint PYTHON_FILES=...'
82 @echo ' lint-flake8-modified flake8 checking: only modified'
83 @echo ' lint-flake8-all flake8 checking: exhaustive'
84 @echo ' lint-flake8-install Install the flake8 command'
85 endif
86
87$(if $(DEBUG),$(warning LEAVE))
88
89# [EOF]