|
1 | 1 |
|
2 | | -PYTHON=python |
3 | | -VERSION=`cut -d "'" -f 2 alertaclient/version.py` |
| 2 | +VENV=venv |
| 3 | +PYTHON=$(VENV)/bin/python |
| 4 | +PIP=$(VENV)/bin/pip --disable-pip-version-check |
| 5 | +PYLINT=$(VENV)/bin/pylint |
| 6 | +MYPY=$(VENV)/bin/mypy |
| 7 | +BLACK=$(VENV)/bin/black |
| 8 | +TOX=$(VENV)/bin/tox |
| 9 | +PYTEST=$(VENV)/bin/pytest |
| 10 | +PRE_COMMIT=$(VENV)/bin/pre-commit |
| 11 | +TWINE=$(VENV)/bin/twine |
| 12 | +GIT=git |
| 13 | + |
4 | 14 | .DEFAULT_GOAL:=help |
5 | 15 |
|
| 16 | +-include .env .env.local .env.*.local |
| 17 | + |
| 18 | +ifndef PROJECT |
| 19 | +$(error PROJECT is not set) |
| 20 | +endif |
| 21 | + |
| 22 | +VERSION=$(shell cut -d "'" -f 2 $(PROJECT)/version.py) |
| 23 | + |
| 24 | +PKG_SDIST=dist/*-$(VERSION).tar.gz |
| 25 | +PKG_WHEEL=dist/*-$(VERSION)-*.whl |
| 26 | + |
6 | 27 | all: help |
7 | 28 |
|
8 | | -## init - Initialise environment. |
9 | | -init: |
10 | | - pip install -r requirements.txt --upgrade |
11 | | - pip install -e . |
| 29 | +$(PIP): |
| 30 | + python3 -m venv $(VENV) |
12 | 31 |
|
13 | | -## dev - Initialise dev environment. |
14 | | -dev: |
15 | | - pip install -r requirements-dev.txt --upgrade |
16 | | - pre-commit install |
17 | | - pre-commit autoupdate |
| 32 | +$(PYLINT): $(PIP) |
| 33 | + $(PIP) install pylint |
18 | 34 |
|
19 | | -## hooks - Run pre-commit hooks. |
20 | | -hooks: |
21 | | - pre-commit run --all-files |
| 35 | +$(MYPY): $(PIP) |
| 36 | + $(PIP) install mypy |
22 | 37 |
|
23 | | -## lint - Lint and type checking. |
24 | | -lint: |
25 | | - @pip -q install pylint |
26 | | - pylint --rcfile pylintrc alertaclient |
27 | | - @pip -q install mypy==0.620 |
28 | | - mypy alertaclient/ |
| 38 | +$(BLACK): $(PIP) |
| 39 | + $(PIP) install black |
29 | 40 |
|
30 | | -## clean - Clean source. |
31 | | -clean: |
32 | | - find . -name "*.pyc" -exec rm {} \; |
33 | | - rm -Rf build dist *.egg-info |
| 41 | +$(TOX): $(PIP) |
| 42 | + $(PIP) install tox |
| 43 | + |
| 44 | +$(PYTEST): $(PIP) |
| 45 | + $(PIP) install pytest |
| 46 | + |
| 47 | +$(PRE_COMMIT): $(PIP) |
| 48 | + $(PIP) install pre-commit |
| 49 | + |
| 50 | +$(TWINE): $(PIP) |
| 51 | + $(PIP) install wheel twine |
34 | 52 |
|
35 | | -## test.unit - Run unit tests. |
36 | | -test.unit: |
37 | | - pip install coveralls |
38 | | - pytest --cov=alertaclient tests/unit |
| 53 | +ifdef TOXENV |
| 54 | +toxparams?=-e $(TOXENV) |
| 55 | +endif |
39 | 56 |
|
40 | | -## test.integration - Run integration tests. |
41 | | -test.integration: |
42 | | - docker-compose -f docker-compose.ci.yaml build sut |
43 | | - docker-compose -f docker-compose.ci.yaml up --exit-code-from sut |
44 | | - docker-compose -f docker-compose.ci.yaml rm --stop --force |
| 57 | +## format - Code formatter. |
| 58 | +format: $(BLACK) |
| 59 | + $(BLACK) -l120 -S -v $(PROJECT) |
| 60 | + |
| 61 | +## lint - Lint and type checking. |
| 62 | +lint: $(PYLINT) $(MYPY) $(BLACK) |
| 63 | + $(PYLINT) --rcfile pylintrc $(PROJECT) |
| 64 | + $(MYPY) $(PROJECT)/ |
| 65 | + $(BLACK) -l120 -S --check -v $(PROJECT) || true |
| 66 | + |
| 67 | +## hooks - Run pre-commit hooks. |
| 68 | +hooks: $(PRE_COMMIT) |
| 69 | + $(PRE_COMMIT) run -a |
| 70 | + |
| 71 | +## test - Run unit tests. |
| 72 | +test: $(TOX) $(PYTEST) |
| 73 | + $(TOX) $(toxparams) |
45 | 74 |
|
46 | 75 | ## run - Run application. |
47 | 76 | run: |
48 | | - alerta top |
| 77 | + alertad |
49 | 78 |
|
50 | 79 | ## tag - Git tag with current version. |
51 | 80 | tag: |
52 | | - git tag -a v$(VERSION) -m v$(VERSION) |
53 | | - git push --tags |
| 81 | + $(GIT) tag -a v$(VERSION) -m "version $(VERSION)" |
| 82 | + $(GIT) push --tags |
| 83 | + |
| 84 | +## build - Build package. |
| 85 | +build: $(PKG_SDIST) $(PKG_WHEEL) |
| 86 | +$(PKG_SDIST): |
| 87 | + $(PYTHON) setup.py sdist |
| 88 | +$(PKG_WHEEL): |
| 89 | + $(PYTHON) setup.py bdist_wheel |
54 | 90 |
|
55 | 91 | ## upload - Upload package to PyPI. |
56 | | -upload: |
57 | | - $(PYTHON) setup.py sdist bdist_wheel |
58 | | - twine upload dist/* |
| 92 | +upload: $(TWINE) |
| 93 | + $(TWINE) upload dist/* |
| 94 | + |
| 95 | +## clean - Clean source. |
| 96 | +clean: |
| 97 | + find . -name "*.pyc" -exec rm {} \; |
| 98 | + rm -Rf build dist *.egg-info |
59 | 99 |
|
60 | 100 | ## help - Show this help. |
61 | 101 | help: Makefile |
| 102 | + @echo '' |
| 103 | + @echo 'Usage:' |
| 104 | + @echo ' make [TARGET]' |
| 105 | + @echo '' |
| 106 | + @echo 'Targets:' |
62 | 107 | @sed -n 's/^##//p' $< |
| 108 | + @echo '' |
| 109 | + |
| 110 | + @echo 'Add project-specific env variables to .env file:' |
| 111 | + @echo 'PROJECT=$(PROJECT)' |
| 112 | + |
| 113 | +.PHONY: help lint test build sdist wheel clean all |
0 commit comments