forked from gabrielfalcao/sure
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
135 lines (109 loc) · 4.07 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
MAKEFILE_PATH := $(realpath $(firstword $(MAKEFILE_LIST)))
GIT_ROOT := $(shell dirname $(MAKEFILE_PATH))
VENV_ROOT := $(GIT_ROOT)/.venv
PACKAGE_NAME := sure
MAIN_CLI_NAME := sure
REQUIREMENTS_FILE := development.txt
PACKAGE_PATH := $(GIT_ROOT)/$(PACKAGE_NAME)
REQUIREMENTS_PATH := $(GIT_ROOT)/$(REQUIREMENTS_FILE)
MAIN_CLI_PATH := $(VENV_ROOT)/bin/$(MAIN_CLI_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
######################################################################
# Phony targets (only exist for typing convenience and don't represent
# real paths as Makefile expects)
######################################################################
# default target when running `make` without arguments
all: | $(MAIN_CLI_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: | $(MAIN_CLI_PATH)
# Convenience target to ensure that the venv exists and all
# requirements are installed
dependencies:
@rm -f $(MAIN_CLI_PATH) # remove MAIN_CLI_PATH to trigger pip install
$(MAKE) develop setup
docs:
@(cd docs && make html)
$(OPEN_COMMAND) docs/build/html/index.html
test:
@$(VENV)/bin/pytest -vv
# run main command-line tool
run: | $(MAIN_CLI_PATH)
@$(MAIN_CLI_PATH) --help
# Pushes release of this package to pypi
push-release: dist # pushes distribution tarballs of the current version
$(VENV)/bin/twine upload dist/*.tar.gz
# Prepares release of this package prior to pushing to pypi
build-release:
rm -rf ./dist # remove local packages
$(VENV)/bin/twine check dist/*.tar.gz
$(VENV)/bin/python setup.py build sdist
# Convenience target that runs all tests then builds and pushes a release to pypi
release: tests build-release push-release
@rm -rf dist/*
@./.release
$(MAKE) build-release
$(MAKE) push-release
# Convenience target to delete the virtualenv
clean:
@rm -rf .venv
# Convenience target to format code with black with PEP8's default
# 80 character limit per line
black: | $(VENV)/bin/black
@$(VENV)/bin/black -l 80 $(PACKAGE_PATH) tests
##############################################################
# 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
# installs this package in "edit" mode after ensuring its requirements are installed
$(VENV)/bin/nosetests $(VENV)/bin/pytest $(MAIN_CLI_PATH): | $(VENV) $(VENV)/bin/pip $(VENV)/bin/python $(REQUIREMENTS_PATH)
$(VENV)/bin/pip install -r $(REQUIREMENTS_PATH)
$(VENV)/bin/pip install -e .
# 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 \
black \
build-release \
clean \
dependencies \
develop \
push-release \
release \
setup \
run \
test \
docs