|
| 1 | +PHONY: clean clean-test clean-pyc clean-build clean-env docs help setup test test-all coverage list-outdated install-latest setup |
| 2 | +.DEFAULT_GOAL := help |
| 3 | +.SILENT: clean clean-build clean-pyc clean-test setup |
| 4 | + |
| 5 | +define BROWSER_PYSCRIPT |
| 6 | +import os, webbrowser, sys |
| 7 | + |
| 8 | +from urllib.request import pathname2url |
| 9 | + |
| 10 | +webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) |
| 11 | +endef |
| 12 | +export BROWSER_PYSCRIPT |
| 13 | + |
| 14 | +define PRINT_HELP_PYSCRIPT |
| 15 | +import re, sys |
| 16 | + |
| 17 | +for line in sys.stdin: |
| 18 | + match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) |
| 19 | + if match: |
| 20 | + target, help = match.groups() |
| 21 | + print("%-20s %s" % (target, help)) |
| 22 | +endef |
| 23 | +export PRINT_HELP_PYSCRIPT |
| 24 | + |
| 25 | +BROWSER := python -c "$$BROWSER_PYSCRIPT" |
| 26 | + |
| 27 | +help: |
| 28 | + @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) |
| 29 | + |
| 30 | +clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts |
| 31 | + |
| 32 | +clean-build: ## remove build artifacts |
| 33 | + rm -fr build/ |
| 34 | + rm -fr out/ |
| 35 | + rm -fr gen/ |
| 36 | + rm -fr dist/ |
| 37 | + rm -fr .eggs/ |
| 38 | + rm -fr .hypothesis/ |
| 39 | + rm -fr .mypy_cache/ |
| 40 | + find . -name '*.egg-info' -exec rm -fr {} + |
| 41 | + find . -name '*.egg' -exec rm -fr {} + |
| 42 | + |
| 43 | +clean-pyc: ## remove Python file artifacts |
| 44 | + find . -name '*.pyc' -exec rm -f {} + |
| 45 | + find . -name '*.pyo' -exec rm -f {} + |
| 46 | + find . -name '*~' -exec rm -f {} + |
| 47 | + find . -name '__pycache__' -exec rm -fr {} + |
| 48 | + |
| 49 | +clean-test: ## remove test and coverage artifacts |
| 50 | + rm -fr .tox/ |
| 51 | + rm -f .coverage |
| 52 | + rm -fr htmlcov/ |
| 53 | + rm -fr .pytest_cache |
| 54 | + |
| 55 | +clean-env: ## remove environment |
| 56 | + rm -fr venv-pypy |
| 57 | + |
| 58 | +lint: ## static code analysis |
| 59 | + black --line-length 120 --check resoto_datalink tests |
| 60 | + flake8 resoto_datalink |
| 61 | + mypy --python-version 3.9 --strict --install-types --non-interactive resoto_datalink tests |
| 62 | + |
| 63 | +test: ## run tests quickly with the default Python |
| 64 | + pytest |
| 65 | + |
| 66 | +test-all: ## run tests on every Python version with tox |
| 67 | + tox |
| 68 | + |
| 69 | +coverage: ## check code coverage quickly with the default Python |
| 70 | + coverage run --source resotolib -m pytest |
| 71 | + coverage combine |
| 72 | + coverage report -m |
| 73 | + coverage html |
| 74 | + $(BROWSER) htmlcov/index.html |
| 75 | + |
| 76 | +setup: |
| 77 | + python3 -m venv venv --prompt "resoto-datalink venv" |
| 78 | + ./venv/bin/python3 -m pip install --upgrade pip tox |
| 79 | + ./venv/bin/pip3 install -r requirements-all.txt |
| 80 | + ./venv/bin/pip3 install ".[dev,test]" |
| 81 | + echo "\n\n\nUse the following command to activate the venv" |
| 82 | + echo "source venv/bin/activate" |
| 83 | + |
| 84 | +requirements: |
| 85 | + pip-compile -q --no-annotate --resolver=backtracking --upgrade --allow-unsafe --no-header -o requirements.txt |
| 86 | + pip-compile -q --all-extras --no-annotate --resolver=backtracking --upgrade --allow-unsafe --no-header -o requirements-all.txt |
| 87 | + |
| 88 | +list-outdated: |
| 89 | + pip list --outdated |
| 90 | + |
| 91 | +install-latest: |
| 92 | + pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U |
0 commit comments