blob: 3241d3dc158e405fd1e5b7a1e4e78c54673c8048 [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)
12
13# tooling
14VIRTUALENV ?= python3 -m venv
15
16# Create the virtualenv with all the tools installed
17VENV_NAME = venv_cbrs
18
19$(VENV_NAME): requirements.txt
20 $(VIRTUALENV) $@ ;\
21 source ./$@/bin/activate ; set -u ;\
22 python -m pip install --upgrade pip;\
23 python -m pip install -r requirements.txt
24 echo "To enter virtualenv, run 'source $@/bin/activate'"
25
26test: black pylint license ## run tests
27
28pylint: $(VENV_NAME) ## pylint check for best practices
29 source ./$</bin/activate ; set -u ;\
30 pylint --version ;\
31 pylint $(PYTHON_FILES)
32
33black: $(VENV_NAME) ## run black on python files in check mode
34 source ./$</bin/activate ; set -u ;\
35 black --version ;\
36 black --check $(PYTHON_FILES)
37
38blacken: $(VENV_NAME) ## run black on python files to reformat
39 source ./$</bin/activate ; set -u ;\
40 black --version ;\
41 black $(PYTHON_FILES)
42
43license: $(VENV_NAME) ## Check license with the reuse tool
44 source ./$</bin/activate ; set -u ;\
45 reuse --version ;\
46 reuse --root . lint
47
48clean:
49 rm -rf $(VENV_NAME)
50
51help: ## Print help for each target
52 @echo cbrstools make targets
53 @echo
54 @grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \
55 | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'