Zack Williams | 7af92fe | 2021-08-15 15:37:50 -0700 | [diff] [blame] | 1 | # 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 |
| 6 | SHELL = bash -e -o pipefail |
| 7 | |
| 8 | .DEFAULT_GOAL := help |
| 9 | .PHONY: test lint pylint black blacken license help |
| 10 | |
| 11 | PYTHON_FILES ?= $(wildcard *.py) |
| 12 | |
| 13 | # tooling |
| 14 | VIRTUALENV ?= python3 -m venv |
| 15 | |
| 16 | # Create the virtualenv with all the tools installed |
| 17 | VENV_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 | |
| 26 | test: black pylint license ## run tests |
| 27 | |
| 28 | pylint: $(VENV_NAME) ## pylint check for best practices |
| 29 | source ./$</bin/activate ; set -u ;\ |
| 30 | pylint --version ;\ |
| 31 | pylint $(PYTHON_FILES) |
| 32 | |
| 33 | black: $(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 | |
| 38 | blacken: $(VENV_NAME) ## run black on python files to reformat |
| 39 | source ./$</bin/activate ; set -u ;\ |
| 40 | black --version ;\ |
| 41 | black $(PYTHON_FILES) |
| 42 | |
| 43 | license: $(VENV_NAME) ## Check license with the reuse tool |
| 44 | source ./$</bin/activate ; set -u ;\ |
| 45 | reuse --version ;\ |
| 46 | reuse --root . lint |
| 47 | |
| 48 | clean: |
| 49 | rm -rf $(VENV_NAME) |
| 50 | |
| 51 | help: ## 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};' |