This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Makefile
185 lines (135 loc) · 7.54 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
.DEFAULT_GOAL := test
TOX=''
.PHONY: help clean static upgrade piptools requirements production-requirements \
prod-requirements devstack-requirements local-requirements run-local \
dbshell-local shell coverage test quality pii_check validate migrate \
createsuperuser html_coverage extract_translations dummy_translations \
fake_translations pull_translations push_translations \
detect_changed_source_translations validate_translations api_generated \
validate_api_committed install_transifex_client
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"
ifdef TOXENV
TOX := tox -- #to isolate each tox environment if TOXENV is defined
endif
# Generates a help message. Borrowed from https://github.com/pydanny/cookiecutter-djangopackage.
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}'
clean: ## delete generated byte code and coverage reports
find . -name '*.pyc' -delete
find . -name '__pycache__' -type d -exec rm -rf {} ';' || true
coverage erase
rm -rf assets
rm -rf pii_report
full_clean: clean ## clean byte code, reports, and uploaded media
rm -rf registrar/media
static: ## generate static files
$(TOX)python manage.py collectstatic --noinput
define COMMON_CONSTRAINTS_TEMP_COMMENT
# This is a temporary solution to override the real common_constraints.txt\n# In edx-lint, until the pyjwt constraint in edx-lint has been removed.\n# See BOM-2721 for more details.\n# Below is the copied and edited version of common_constraints\n
endef
COMMON_CONSTRAINTS_TXT=requirements/common_constraints.txt
.PHONY: $(COMMON_CONSTRAINTS_TXT)
$(COMMON_CONSTRAINTS_TXT):
wget -O "$(@)" https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt || touch "$(@)"
echo "$(COMMON_CONSTRAINTS_TEMP_COMMENT)" | cat - $(@) > temp && mv temp $(@)
upgrade: export CUSTOM_COMPILE_COMMAND=make upgrade
upgrade: piptools $(COMMON_CONSTRAINTS_TXT) ## re-compile requirements .txt files from .in files
sed 's/django-simple-history==3.0.0//g' requirements/common_constraints.txt > requirements/common_constraints.tmp
mv requirements/common_constraints.tmp requirements/common_constraints.txt
pip-compile --allow-unsafe --rebuild --upgrade -o requirements/pip.txt requirements/pip.in
pip-compile --upgrade -o requirements/pip-tools.txt requirements/pip-tools.in
pip install -qr requirements/pip.txt
pip install -qr requirements/pip-tools.txt
pip-compile --upgrade -o requirements/github.txt requirements/github.in
pip-compile --upgrade -o requirements/optional.txt requirements/optional.in
pip-compile --upgrade -o requirements/base.txt requirements/base.in
pip-compile --upgrade -o requirements/docs.txt requirements/docs.in
pip-compile --upgrade -o requirements/test.txt requirements/test.in
pip-compile --upgrade -o requirements/local.txt requirements/local.in
pip-compile --upgrade -o requirements/nonlocal.txt requirements/nonlocal.in
pip-compile --upgrade -o requirements/production.txt requirements/production.in
pip-compile --upgrade -o requirements/devstack.txt requirements/devstack.in
pip-compile --upgrade -o requirements/monitoring/requirements.txt requirements/monitoring/requirements.in
# Let tox control the Django version for tests
grep -e "^django==" requirements/production.txt > requirements/django.txt
sed '/^[dD]jango==/d' requirements/test.txt > requirements/test.tmp
mv requirements/test.tmp requirements/test.txt
piptools:
pip install -r requirements/pip-tools.txt
requirements: devstack-requirements ## alias to make devstack-requirements
production-requirements: piptools ## install requirements for production
pip-sync -q requirements/production.txt
prod-requirements: production-requirements ## synonymous to 'production-requirements'
devstack-requirements: piptools ## install requirements for devstack development
pip-sync requirements/devstack.txt
local-requirements: piptools ## install requirements for local development
pip-sync -q requirements/local.txt
run-local: ## Run local (non-devstack) development server on port 8000
python manage.py runserver 0.0.0.0:8000 --settings=registrar.settings.local
dbshell-local: ## Run local (non-devstack) database shell
python manage.py dbshell --settings=registrar.settings.local
shell: ## Run Python shell with devstack settings
python manage.py shell
coverage: clean
$(TOX)pytest --cov-report html
test: clean ## run tests and generate coverage report
$(TOX)pytest
quality: pycodestyle pylint yamllint isort_check ## run all code quality checks
pycodestyle: # run pycodestyle
$(TOX)pycodestyle registrar/ scripts/
pylint: # run pylint
$(TOX)pylint --rcfile=pylintrc registrar scripts
yamllint: # run yamlint
$(TOX)yamllint *.yaml
isort_check: ## check that isort has been run
$(TOX)isort --check-only -rc registrar/ scripts/
isort: ## run isort to sort imports in all Python files
$(TOX)isort --recursive --atomic registrar scripts
pii_check: ## check for PII annotations on all Django models
DJANGO_SETTINGS_MODULE=registrar.settings.test \
$(TOX)code_annotations django_find_annotations --config_file .pii_annotations.yml --lint --report --coverage
validate: coverage quality pii_check validate_api_committed ## run all tests and quality checks
migrate: ## apply database migrations
python manage.py migrate
createsuperuser: ## create a super user with username and password 'edx'
echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser(\"edx\", \"[email protected]\",\"edx\") if not User.objects.filter(username=\"edx\").exists() else None" | python manage.py shell
html_coverage: coverage ## generate and view HTML coverage report
$(BROWSER) htmlcov/index.html
extract_translations: ## extract strings to be translated, outputting .mo files
$(TOX)python manage.py makemessages -l en -v1 -d django
$(TOX)python manage.py makemessages -l en -v1 -d djangojs
dummy_translations: ## generate dummy translation (.po) files
cd registrar && i18n_tool dummy
compile_translations:
$(TOX)python manage.py compilemessages
fake_translations: extract_translations dummy_translations compile_translations ## generate and compile dummy translation files
pull_translations: ## pull translations from Transifex
tx pull -t -a -f --mode reviewed
push_translations: ## push source translation files (.po) from Transifex
tx push -s
detect_changed_source_translations: ## check if translation files are up-to-date
cd registrar && i18n_tool changed
validate_translations: fake_translations detect_changed_source_translations ## install fake translations and check if translation files are up-to-date
# Docker commands
docker_build:
docker build . --target app -t "openedx/registrar:latest"
docker_auth:
echo "$$DOCKERHUB_PASSWORD" | docker login -u "$$DOCKERHUB_USERNAME" --password-stdin
docker_tag: docker_build
docker build . --target app -t "openedx/registrar:${GITHUB_SHA}"
docker_push: docker_tag docker_auth ## push to docker hub
docker push "openedx/registrar:latest"
docker push "openedx/registrar:${GITHUB_SHA}"
install_transifex_client: ## Install the Transifex client
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash
git checkout -- LICENSE README.md