summaryrefslogtreecommitdiff
path: root/Makefile
blob: 8466ce9f735a3c5517b4884b02c89aed9ee92c3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright 2017 Canonical Ltd.
# Licensed under the LGPLv3, see LICENCE file for details.
include sysdeps.mk

PYTHON = python
# Since the python-tox package in Ubuntu uses Python 3, use pip to install tox
# instead. This also works on OSX where tox is not present in Homebrew.
PIP_SYSDEPS = tox

PIP = sudo pip install $(1)

SYSDEPS_INSTALLED = .sysdeps-installed
DEVENV = devenv
DEVENVPIP = $(DEVENV)/bin/pip

.DEFAULT_GOAL := setup

$(DEVENVPIP):
	@tox -e devenv

$(SYSDEPS_INSTALLED): sysdeps.mk
ifeq ($(shell command -v apt-get > /dev/null; echo $$?),0)
	sudo apt-get install --yes $(APT_SYSDEPS)
else
	@echo 'System dependencies can only be installed automatically on'
	@echo 'systems with "apt-get". On OSX you can manually use Homebrew'
	@echo 'if there are missing dependencies corresponding to the following'
	@echo 'Debian packages:'
	@echo '$(APT_SYSDEPS).'
endif
	sudo pip2 install $(PIP_SYSDEPS)
	touch $(SYSDEPS_INSTALLED)


.PHONY: check
check: setup lint
	@tox

.PHONY: clean
clean:
	$(PYTHON) setup.py clean
	# Remove the development environments.
	rm -rfv $(DEVENV) .tox/
	# Remove distribution artifacts.
	rm -rfv *.egg build/ dist/ macaroonbakery.egg-info MANIFEST
	# Remove tests artifacts.
	rm -fv .coverage
	# Remove the canary file.
	rm -fv $(SYSDEPS_INSTALLED)
	# Remove Python compiled bytecode.
	find . -name '*.pyc' -delete
	find . -name '__pycache__' -type d -delete

.PHONY: docs
docs: setup
	@tox -e docs

.PHONY: help
help:
	@echo -e 'Macaroon Bakery - list of make targets:\n'
	@echo 'make - Set up the development and testing environment.'
	@echo 'make test - Run tests.'
	@echo 'make lint - Run linter and pep8.'
	@echo 'make check - Run all the tests and lint in all supported scenarios.'
	@echo 'make source - Create source package.'
	@echo 'make clean - Get rid of bytecode files, build and dist dirs, venvs.'
	@echo 'make release - Register and upload a release on PyPI.'
	@echo -e '\nAfter creating the development environment with "make", it is'
	@echo 'also possible to do the following:'
	@echo '- run a specific subset of the test suite, e.g. with'
	@echo '  "$(DEVENV)/bin/nosetests bakery/tests/...";'
	@echo '- use tox as usual on this project;'
	@echo '  see https://tox.readthedocs.org/en/latest/'


.PHONY: lint
lint: setup
	@tox -e lint

.PHONY: release
release: check
	$(PYTHON) setup.py register sdist upload

.PHONY: setup
setup: $(SYSDEPS_INSTALLED) $(DEVENVPIP) setup.py

.PHONY: source
source:
	$(PYTHON) setup.py sdist

.PHONY: sysdeps
sysdeps: $(SYSDEPS_INSTALLED)

.PHONY: test
test: setup
	@$(DEVENV)/bin/nosetests \
		--verbosity 2 --with-coverage --cover-erase \
		--cover-package macaroonbakery

.PHONY: isort
isort:
	isort \
		--trailing-comma \
		--recursive \
		--multi-line 3 \
		`find macaroonbakery -name '*.py' | grep -v 'internal/id_pb2\.py'`