Makefile 2.35 KB
Newer Older
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
1
PYVERSIONS=3.4 2.7
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
2
PYMAIN=$(firstword $(PYVERSIONS))
3
4
5
6
7
8
9
NAME=senpy
REPO=gsiupm
VERSION=$(shell cat $(NAME)/VERSION)


all: build run

J. Fernando Sánchez's avatar
YAPFed    
J. Fernando Sánchez committed
10
11
12
13
yapf:
	yapf -i -r senpy
	yapf -i -r tests

14
15
16
17
dev:
	pip install --user pre-commit
	pre-commit install

18
dockerfiles: $(addprefix Dockerfile-,$(PYVERSIONS))
19
	ln -s Dockerfile-$(PYMAIN) Dockerfile
20
21
22
23

Dockerfile-%: Dockerfile.template
	sed "s/{{PYVERSION}}/$*/" Dockerfile.template > Dockerfile-$*

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
24
25
26
build: $(addprefix build-, $(PYMAIN))

buildall: $(addprefix build-, $(PYVERSIONS))
27
28
29
30

build-%: Dockerfile-%
	docker build -t '$(REPO)/$(NAME):$(VERSION)-python$*' -f Dockerfile-$* .;

31
32
33
build-debug-%:
	docker build -t '$(NAME)-debug' -f Dockerfile-debug-$* .;

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
34
35
36
test: $(addprefix test-,$(PYMAIN))

testall: $(addprefix test-,$(PYVERSIONS))
37

38
39
40
41
debug-%: build-debug-%
	docker run --rm -w /usr/src/app/ -v $$PWD:/usr/src/app --entrypoint=/bin/bash -ti $(NAME)-debug ;

debug: debug-$(PYMAIN)
42

43
test-%: build-%
44
	docker run --rm -w /usr/src/app/ --entrypoint=/usr/local/bin/python -ti '$(REPO)/$(NAME):$(VERSION)-python$*' setup.py test --addopts "-vvv -s" ;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
45

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
46
47
48
49
50
51
52
53
54
dist/$(NAME)-$(VERSION).tar.gz:
	docker run --rm -ti -v $$PWD:/usr/src/app/ -w /usr/src/app/ python:$(PYMAIN) python setup.py sdist;

sdist: dist/$(NAME)-$(VERSION).tar.gz

pip_test-%: sdist
	docker run --rm -v $$PWD/dist:/dist/ -ti python:$* pip install /dist/$(NAME)-$(VERSION).tar.gz ;

pip_test: $(addprefix pip_test-,$(PYVERSIONS))
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
55
56

upload-%: test-%
57
	docker push '$(REPO)/$(NAME):$(VERSION)-python$*'
58

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
59
60
upload: testall $(addprefix upload-,$(PYVERSIONS))
	docker tag '$(REPO)/$(NAME):$(VERSION)-python$(PYMAIN)' '$(REPO)/$(NAME):$(VERSION)'
61
62
63
64
65
66
	docker tag '$(REPO)/$(NAME):$(VERSION)-python$(PYMAIN)' '$(REPO)/$(NAME)'
	docker push '$(REPO)/$(NAME):$(VERSION)'

clean:
	@docker ps -a | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[1] != "${VERSION}"){ print $$1;}}' | xargs docker rm 2>/dev/null|| true
	@docker images | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[1] != "${VERSION}"){ print $$1":"$$2;}}' | xargs docker rmi 2>/dev/null|| true
67
	@docker rmi $(NAME)-debug 2>/dev/null || true
68

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
69
70
71
72
upload_git:
	git commit -a
	git tag ${VERSION}
	git push --tags origin master
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
73

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
74
75
pip_upload:
	python setup.py sdist upload ;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
76

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
77
pip_test: $(addprefix pip_test-,$(PYVERSIONS))
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
78

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
79
80
run: build
	docker run --rm -p 5000:5000 -ti '$(REPO)/$(NAME):$(VERSION)-python$(PYMAIN)'
81

82
.PHONY: test test-% build-% build test test_pip run yapf dev