blob: 381a5448bf238b15b9001ae95fbd0efb03bb1937 [file] [log] [blame]
Zack Williams7af92fe2021-08-15 15:37:50 -07001# SPDX-FileCopyrightText: © 2021 Open Networking Foundation <support@opennetworking.org>
2# SPDX-License-Identifier: Apache-2.0
3
4# Use bash for pushd/popd, and to fail quickly.
5# No -u as virtualenv activate script has undefined vars
6SHELL = bash -e -o pipefail
7
8.DEFAULT_GOAL := help
9.PHONY: test lint pylint black blacken license help
10
11PYTHON_FILES ?= $(wildcard *.py)
Zack Williams84cb77a2022-01-14 14:46:39 -080012SHELL_FILES ?= $(wildcard *.sh)
13CPI_KEY ?= $(wildcard *.p12)
14
Zack Williams7af92fe2021-08-15 15:37:50 -070015
16# tooling
17VIRTUALENV ?= python3 -m venv
18
19# Create the virtualenv with all the tools installed
20VENV_NAME = venv_cbrs
21
22$(VENV_NAME): requirements.txt
23 $(VIRTUALENV) $@ ;\
24 source ./$@/bin/activate ; set -u ;\
25 python -m pip install --upgrade pip;\
26 python -m pip install -r requirements.txt
27 echo "To enter virtualenv, run 'source $@/bin/activate'"
28
Zack Williams84cb77a2022-01-14 14:46:39 -080029test: shellcheck black pylint license ## run tests
Zack Williams7af92fe2021-08-15 15:37:50 -070030
31pylint: $(VENV_NAME) ## pylint check for best practices
32 source ./$</bin/activate ; set -u ;\
33 pylint --version ;\
34 pylint $(PYTHON_FILES)
35
Zack Williams84cb77a2022-01-14 14:46:39 -080036shellcheck: ## shellcheck shell scripts
37 # SC1091 is excluded which is soucing the venv
38 shellcheck -V
39 shellcheck -e SC1091 $(SHELL_FILES)
40
Zack Williams7af92fe2021-08-15 15:37:50 -070041black: $(VENV_NAME) ## run black on python files in check mode
42 source ./$</bin/activate ; set -u ;\
43 black --version ;\
44 black --check $(PYTHON_FILES)
45
46blacken: $(VENV_NAME) ## run black on python files to reformat
47 source ./$</bin/activate ; set -u ;\
48 black --version ;\
49 black $(PYTHON_FILES)
50
51license: $(VENV_NAME) ## Check license with the reuse tool
52 source ./$</bin/activate ; set -u ;\
53 reuse --version ;\
54 reuse --root . lint
55
56clean:
57 rm -rf $(VENV_NAME)
58
59help: ## Print help for each target
60 @echo cbrstools make targets
61 @echo
62 @grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \
63 | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'