Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame^] | 1 | # ONF enodebd Makefile |
| 2 | # |
| 3 | # SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org> |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | |
| 6 | # Use bash for pushd/popd, and to fail quickly. |
| 7 | # No -u as virtualenv activate script has undefined vars |
| 8 | SHELL = bash -e -o pipefail |
| 9 | |
| 10 | # tooling |
| 11 | VIRTUALENV ?= python3 -m venv |
| 12 | |
| 13 | # all files with extensions |
| 14 | PYTHON_FILES ?= $(wildcard devices/freedomfi_one.py devices/device_utils.py devices/device_map.py) |
| 15 | |
| 16 | .DEFAULT_GOAL := help |
| 17 | .PHONY: test lint license help |
| 18 | |
| 19 | # Create the virtualenv with all the tools installed |
| 20 | VENV_NAME = venv |
| 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 | |
| 29 | license: $(VENV_NAME) ## Check license with the reuse tool |
| 30 | source ./$</bin/activate ; set -u ;\ |
| 31 | reuse --version ;\ |
| 32 | reuse --root . lint |
| 33 | |
| 34 | test: flake8 pylint black ## run all standard tests |
| 35 | |
| 36 | flake8: $(VENV_NAME) ## check python formatting with flake8 |
| 37 | source ./$</bin/activate ; set -u ;\ |
| 38 | flake8 --version ;\ |
| 39 | flake8 --max-line-length 99 --per-file-ignores="__init__.py:F401" $(PYTHON_FILES) |
| 40 | |
| 41 | pylint: $(VENV_NAME) ## pylint check for python 3 compliance |
| 42 | source ./$</bin/activate ; set -u ;\ |
| 43 | pylint --version ;\ |
| 44 | pylint --rcfile=pylint.ini $(PYTHON_FILES) |
| 45 | |
| 46 | black: $(VENV_NAME) ## run black on python files in check mode |
| 47 | source ./$</bin/activate ; set -u ;\ |
| 48 | black --version ;\ |
| 49 | black --check $(PYTHON_FILES) |
| 50 | |
| 51 | blacken: $(VENV_NAME) ## run black on python files to reformat |
| 52 | source ./$</bin/activate ; set -u ;\ |
| 53 | black --version ;\ |
| 54 | black $(PYTHON_FILES) |
| 55 | |
| 56 | clean: |
| 57 | rm -rf $(VENV_NAME) ansible_collections |
| 58 | |
| 59 | help: ## Print help for each target |
| 60 | @echo enodebd make targets |
| 61 | @echo |
| 62 | @grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \ |
| 63 | | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};' |