-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile
224 lines (167 loc) · 6.89 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
SHELL := /bin/bash
ROOT_DIR := $(shell pwd)
DOCS_DIR := $(ROOT_DIR)/docs
DOCS_BUILD_DIR := $(DOCS_DIR)/_build
PROJECT_NAME := $(notdir $(ROOT_DIR))
PROJECT_DOCKER_TAG := steemit/$(PROJECT_NAME)
PYTHON_VERSION := 3.6
PYTHON := $(shell which python$(PYTHON_VERSION))
PIPENV := $(shell which pipenv)
PIPENV_VENV_IN_PROJECT := 1
export PIPENV_VENV_IN_PROJECT
ENVFILE := .env
PROJECT_DOCKER_RUN_ARGS := -p8080:8080 --env-file .env
BUILD_DIR := $(ROOT_DIR)/build
CODEGEN_PATH := sbds/codegen
EXAMPLES_PATH :=$(CODEGEN_PATH)/examples
HEADERS_PATH := $(CODEGEN_PATH)/headers
TEMPLATES_PATH := $(CODEGEN_PATH)/templates
SBDS_BASE_CMD := $(PIPENV) run python -m sbds.cli
STORAGES_DB_PATH := sbds/storages/db
VIEWS_PATH := $(STORAGES_DB_PATH)/views
TABLES_PATH := $(STORAGES_DB_PATH)/tables
META_PATH := $(TABLES_PATH)/meta
OPERATIONS_PATH := $(TABLES_PATH)/operations
VIRTUAL_OPERATIONS_PATH := $(TABLES_PATH)/operations/virtual
OPERATIONS_HEADER_FILE := $(HEADERS_PATH)/operations_header.json
VIRTUAL_OPERATIONS_HEADER_FILE := $(HEADERS_PATH)/virtual_operations_header.json
OPERATION_NAMES := $(filter %operation, $(shell jq -r '.classes[].name' $(OPERATIONS_HEADER_FILE)))
VIRTUAL_OPERATION_NAMES := $(filter %operation, $(shell jq -r '.classes[].name' $(VIRTUAL_OPERATIONS_HEADER_FILE)))
OPERATION_PYTHON_FILES := $(addprefix $(OPERATIONS_PATH)/, $(addsuffix .py, $(subst _operation,,$(OPERATION_NAMES))))
VIRTUAL_OPERATION_PYTHON_FILES := $(addprefix $(VIRTUAL_OPERATIONS_PATH)/, $(addsuffix .py, $(subst _operation,,$(VIRTUAL_OPERATION_NAMES))))
META_NAMES := accounts
META_PYTHON_FILES := $(addprefix $(VIEWS_PATH)/, $(addsuffix .py, $(META_NAMES)))
VIEWS_NAMES := accounts accounts_history
VIEWS_PYTHON_FILES := $(addprefix $(VIEWS_PATH)/, $(addsuffix .py, $(VIEWS_NAMES)))
default: help
.PHONY: help
help:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: init
init: clean ## install project requrements into .venv
pip3 install --upgrade pipenv
-$(PIPENV) --rm
if [[ $(shell uname) == 'Darwin' ]]; then \
brew install openssl postgresql; \
env LDFLAGS="-L$(shell brew --prefix openssl)/lib" CFLAGS="-I$(shell brew --prefix openssl)/include" $(PIPENV) install --python $(PYTHON) --dev --skip-lock; \
else \
$(PIPENV) install --python 3.6 --dev --skip-lock; \
fi
$(PIPENV) run pre-commit install
Pipfile.lock: Pipfile
$(shell docker run $(PROJECT_DOCKER_TAG) /bin/bash -c 'pipenv lock && cat Pipfile.lock' > $@)
.PHONY: clean
clean: unmac ## clean python and dev junk
find . -name "__pycache__" | xargs rm -rf
-rm -rf .cache
-rm -rf .eggs
-rm -rf .mypy_cache
-rm -rf *.egg-info
-rm -rf *.log
-rm -rf service/*/supervise
.PHONY: build
build: clean clean-perf ## build docker image
docker build -t $(PROJECT_DOCKER_TAG) .
.PHONY: run
run: ## run docker image
docker run $(PROJECT_DOCKER_RUN_ARGS) $(PROJECT_DOCKER_TAG)
.PHONY: run-local
run-local: ## run the python app without docker
$(PIPENV) run python3 -m jussi.serve --debug=1 --server_workers=1 --upstream_config_file ALT_CONFIG.json
.PHONY: test
test: ## run all tests
$(PIPENV) run pytest
.PHONY: test-with-docker
test-with-docker: Pipfile.lock build ## run tests that depend on docker
$(PIPENV) run pytest --rundocker --jussiurl http://localhost:8080
.PHONY: lint
lint: ## lint python files
$(PIPENV) run pylint $(PROJECT_NAME)
.PHONY: fmt
fmt: ## format python files
# yapf is disabled until the update 3.6 fstring compat
$(PIPENV) run yapf --in-place --style pep8 --recursive $(PROJECT_NAME) tests
$(PIPENV) run autopep8 --verbose --verbose --max-line-length=100 --aggressive --jobs -1 --in-place --recursive $(PROJECT_NAME) tests
.PHONY: fix-imports
fix-imports: remove-unused-imports sort-imports ## remove unused and then sort imports
.PHONY: remove-unused-imports
remove-unused-imports: ## remove unused imports from python files
$(PIPENV) run autoflake --in-place --remove-all-unused-imports --recursive $(PROJECT_NAME) tests
.PHONY: sort-imports
sort-imports: ## sorts python imports using isort with settings from .editorconfig
$(PIPENV) run isort --verbose --recursive --atomic --settings-path .editorconfig --virtual-env .venv $(PROJECT_NAME) tests
.PHONY: pipenv-check
pipenv-check: ## run pipenv's package security checker
$(PIPENV) check
.PHONY: pre-commit-init
pre-commit-init: ## initialize pre-commit
$(PIPENV) run pre-commit install
.PHONY: pre-commit
pre-commit: ## run pre-commit against modified files
$(PIPENV) run pre-commit run
.PHONY: pre-commit-all
pre-commit-all: ## run pre-commit against all files
$(PIPENV) run pre-commit run --all-files
.PHONY: unmac
unmac:
find $(ROOT_DIR) -type f -name '.DS_Store' -delete
.PHONY: prepare
prepare: fix-imports lint fmt pre-commit-all pipenv-check test unmac ## fix-imports lint fmt pre-commit-all pipenv-check test
.PHONY: prepare-and-build
prepare-and-build: prepare Pipfile.lock build ## run all tests, formatting and pre-commit checks, then build docker image
.PHONY: prepare-and-test
prepare-and-test: prepare test-with-docker ## run all tests, formatting and pre-commit checks, build docker image, test docker image
.PHONY: sql
sql:
psql
.PHONY: reset-db
reset-db:
$(PIPENV) run python -m sbds.cli db reset
.PHONY: init-db
init-db:
$(PIPENV) run python -m sbds.cli db init
.PHONY: ipython
ipython:
envdir envd $(PIPENV) run ipython -i sbds/storages/db/scripts/ipython_init.py
README.rst: docs/src/README.rst
cd $(DOCS_DIR) && $(MAKE) README
# --- CODEGEN -- #
$(VIRTUAL_OPERATIONS_PATH)/%.py: $(TEMPLATES_PATH)/operation_class.tmpl
$(SBDS_BASE_CMD) codegen generate-class $(*F) \
--templates_path $(TEMPLATES_PATH) \
--headers_path $(HEADERS_PATH) \
--examples_path $(EXAMPLES_PATH) > $@
$(OPERATIONS_PATH)/%.py: $(TEMPLATES_PATH)/operation_class.tmpl
$(SBDS_BASE_CMD) codegen generate-class $(*F) \
--templates_path $(TEMPLATES_PATH) \
--headers_path $(HEADERS_PATH) \
--examples_path $(EXAMPLES_PATH) > $@
$(VIEW_PATH)/%.py: $(TEMPLATES_PATH)/operation_class.tmpl
$(SBDS_BASE_CMD) codegen generate-view $(*F) \
--templates_path $(TEMPLATES_PATH) \
--headers_path $(HEADERS_PATH) \
--examples_path $(EXAMPLES_PATH) > $@
$(META_PATH)/%.py: $(TEMPLATES_PATH)/operation_class.tmpl
$(SBDS_BASE_CMD) codegen generate-meta $(*F) \
--templates_path $(TEMPLATES_PATH) \
--headers_path $(HEADERS_PATH) \
--examples_path $(EXAMPLES_PATH) > $@
virtual-ops: $(VIRTUAL_OPERATION_PYTHON_FILES)
ops: $(OPERATION_PYTHON_FILES)
.PHONY: delete-virtual-ops
delete-virtual-ops:
-rm $(VIRTUAL_OPERATION_PYTHON_FILES)
.PHONY: delete-ops
delete-ops:
-rm $(OPERATION_PYTHON_FILES)
.PHONY: remove-ops
remove-ops: delete-ops delete-virtual-ops
.PHONY: build-ops
build-ops: ops virtual-ops
.PHONY: rebuild-ops
rebuild-ops: remove-ops build-ops
$(VIEWS_PATH)/%.py: $(TEMPLATES_PATH)/operation_class.tmpl
$(SBDS_BASE_CMD) codegen generate-view $(*F) \
--templates_path $(TEMPLATES_PATH) \
--headers_path $(HEADERS_PATH) \
--examples_path $(EXAMPLES_PATH) > $@