-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
173 lines (120 loc) · 6.45 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
162
163
164
165
166
167
168
169
170
171
172
173
#---------------------------------------------------------------------------------------#
# #
# - Makefile, version 1.8.2 #
# - PROJECT: spotlib #
# - copyright, Blake Huber. All rights reserved. #
# #
#---------------------------------------------------------------------------------------#
PROJECT := spotlib
CUR_DIR = $(shell pwd)
PYTHON_VERSION := python3
PYTHON3_PATH := $(shell which $(PYTHON_VERSION))
GIT := $(shell which git)
VENV_DIR := $(CUR_DIR)/p3_venv
PIP_CALL := $(VENV_DIR)/bin/pip
PANDOC_CALL := $(shell which pandoc)
ACTIVATE = $(shell . $(VENV_DIR)/bin/activate)
MAKE = $(shell which make)
MODULE_PATH := $(CUR_DIR)/$(PROJECT)
SCRIPTS := $(CUR_DIR)/scripts
DOC_PATH := $(CUR_DIR)/docs
REQUIREMENT = $(CUR_DIR)/requirements.txt
VERSION_FILE = $(CUR_DIR)/$(PROJECT)/_version.py
# --- rollup targets ------------------------------------------------------------------------------
.PHONY: fresh-install fresh-test-install deploy-test deploy-prod
zero-source-install: clean source-install ## Install (source: local). Zero prebuild artifacts
zero-test-install: clean setup-venv test-install ## Install (source: testpypi). Zero prebuild artifacts
deploy-test: clean testpypi ## Deploy (testpypi), generate all prebuild artifacts
deploy-prod: clean pypi ## Deploy (pypi), generate all prebuild artifacts
# --- targets -------------------------------------------------------------------------------------
.PHONY: pre-build
pre-build: ## Remove residual build artifacts
rm -rf $(CUR_DIR)/dist
mkdir $(CUR_DIR)/dist
setup-venv: $(VENV_DIR)
$(VENV_DIR): clean pre-build ## Create and activiate python virtual package environment
$(PYTHON3_PATH) -m venv $(VENV_DIR)
. $(VENV_DIR)/bin/activate && $(PIP_CALL) install -U setuptools pip && \
$(PIP_CALL) install -r $(REQUIREMENT)
.PHONY: artifacts
artifacts: setup-venv ## Generate documentation build artifacts (*.rst)
. $(VENV_DIR)/bin/activate && $(PIP_CALL) install pandoc && \
$(PANDOC_CALL) --from=markdown --to=rst README.md --output=README.rst
.PHONY: test
test: setup-venv ## Run pytest unittests. Optional Param: PDB, MODULE
if [ $(MODULE) ]; then \
bash $(CUR_DIR)/scripts/make-test.sh --package-path $(MODULE_PATH) --module $(MODULE); \
else bash $(CUR_DIR)/scripts/make-test.sh --package-path $(MODULE_PATH); fi
.PHONY: test-coverage
test-coverage: setup-venv ## Run pytest unittests; generate coverage report
bash $(CUR_DIR)/scripts/make-test.sh --package-path $(MODULE_PATH) --coverage
.PHONY: test-complexity
test-complexity: setup-venv ## Run pytest unittests; generate McCabe Complexity Report
bash $(CUR_DIR)/scripts/make-test.sh --package-path $(MODULE_PATH) --complexity
.PHONY: test-pdb
test-pdb: setup-venv ## Run pytest unittests with debugging output on
bash $(CUR_DIR)/scripts/make-test.sh --package-path $(MODULE_PATH) --pdb
.PHONY: test-help
test-help: ## Print runtime options for running pytest unittests
bash $(CUR_DIR)/scripts/make-test.sh --help
.PHONY: build
build: artifacts ## Build dist, increment version || force version (VERSION=X.Y)
if [ $(VERSION) ]; then . $(VENV_DIR)/bin/activate && \
versionpro --set-version $(VERSION) --update; \
else . $(VENV_DIR)/bin/activate && versionpro --update; fi; \
. $(VENV_DIR)/bin/activate && cd $(CUR_DIR) && $(PYTHON3_PATH) setup.py sdist
.PHONY: testpypi
testpypi: build ## Deploy to testpypi without regenerating prebuild artifacts
@echo "Deploy $(PROJECT) to test.pypi.org"
. $(VENV_DIR)/bin/activate && twine upload --repository testpypi dist/*
.PHONY: pypi
pypi: clean build ## Deploy to pypi without regenerating prebuild artifacts
@echo "Deploy $(PROJECT) to pypi.org"
. $(VENV_DIR)/bin/activate && twine upload --repository pypi dist/*
rm -f $(CUR_DIR)/README.rst
.PHONY: install
install: ## Install (source: pypi). Build artifacts exist
if [ ! -e $(VENV_DIR) ]; then $(MAKE) setup-venv; fi; \
cd $(CUR_DIR) && . $(VENV_DIR)/bin/activate && \
$(PIP_CALL) install -U $(PROJECT)
.PHONY: test-install
test-install: ## Install (source: testpypi). Build artifacts exist
if [ ! -e $(VENV_DIR) ]; then $(MAKE) setup-venv; fi; \
cd $(CUR_DIR) && . $(VENV_DIR)/bin/activate && \
$(PIP_CALL) install -U $(PROJECT) --extra-index-url https://test.pypi.org/simple/
.PHONY: source-install
source-install: clean setup-venv ## Install (source: local source). Build artifacts exist
cd $(CUR_DIR) && . $(VENV_DIR)/bin/activate && $(PIP_CALL) install .
.PHONY: update-src-install
update-src-install: ## Update Install (source: local source).
if [ -e $(VENV_DIR) ]; then \
cp -rv $(MODULE_PATH) $(VENV_DIR)/lib/python3*/site-packages/; fi
.PHONY: simulate
simulate: ## Simulate a build to show version labels to be applied
cd $(CUR_DIR) && versionpro --dryrun;
.PHONY: upload-images
upload-images: ## Upload README images to Amazon S3
bash $(CUR_DIR)/scripts/s3upload.sh
.PHONY: help
help: ## Print help index
@printf "\n\033[0m %-15s\033[0m %-13s\u001b[37;1m%-15s\u001b[0m\n\n" " " "make targets: " $(PROJECT)
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[0m%-2s\033[36m%-20s\033[33m %-8s\033[0m%-5s\n\n"," ", $$1, "-->", $$2}' $(MAKEFILE_LIST)
@printf "\u001b[37;0m%-2s\u001b[37;0m%-2s\n\n" " " "___________________________________________________________________"
@printf "\u001b[37;1m%-3s\u001b[37;1m%-3s\033[0m %-6s\u001b[44;1m%-9s\u001b[37;0m%-15s\n\n" " " " make" "deploy-[test|prod] " "VERSION=X" " to deploy specific version"
.PHONY: clean-docs
clean-docs: ## Remove build artifacts for documentation only
@echo "Clean docs build directory"
cd $(DOC_PATH) && $(VENV_DIR)/bin/activate && $(MAKE) clean || true
.PHONY: clean
clean: clean-docs ## Remove generic build artifacts common to most targets
@echo "Clean project directories"
rm -rf $(VENV_DIR) || true
rm -rf $(CUR_DIR)/dist || true
rm -rf $(CUR_DIR)/*.egg* || true
rm -f $(CUR_DIR)/README.rst || true
rm -rf $(CUR_DIR)/$(PROJECT)/__pycache__ || true
rm -rf $(CUR_DIR)/$(PROJECT)/core/__pycache__ || true
rm -rf $(CUR_DIR)/tests/__pycache__ || true
rm -rf $(CUR_DIR)/docs/__pycache__ || true
rm -rf $(CUR_DIR)/.pytest_cache || true
rm -rf $(CUR_DIR)/build || true