blob: 6b2b5619ed3b2bf0f68401bd3b5034920daaee58 [file] [log] [blame]
Joey Armstrong04cdd9f2023-06-09 15:18:23 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrong9fadcbe2024-01-17 19:00:37 -05003# Copyright 2022-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrong04cdd9f2023-06-09 15:18:23 -04004#
Joey Armstronga5278142023-06-28 16:56:54 -04005# Licensed under the Apache License, Version 2.0 (the "License")
Joey Armstrong04cdd9f2023-06-09 15:18:23 -04006# 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
Joey Armstronga5278142023-06-28 16:56:54 -040018$(if $(DEBUG),$(warning ENTER))
19
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040020##-------------------##
21##---] GLOBALS [---##
22##-------------------##
Joey Armstronga5278142023-06-28 16:56:54 -040023.PHONY: lint-flake8 lint-flake8-all lint-flake8-modified
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040024
Joey Armstronga5278142023-06-28 16:56:54 -040025PYTHON_FILES ?= $(error PYTHON_FILES= required)
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040026
27## -----------------------------------------------------------------------
Joey Armstronga5278142023-06-28 16:56:54 -040028## Intent: Use the flake8 command to perform syntax checking.
29## Usage:
30## % make lint
31## % make lint-flake8-all
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040032## -----------------------------------------------------------------------
Joey Armstronga5278142023-06-28 16:56:54 -040033ifndef 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) \
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040051 | $(xargs-n1) flake8 --max-line-length=99 --count
52
Joey Armstronga5278142023-06-28 16:56:54 -040053# && find . \( $(flake8-find-filter) \) -prune -o -name '*.py' -print0 \
54# | $(xargs-n1) flake8 --max-line-length=99 --count
55
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040056## -----------------------------------------------------------------------
Joey Armstronga5278142023-06-28 16:56:54 -040057## Intent: check deps for format and python3 cleanliness
58## Note:
59## pylint --py3k option no longer supported
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040060## -----------------------------------------------------------------------
Joey Armstronga5278142023-06-28 16:56:54 -040061lint-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))
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040093
94# [EOF]