Skip to content

Commit 0091033

Browse files
authored
Update makefile and travis config (#212)
1 parent 299ddd3 commit 0091033

6 files changed

Lines changed: 143 additions & 52 deletions

File tree

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PROJECT=alertaclient
2+
COMPOSE_PROJECT_NAME=sdk

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
repos:
2+
- repo: https://github.com/pre-commit/mirrors-autopep8
3+
rev: v1.5.1
4+
hooks:
5+
- id: autopep8
26
- repo: https://github.com/pre-commit/pre-commit-hooks.git
37
rev: v2.5.0
48
hooks:
@@ -22,17 +26,13 @@ repos:
2226
args: ['--django']
2327
- id: requirements-txt-fixer
2428
- id: trailing-whitespace
25-
- repo: https://github.com/pre-commit/mirrors-autopep8
26-
rev: v1.5.1
27-
hooks:
28-
- id: autopep8
2929
- repo: https://github.com/asottile/pyupgrade
30-
rev: v2.1.1
30+
rev: v1.27.0
3131
hooks:
3232
- id: pyupgrade
3333
args: ['--py3-plus']
3434
- repo: https://github.com/asottile/seed-isort-config
35-
rev: v2.1.1
35+
rev: v1.9.4
3636
hooks:
3737
- id: seed-isort-config
3838
- repo: https://github.com/pre-commit/mirrors-isort

.travis.yml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,42 @@ python:
77
- "3.5"
88
- "3.6"
99
- "3.7"
10+
- "3.8"
11+
12+
services:
13+
- docker
1014

1115
install:
1216
- pip install -r requirements.txt
1317
- pip install -r requirements-dev.txt
1418
- pip install .
1519

16-
1720
script:
18-
- make test.unit
19-
- make test.integration
21+
- pytest --cov=alertaclient tests/unit
2022

2123
stages:
22-
- lint
24+
- Hooks
25+
- Checks
26+
- Test
27+
- Integration
2328

2429
jobs:
2530
include:
26-
- stage: lint
27-
script: make lint
31+
- stage: Hooks
32+
name: Pre-commit
33+
script: pre-commit run -a
34+
- stage: Checks
35+
name: Lint
36+
script: pylint --rcfile pylintrc alertaclient
37+
- name: Type Check
38+
script: python -m mypy alertaclient/
39+
- stage: Integration
40+
name: Integration Test
41+
script:
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
45+
46+
47+
after_success:
48+
- coveralls

Makefile

Lines changed: 90 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,113 @@
11

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+
414
.DEFAULT_GOAL:=help
515

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+
627
all: help
728

8-
## init - Initialise environment.
9-
init:
10-
pip install -r requirements.txt --upgrade
11-
pip install -e .
29+
$(PIP):
30+
python3 -m venv $(VENV)
1231

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
1834

19-
## hooks - Run pre-commit hooks.
20-
hooks:
21-
pre-commit run --all-files
35+
$(MYPY): $(PIP)
36+
$(PIP) install mypy
2237

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
2940

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
3452

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
3956

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)
4574

4675
## run - Run application.
4776
run:
48-
alerta top
77+
alertad
4978

5079
## tag - Git tag with current version.
5180
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
5490

5591
## 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
5999

60100
## help - Show this help.
61101
help: Makefile
102+
@echo ''
103+
@echo 'Usage:'
104+
@echo ' make [TARGET]'
105+
@echo ''
106+
@echo 'Targets:'
62107
@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

requirements-dev.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
mypy==0.620
1+
mypy
22
pre-commit
3+
pylint
34
pytest
45
pytest-cov
6+
python-dotenv
57
requests_mock
68
twine
9+
wheel

tox.ini

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[tox]
2+
envlist = py36,py37,py38
3+
skip_missing_interpreters=true
4+
5+
[testenv]
6+
deps =
7+
pytest
8+
requests_mock
9+
10+
commands = pytest -s {posargs} tests/unit/
11+
#passenv = *
12+
setenv =
13+
ALERTA_CONF_FILE =
14+
ALERTA_DEFAULT_PROFILE =

0 commit comments

Comments
 (0)