-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
141 lines (101 loc) · 5.12 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
#
# Makefile, ver 1.6, PROJECT: stslib
#
# --- declarations --------------------------------------------------------------------------------
PROJECT := stslib
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
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
.PHONY: setup-venv
setup-venv: ## Create and activiate python venv
$(PYTHON3_PATH) -m venv $(VENV_DIR)
. $(VENV_DIR)/bin/activate && $(PIP_CALL) install -U setuptools pip && \
$(PIP_CALL) install -r $(REQUIREMENT)
.PHONY: test
test: ## Run pytest unittests
if [ $(PDB) ]; then PDB = "true"; \
bash $(CUR_DIR)/scripts/make-test.sh $(CUR_DIR) $(VENV_DIR) $(MODULE_PATH) $(PDB); \
elif [ $(MODULE) ]; then PDB = "false"; \
bash $(CUR_DIR)/scripts/make-test.sh $(CUR_DIR) $(VENV_DIR) $(MODULE_PATH) $(PDB) $(MODULE); \
elif [ $(COMPLEXITY) ]; then COMPLEXITY = "run"; \
bash $(CUR_DIR)/scripts/make-test.sh $(CUR_DIR) $(VENV_DIR) $(MODULE_PATH) $(COMPLEXITY) $(MODULE); \
else bash $(CUR_DIR)/scripts/make-test.sh $(CUR_DIR) $(VENV_DIR) $(MODULE_PATH); fi
docs: setup-venv ## Generate sphinx documentation
. $(VENV_DIR)/bin/activate && \
$(PIP_CALL) install sphinx sphinx_rtd_theme autodoc
cd $(CUR_DIR) && $(MAKE) clean-docs
cd $(DOC_PATH) && . $(VENV_DIR)/bin/activate && $(MAKE) html
.PHONY: build
build: pre-build setup-venv ## Build dist, increment version || force version (VERSION=X.Y)
if [ $(VERSION) ]; then bash $(SCRIPTS)/version_update.sh $(VERSION); \
else bash $(SCRIPTS)/version_update.sh; 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/*
.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: setup-venv ## Install (source: local source). Build artifacts exist
if [ ! -e $(VENV_DIR) ]; then $(MAKE) clean; fi; \
cd $(CUR_DIR) && . $(VENV_DIR)/bin/activate && \
$(PIP_CALL) install .
.PHONY: update-source-install
update-source-install: ## Update Install (source: local source).
if [ -e $(VENV_DIR) ]; then \
cp -rv $(MODULE_PATH) $(VENV_DIR)/lib/python3.6/site-packages/; fi
.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"
if [ -e $(VENV_DIR) ]; then . $(VENV_DIR)/bin/activate && \
cd $(DOC_PATH) && $(MAKE) clean || true; fi
.PHONY: clean
clean: clean-docs ## Remove all build artifacts generated by make
@echo "Cleanup"
rm -rf $(VENV_DIR)
rm -rf $(CUR_DIR)/dist
rm -rf $(CUR_DIR)/*.egg-info
rm -f $(CUR_DIR)/README.rst || true
rm -rf $(CUR_DIR)/$(PROJECT)/__pycache__ || true
rm -rf $(CUR_DIR)/tests/__pycache__ || true
rm -rf $(CUR_DIR)/.pytest_cache || true