forked from achillesrasquinha/pipupgrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
196 lines (146 loc) · 5.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
.PHONY: shell test help
BASEDIR = $(shell pwd)
-include ${BASEDIR}/.env
ENVIRONMENT ?= development
PROJECT = pipupgrade
PROJDIR = ${BASEDIR}/src/pipupgrade
TESTDIR = ${BASEDIR}/tests
DOCSDIR = ${BASEDIR}/docs
PYTHONPATH ?= python
VIRTUAL_ENV ?= ${BASEDIR}/.venv
VENVBIN ?= ${VIRTUAL_ENV}/bin
PYTHON ?= ${VENVBIN}/python
IPYTHON = ${VENVBIN}/ipython
PIP ?= ${VENVBIN}/pip
PYTEST ?= ${VENVBIN}/pytest
TOX = ${VENVBIN}/tox
COVERALLS ?= ${VENVBIN}/coveralls
IPYTHON = ${VENVBIN}/ipython
SAFETY = ${VENVBIN}/safety
PRECOMMIT = ${VENVBIN}/pre-commit
SPHINXBUILD = ${VENVBIN}/sphinx-build
TWINE = ${VENVBIN}/twine
JOBS ?= $(shell $(PYTHON) -c "import multiprocessing as mp; print(mp.cpu_count())")
PYTHON_ENVIRONMENT = $(shell $(PYTHON) -c "import sys;v=sys.version_info;print('py%s%s'%(v.major,v.minor))")
NULL = /dev/null
define log
$(eval CLEAR = \033[0m)
$(eval BOLD = \033[0;1m)
$(eval INFO = \033[0;36m)
$(eval SUCCESS = \033[0;32m)
$(eval BULLET = "→")
$(eval TIMESTAMP = $(shell date +%H:%M:%S))
@echo "${BULLET} ${$1}[${TIMESTAMP}]${CLEAR} ${BOLD}$2${CLEAR}"
endef
define browse
$(PYTHON) -c "import webbrowser as wb; wb.open('${$1}')"
endef
ifndef VERBOSE
.SILENT:
endif
.DEFAULT_GOAL := help
env: ## Create a Virtual Environment
ifneq (${VERBOSE},true)
$(eval OUT = > /dev/null)
endif
$(call log,INFO,Creating a Virtual Environment ${VIRTUAL_ENV} with Python - ${PYTHONPATH})
@virtualenv $(VIRTUAL_ENV) -p $(PYTHONPATH) $(OUT)
info: ## Display Information
@echo "Python Environment: ${PYTHON_ENVIRONMENT}"
install: clean info ## Install dependencies and module.
ifneq (${VERBOSE},true)
$(eval OUT = > /dev/null)
endif
ifneq (${PIPCACHEDIR},)
$(eval PIPCACHEDIR := --cache-dir $(PIPCACHEDIR))
endif
$(call log,INFO,Building Requirements)
@find $(BASEDIR)/requirements -maxdepth 1 -type f | xargs awk '{print}' > $(BASEDIR)/requirements-dev.txt
@cat $(BASEDIR)/requirements/production.txt > $(BASEDIR)/requirements.txt
@cat $(BASEDIR)/requirements/production.txt $(BASEDIR)/requirements/test.txt > $(BASEDIR)/requirements-test.txt
$(call log,INFO,Installing Requirements)
ifeq (${ENVIRONMENT},test)
$(PIP) install -r $(BASEDIR)/requirements-test.txt $(OUT)
else
$(PIP) install -r $(BASEDIR)/requirements-dev.txt $(OUT)
endif
$(call log,INFO,Installing ${PROJECT} (${ENVIRONMENT}))
ifeq (${ENVIRONMENT},development)
$(PYTHON) setup.py develop $(OUT)
else
$(PYTHON) setup.py install $(OUT)
endif
$(call log,SUCCESS,Installation Successful)
clean: ## Clean cache, build and other auto-generated files.
ifneq (${ENVIRONMENT},test)
@clear
$(call log,INFO,Cleaning Python Cache)
@find $(BASEDIR) | grep -E "__pycache__|\.pyc" | xargs rm -rf
@rm -rf \
$(BASEDIR)/*.egg-info \
$(BASEDIR)/.pytest_cache \
$(BASEDIR)/.tox \
$(BASEDIR)/*.coverage \
$(BASEDIR)/*.coverage.* \
$(BASEDIR)/htmlcov \
$(BASEDIR)/dist \
$(BASEDIR)/build \
~/.config/$(PROJECT)
$(call log,SUCCESS,Cleaning Successful)
else
$(call log,SUCCESS,Nothing to clean)
endif
console: install ## Open Console.
$(IPYTHON)
test: install ## Run tests.
$(call log,INFO,Running Python Tests using $(JOBS) jobs.)
$(TOX) --skip-missing-interpreters $(ARGS)
coverage: install ## Run tests and display coverage.
ifeq (${ENVIRONMENT},development)
$(eval IARGS := --cov-report html)
endif
$(PYTEST) -s -n $(JOBS) --cov $(PROJDIR) $(IARGS) -vv $(ARGS)
ifeq (${ENVIRONMENT},development)
$(call browse,file:///${BASEDIR}/htmlcov/index.html)
endif
ifeq (${ENVIRONMENT},test)
$(COVERALLS)
endif
shell: ## Launch an IPython shell.
$(call log,INFO,Launching Python Shell)
$(IPYTHON) \
--no-banner
build: clean ## Build the Distribution.
$(PYTHON) setup.py sdist bdist_wheel
pre-commit: ## Perform Pre-Commit Tasks.
$(PRECOMMIT) run
docs: install ## Build Documentation
ifneq (${VERBOSE},true)
$(eval OUT = > /dev/null)
endif
$(call log,INFO,Building Documentation)
$(SPHINXBUILD) $(DOCSDIR)/source $(DOCSDIR)/build $(OUT)
$(call log,SUCCESS,Building Documentation Successful)
ifeq (${launch},true)
$(call browse,file:///${DOCSDIR}/build/index.html)
endif
docker-build: clean ## Build the Docker Image.
$(call log,INFO,Building Docker Image)
@docker build $(BASEDIR) --tag $(DOCKER_HUB_USERNAME)/$(PROJECT) $(DOCKER_BUILD_ARGS)
docker-tox: clean ## Test using Docker Tox Image.
$(call log,INFO,Running Tests using Docker Tox)
$(eval TMPDIR := /tmp/$(PROJECT)-$(shell date +"%Y_%m_%d_%H_%M_%S"))
@mkdir $(TMPDIR)
@cp -R . $(TMPDIR)
@docker run --rm -v $(TMPDIR):/app themattrix/tox
@rm -rf $(TMPDIR)
release: ## Create a Release
$(PYTHON) setup.py sdist bdist_wheel
ifeq (${ENVIRONMENT},development)
$(call log,WARN,Ensure your environment is in production mode.)
$(TWINE) upload --repository-url https://test.pypi.org/legacy/ $(BASEDIR)/dist/*
else
$(TWINE) upload --repository-url https://upload.pypi.org/legacy/ $(BASEDIR)/dist/*
endif
help: ## Show help and exit.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)