-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
90 lines (76 loc) · 2.28 KB
/
Makefile
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
#!/usr/bin/env make
# External commands
BLACK ?= black
CTAGS ?= ctags
FIND ?= find
PYTHON ?= python
PYTEST ?= $(PYTHON) -m pytest
RM_R ?= rm -fr
SH ?= sh
TOX ?= tox
# Detect macOS to customize how we query the cpu count.
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo unknown')
ifeq ($(uname_S),Darwin)
NPROC ?= sysctl -n hw.activecpu
else
NPROC ?= nproc
endif
# Options
flags ?=
timeout ?= 600
# Default job count -- this is used if "-j" is not present in MAKEFLAGS.
nproc := $(shell sh -c '$(NPROC) 2>/dev/null || echo 4')
# Extract the "-j#" flags in $(MAKEFLAGS) so that we can forward the value to
# other commands. This can be empty.
JOB_FLAGS := $(shell echo -- $(MAKEFLAGS) | grep -o -e '-j[0-9]\+' | head -n 1)
# Extract just the number from "-j#".
JOB_COUNT := $(shell printf '%s' "$(JOB_FLAGS)" | sed -e 's/-j//')
# We have "-jX" from MAKEFLAGS but tox wants "--parallel X"
DASH_J := $(shell echo -- $(JOB_FLAGS) -j$(nproc) | grep -o -e '-j[0-9]\+' | head -n 1)
NUM_JOBS := $(shell printf %s "$(DASH_J)" | sed -e 's/-j//')
TESTCMD ?= $(PYTEST)
TOXCMD ?= $(TOX)
TOXCMD += --parallel $(NUM_JOBS)
TOXCMD += --develop --skip-missing-interpreters
ifdef multi
TOXCMD += -e
TOXCMD += 'clean,py{27,36,37,38},py{27,37}-sa{10,11,12,13},py{27,37}-libs'
endif
ifdef V
TESTCMD += --verbose
TOXCMD += -v
endif
# Data
ARTIFACTS := build
ARTIFACTS += dist
ARTIFACTS += __pycache__
ARTIFACTS += tags
ARTIFACTS += *.egg-info
PYTHON_DIRS := tests
PYTHON_DIRS += jsonpickle
# The default target of this makefile is....
all:: help
help:
@echo "---- Makefile Targets ----"
@echo "make help - print this message"
@echo "make test - run unit tests"
@echo "make tox - run unit tests using tox"
@echo "make tox multi=1 - run unit tests on multiple pythons using tox"
@echo "make clean - remove cruft"
.PHONY: help
test:
$(TESTCMD) $(flags)
.PHONY: test
tox:
$(TOXCMD) $(flags)
.PHONY: tox
tags:
$(FIND) $(PYTHON_DIRS) -name '*.py' -print0 | xargs -0 $(CTAGS) -f tags
clean:
$(FIND) $(PYTHON_DIRS) -name '*.py[cod]' -print0 | xargs -0 rm -f
$(FIND) $(PYTHON_DIRS) -name '__pycache__' -print0 | xargs -0 rm -fr
$(RM_R) $(ARTIFACTS)
.PHONY: clean
format::
$(BLACK) --skip-string-normalization --target-version py27 $(PYTHON_DIRS)
.PHONY: format