blob: c3ed3fc6b84e0e15c0fbd5d82f45d2929d6c90c4 [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-pylint lint-pylint-all lint-pylint-modified
24
25PYTHON_FILES ?= $(error PYTHON_FILES= required)
26
27## -----------------------------------------------------------------------
28## Intent: Use the pylint command to perform syntax checking.
29## o If UNSTABLE=1 syntax check all sources
30## o else only check sources modified by the developer.
31## Usage:
32## % make lint UNSTABLE=1
33## % make lint-pylint-all
34## -----------------------------------------------------------------------
35ifndef NO-LINT-PYLINT
36 lint-pylint-mode := $(if $(have-python-files),modified,all)
37 lint : lint-pylint
38 lint-pylint : lint-pylint-$(lint-pylint-mode)
39endif# NO-LINT-PYLINT
40
41## -----------------------------------------------------------------------
42## Intent: exhaustive pylint syntax checking
43## -----------------------------------------------------------------------
44lint-pylint-all: $(venv-activate-script)
45 $(call banner-enter,Target $@)
46 $(MAKE) --no-print-directory lint-pylint-install
47
48 $(activate) && $(call gen-python-find-cmd) | $(xargs-n1) pylint
49 $(call banner-leave,Target $@)
50
51## -----------------------------------------------------------------------
52## Intent: check deps for format and python3 cleanliness
53## Note:
54## pylint --py3k option no longer supported
55## -----------------------------------------------------------------------
56lint-pylint-modified: $(venv-activate-script)
57 $(call banner-enter,Target $@)
58 $(MAKE) --no-print-directory lint-pylint-install
59
60 $(activate) && pylint $(PYTHON_FILES)
61 $(call banner-leave,Target $@)
62
63## -----------------------------------------------------------------------
64## Intent: Install the pylint tool for checking
65## Todo:
66## o Update to use file dependencies VS generic target always called
67## -----------------------------------------------------------------------
68.PHONY: lint-pylint-install
69lint-pylint-install: $(venv-activate-script)
70
71 $(call banner-enter,Target $@)
72 $(activate) && pip install --upgrade pylint
73 $(activate) && pylint --version
74 $(call banner-leave,Target $@)
75 @echo
76
77## -----------------------------------------------------------------------
78## Intent: Display command usage
79## -----------------------------------------------------------------------
80help::
81 @echo ' lint-pylint Syntax check python using the pylint command'
82 ifdef VERBOSE
83 @echo ' $(MAKE) lint-pylint PYTHON_FILES=...'
84 @echo ' lint-pylint-modified pylint checking: only modified'
85 @echo ' lint-pylint-all pylint checking: exhaustive'
86 @echo ' lint-pylint-install Install the pylint command'
87 endif
88
89$(if $(DEBUG),$(warning LEAVE))
90
91# [EOF]