-
Notifications
You must be signed in to change notification settings - Fork 74
/
Makefile
161 lines (125 loc) · 4.73 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
MAKEFILE_PATH := $(realpath $(firstword $(MAKEFILE_LIST)))
GIT_ROOT := $(shell dirname $(MAKEFILE_PATH))
VENV_ROOT := $(GIT_ROOT)/.venv
PACKAGE_NAME := sure
LIBEXEC_NAME := sure
REQUIREMENTS_FILE := development.txt
PACKAGE_PATH := $(GIT_ROOT)/$(PACKAGE_NAME)
REQUIREMENTS_PATH := $(GIT_ROOT)/$(REQUIREMENTS_FILE)
LIBEXEC_PATH := $(VENV_ROOT)/bin/$(LIBEXEC_NAME)
export VENV ?= $(VENV_ROOT)
OSNAME := $(shell uname)
ifeq ($(OSNAME), Linux)
OPEN_COMMAND := gnome-open
else
OPEN_COMMAND := open
endif
export SURE_NO_COLORS := true
export SURE_LOG_FILE := $(GIT_ROOT)/sure-$(date +"%Y-%m-%d-%H:%M:%S").log
export PYTHONPATH := $(GIT_ROOT)
AUTO_STYLE_TARGETS := sure/runtime.py sure/runner.py sure/meta.py sure/meta.py sure/reporter.py sure/reporters
######################################################################
# Phony targets (only exist for typing convenience and don't represent
# real paths as Makefile expects)
######################################################################
# default target when running `make` without arguments
all: | $(LIBEXEC_PATH)
# creates virtualenv
venv: | $(VENV)
# updates pip and setuptools to their latest version
develop: | $(VENV)/bin/python $(VENV)/bin/pip
# installs the requirements and the package dependencies
setup: | $(LIBEXEC_PATH)
# Convenience target to ensure that the venv exists and all
# requirements are installed
dependencies: $(VENV)/bin/pytest
@rm -f $(LIBEXEC_PATH) # remove LIBEXEC_PATH to trigger pip install
$(MAKE) develop setup
clean-docs:
@rm -rf docs/build
html-docs: clean-docs
@(cd docs && make html)
docs: html-docs
$(OPEN_COMMAND) docs/build/html/index.html
test:
@$(VENV)/bin/pytest --cov=sure tests
tests: test run
# runs main command-line tool
run: | $(LIBEXEC_PATH)
$(LIBEXEC_PATH) --reap-warnings tests/crashes
$(LIBEXEC_PATH) --reap-warnings --special-syntax --with-coverage --cover-branches --cover-erase --cover-module=sure --immediate --cover-module=sure --ignore tests/crashes tests
push-release: dist # pushes distribution tarballs of the current version
$(VENV)/bin/twine upload dist/*.tar.gz
build-release:
$(VENV)/bin/python setup.py build sdist
$(VENV)/bin/twine check dist/*.tar.gz
release: tests
@./.release
$(MAKE) build-release
$(MAKE) push-release
clean:
@rm -rf .coverage
flake8: | $(VENV)/bin/flake8
@$(VENV)/bin/flake8 --statistics --max-complexity 17 --exclude=$(VENV) $(AUTO_STYLE_TARGETS)
black: | $(VENV)/bin/black
@$(VENV)/bin/black -l 80 $(AUTO_STYLE_TARGETS)
isort: | $(VENV)/bin/isort
@$(VENV)/bin/isort --overwrite-in-place --profile=black --ls --srx --cs --ca -n --ot --tc --color --star-first --virtual-env $(VENV) --py auto $(AUTO_STYLE_TARGETS)
autostyle: run isort black flake8
##############################################################
# Real targets (only run target if its file has been "made" by
# Makefile yet)
##############################################################
# creates virtual env if necessary and installs pip and setuptools
$(VENV): | $(REQUIREMENTS_PATH) # creates $(VENV) folder if does not exist
echo "Creating virtualenv in $(VENV_ROOT)" && python3 -mvenv $(VENV)
# installs pip and setuptools in their latest version, creates virtualenv if necessary
$(VENV)/bin/python $(VENV)/bin/pip: # installs latest pip
@test -e $(VENV)/bin/python || $(MAKE) $(VENV)
@test -e $(VENV)/bin/pip || $(MAKE) $(VENV)
@echo "Installing latest version of pip and setuptools"
@$(VENV)/bin/pip install -U pip setuptools
# installs latest version of the "black" code formatting tool
$(VENV)/bin/black: | $(VENV)/bin/pip
$(VENV)/bin/pip install -U black
$(VENV)/bin/isort: | $(VENV)/bin/pip
$(VENV)/bin/pip install -U isort
$(VENV)/bin/flake8: | $(VENV)/bin/pip
$(VENV)/bin/pip install -U flake8
# installs this package in "edit" mode after ensuring its requirements are installed
install $(VENV)/bin/pytest $(LIBEXEC_PATH): | $(VENV) $(VENV)/bin/pip $(VENV)/bin/python $(REQUIREMENTS_PATH)
$(VENV)/bin/pip install -r $(REQUIREMENTS_PATH)
$(VENV)/bin/pip install .
# ensure that REQUIREMENTS_PATH exists
$(REQUIREMENTS_PATH):
@echo "The requirements file $(REQUIREMENTS_PATH) does not exist"
@echo ""
@echo "To fix this issue:"
@echo " edit the variable REQUIREMENTS_NAME inside of the file:"
@echo " $(MAKEFILE_PATH)."
@echo ""
@exit 1
###############################################################
# Declare all target names that exist for convenience and don't
# represent real paths, which is what Make expects by default:
###############################################################
.PHONY: \
all \
autostyle \
black \
build-release \
clean \
clean-docs \
dependencies \
develop \
docs \
flake8 \
html-docs \
install \
isort \
push-release \
release \
run \
setup \
test \
tests