-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
159 lines (119 loc) · 4.14 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
# Copyright (C) 2020-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/)
#
# This is free software, licensed under the GNU General Public License v3.
# See /LICENSE for more information.
PROJECT="reForis Diagnostics"
# Retrieve version from pyproject.toml
VERSION= $(shell sed -En "s/.*version = ['\"](.+)['\"].*/\1/p" pyproject.toml)
COPYRIGHT_HOLDER="CZ.NIC, z.s.p.o. (https://www.nic.cz/)"
MSGID_BUGS_ADDRESS="[email protected]"
VENV_NAME?=venv
VENV_BIN=$(shell pwd)/$(VENV_NAME)/bin
PYTHON=python3
PIP_EXTRA_INDEX_URL=https://gitlab.nic.cz/api/v4/projects/1066/packages/pypi/simple
JS_DIR=./js
LANGS = cs da de el en fi fo fr hr hu it ja ko lt nb_NO nl pl ro ru sk sv
.PHONY: all
all:
@echo "make prepare-dev"
@echo " Create python virtual environment and install dependencies."
@echo "make install"
@echo " Install package in your system (for running on router)."
@echo "make watch-js"
@echo " Compile JS in watch mode."
@echo "make build-js"
@echo " Compile JS."
@echo "make lint"
@echo " Run lint on project."
@echo "make test"
@echo " Run tests on project."
@echo "make create-messages"
@echo " Create locale messages (.pot)."
@echo "make update-messages"
@echo " Update locale messages from .pot file."
@echo "make compile-messages"
@echo " Compile locale messager."
@echo "make clean"
@echo " Remove python artifacts and virtualenv."
# Preparation
.PHONY: prepare-dev
prepare-dev:
which npm || curl -sL https://deb.nodesource.com/setup_21.x | sudo -E bash -
which npm || sudo apt-get install -y nodejs
cd $(JS_DIR); npm install
which $(PYTHON) || sudo apt-get install -y $(PYTHON) $(PYTHON)-pip
which virtualenv || sudo $(PYTHON) -m pip install virtualenv
make venv
.PHONY: venv
venv: $(VENV_NAME)/bin/activate
$(VENV_NAME)/bin/activate: pyproject.toml
test -d $(VENV_NAME) || $(PYTHON) -m virtualenv -p $(PYTHON) $(VENV_NAME)
# upgrade pip to latest releases
$(VENV_BIN)/$(PYTHON) -m pip install --upgrade pip
$(VENV_BIN)/$(PYTHON) -m pip install --index-url $(PIP_EXTRA_INDEX_URL) -e .[devel]
touch $(VENV_NAME)/bin/activate
# Installation
.PHONY: install
install:
opkg update
opkg install foris-controller-diagnostics-module
REFORIS_NO_JS_BUILD=1 $(PYTHON) -m pip install --index-url $(PIP_EXTRA_INDEX_URL) -e .
ln -sf /tmp/reforis-diagnostics/reforis_static/reforis_diagnostics /tmp/reforis/reforis_static/
/etc/init.d/lighttpd restart
.PHONY: install-js
install-js: js/package.json
cd $(JS_DIR); npm install --save-dev
.PHONY: install-local-reforis
install-local-reforis:
$(VENV_BIN)/$(PYTHON) -m pip install -e ../reforis
# JavaScript
.PHONY: build-js
build-js:
cd $(JS_DIR); npm run-script build
.PHONY: watch-js
watch-js:
cd $(JS_DIR); npm run-script watch
# Linting
.PHONY: lint
lint: lint-js lint-web
.PHONY: lint-js
lint-js:
cd $(JS_DIR); npm run lint
.PHONY: lint-js-fix
lint-js-fix:
cd $(JS_DIR); npm run lint:fix
.PHONY: lint-web
lint-web: venv
$(VENV_BIN)/$(PYTHON) -m ruff check reforis_diagnostics
# Testing
.PHONY: test
test: test-js test-web
.PHONY: test-js
test-js:
cd $(JS_DIR); npm test
.PHONY: test-js-watch
test-js-watch:
cd $(JS_DIR); npm test -- --watch
.PHONY: test-js-update-snapshots
test-js-update-snapshots:
cd $(JS_DIR); npm test -- -u
.PHONY: test-web
test-web: venv
$(VENV_BIN)/$(PYTHON) -m pytest -vv tests
# Translations
.PHONY: create-messages
create-messages: venv
$(VENV_BIN)/pybabel extract -F babel.cfg -o ./reforis_diagnostics/translations/messages.pot . --project=$(PROJECT) --version=$(VERSION) --copyright-holder=$(COPYRIGHT_HOLDER) --msgid-bugs-address=$(MSGID_BUGS_ADDRESS)
.PHONY: update-messages
update-messages: venv
$(VENV_BIN)/pybabel update -i ./reforis_diagnostics/translations/messages.pot -d ./reforis_diagnostics/translations --update-header-comment
.PHONY: compile-messages
compile-messages: venv install-js
$(VENV_BIN)/pybabel compile -f -d ./reforis_diagnostics/translations
# Other
.PHONY: clean
clean:
find . -name '*.pyc' -exec rm -f {} +
rm -rf $(VENV_NAME) *.eggs *.egg-info dist build docs/_build .cache
rm -rf $(JS_DIR)/node_modules/ reforis_static/reforis_diagnostics/js/app.min.js
$(PYTHON) -m pip uninstall -y reforis_diagnostics