-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
171 lines (138 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
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
#
# GLOBALS
#
define BROWSER_PYSCRIPT
import os, webbrowser, sys
try:
from urllib import pathname2url
except:
from urllib.request import pathname2url
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"
# Get local user ids
USER_ID = $(shell id -u)
GROUP_ID = $(shell id -g)
# Docker
COMPOSE = USER_ID=$(USER_ID) GROUP_ID=$(GROUP_ID) docker-compose
COMPOSE_RUN = $(COMPOSE) run --rm
COMPOSE_RUN_LMS = $(COMPOSE_RUN) lms
COMPOSE_RUN_FONZIE = $(COMPOSE_RUN) fonzie
COMPOSE_EXEC = $(COMPOSE) exec
# Django
MANAGE_LMS = $(COMPOSE_EXEC) lms dockerize -wait tcp://mysql:3306 -timeout 60s python manage.py lms
# -- Python
PYTEST = $(COMPOSE_RUN) -e DJANGO_SETTINGS_MODULE=lms.envs.fun.docker_run_test lms dockerize -wait tcp://mysql:3306 -timeout 60s pytest -c /edx/app/fonzie/setup.cfg
#
# RULES
#
default: help
help: ## display this help message
@echo "Please use \`make <target>' where <target> is one of"
@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}'
.PHONY: help
bootstrap: run migrate demo-course ## bootstrap the project
.PHONY: bootstrap
build: ## build project containers
$(COMPOSE) build lms
.PHONY: build
clean: ## remove generated byte code, coverage reports, and build artifacts
$(COMPOSE_RUN_FONZIE) find . -name '__pycache__' -exec rm -rf {} +
$(COMPOSE_RUN_FONZIE) find . -name '*.pyc' -exec rm -f {} +
$(COMPOSE_RUN_FONZIE) find . -name '*.pyo' -exec rm -f {} +
$(COMPOSE_RUN_FONZIE) find . -name '*~' -exec rm -f {} +
$(COMPOSE_RUN) --no-deps lms coverage erase
$(COMPOSE_RUN_FONZIE) rm -fr build/
$(COMPOSE_RUN_FONZIE) rm -fr dist/
$(COMPOSE_RUN_FONZIE) rm -fr *.egg-info
.PHONY: clean
coverage: clean ## generate and view HTML coverage report
$(PYTEST) --cov-report html
$(BROWSER) edx-platform/reports/cover/index.html
.PHONY: coverage
diff_cover: test
$(DIFF-COVER) edx-platform/reports/coverage.xml
.PHONY: diff_cover
docs: ## generate Sphinx HTML documentation, including API docs
$(COMPOSE_RUN_FONZIE) doc8 --ignore-path docs/_build README.rst docs
rm -f docs/fonzie.rst
rm -f docs/modules.rst
$(COMPOSE_RUN_FONZIE) make -C docs clean
$(COMPOSE_RUN_FONZIE) make -C docs html
$(COMPOSE_RUN_FONZIE) python setup.py check --restructuredtext --strict
$(BROWSER) docs/_build/html/index.html
.PHONY: docs
migrate: run ## run project migrations
$(MANAGE_LMS) migrate
.PHONY: migrate
lint: ## check coding style with pycodestyle and pylint
lint: \
lint-pylint \
lint-bandit \
lint-pycodestyle \
lint-isort \
lint-pyroma \
selfcheck
.PHONY: lint
lint-pylint: ## lint python sources with pylint
@echo "lint:pylint started…"
$(COMPOSE_RUN_FONZIE) pylint fonzie tests
$(COMPOSE_RUN_FONZIE) pylint --py3k fonzie tests
.PHONY: lint-pylint
lint-bandit: ## lint python sources with bandit
@echo "lint:bandit started…"
@$(COMPOSE_RUN_FONZIE) bandit -qr fonzie
.PHONY: lint-bandit
lint-pycodestyle: ## lint python sources with pycodestyle
@echo "lint:pycodestyle started…"
$(COMPOSE_RUN_FONZIE) pycodestyle fonzie tests
.PHONY: lint-pycodestyle
lint-pydocstyle: ## lint python sources with pydocstyle
@echo "lint:pydocstyle started…"
$(COMPOSE_RUN_FONZIE) pydocstyle fonzie tests
.PHONY: lint-pydocstyle
lint-isort: ## lint python sources with isort
@echo "lint:isort started…"
$(COMPOSE_RUN_FONZIE) isort --check-only --recursive tests fonzie manage.py setup.py
.PHONY: lint-isort
lint-pyroma: ## lint python sources with pyroma
@echo "lint:pyroma started…"
$(COMPOSE_RUN_FONZIE) pyroma .
.PHONY: lint-pyroma
report: ## publish test coverage report
$(COMPOSE_RUN) -e CODECOV_TOKEN lms codecov --commit=${CIRCLE_SHA1}
.PHONY: report
run: tree ## start lms development server and nginx
$(COMPOSE) up -d nginx
.PHONY: run
selfcheck: ## check that the Makefile is well-formed
@echo "The Makefile is well-formed."
.PHONY: selfcheck
stop: ## stop development server
$(COMPOSE) stop
.PHONY: stop
test: ## run python tests suite
# Create .pytest_cache directory with appropriate permissions. We cannot
# rely on docker-compose volume as if the directory does not exists, it will
# create one owned by root:root.
@mkdir -p .pytest_cache
$(PYTEST)
.PHONY: test
test-spec: ## run tests on API specification (API blueprint)
$(COMPOSE_RUN) dredd
.PHONY: test-spec
validate: lint test ## run tests and linters
.PHONY: validate
demo-course: ## import demo course from edX repository
@./bin/clone_demo_course
$(COMPOSE_RUN) -v $(shell pwd)/edx-demo-course:/edx/app/edxapp/edx-demo-course cms \
python manage.py cms import /data /edx/app/edxapp/edx-demo-course
.PHONY: demo-course
tree: ## create data directories mounted as volumes
bash -c "mkdir -p data/{static,media,export}"
.PHONY: tree
collectstatic: tree ## copy static assets to static root directory
$(COMPOSE_RUN) lms python manage.py lms collectstatic --noinput --settings=fun.docker_run_development;
$(COMPOSE_RUN) cms python manage.py cms collectstatic --noinput --settings=fun.docker_run_development;
.PHONY: collectstatic