-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJustfile
301 lines (261 loc) · 9.54 KB
/
Justfile
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# Copyright 2024
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PYTHON_DIR := invocation_directory() + '/' + if os_family() == 'windows' { 'venv/Scripts' } else { 'venv/bin' }
PYTHON := PYTHON_DIR + if os_family() == 'windows' { '/python.exe' } else { '/python3' }
TOOL_CLI_LRELEASE := PYTHON_DIR + '/pyside6-lrelease'
TOOL_CLI_LUPDATE := PYTHON_DIR + '/pyside6-lupdate'
TOOL_CLI_RCC := PYTHON_DIR + '/pyside6-rcc'
TOOL_CLI_QML_LINTER := 'qmllint'
TOOL_CLI_QML_TESTRUNNER := 'qmltestrunner'
export QML_IMPORT_PATH := DIRECTORY_QML_TESTS
export QT_QPA_PLATFORM := 'offscreen'
export QT_QUICK_CONTROLS_MATERIAL_VARIANT := 'Dense'
export QT_QUICK_CONTROLS_STYLE := 'Material'
##### #####
##### Names #####
##### #####
NAME_DIRECTORY_BUILD := 'build'
NAME_DIRECTORY_BUILD_HELPERS := 'build-aux'
NAME_DIRECTORY_PY_SOURCES := 'mpvqc'
NAME_DIRECTORY_PY_TESTS := 'test'
NAME_FILE_GENERATED_RESOURCES := 'generated_resources.py'
NAME_FILE_MAIN_ENTRY := 'main.py'
##### #####
##### Existing Directories #####
##### #####
DIRECTORY_ROOT := invocation_directory()
DIRECTORY_BUILD_HELPERS := DIRECTORY_ROOT + '/' + NAME_DIRECTORY_BUILD_HELPERS
DIRECTORY_DATA := DIRECTORY_ROOT + '/data'
DIRECTORY_I18N := DIRECTORY_ROOT + '/i18n'
DIRECTORY_PY_SOURCES := DIRECTORY_ROOT + '/' + NAME_DIRECTORY_PY_SOURCES
DIRECTORY_PY_TESTS := DIRECTORY_ROOT + '/' + NAME_DIRECTORY_PY_TESTS
DIRECTORY_QML_SOURCES := DIRECTORY_ROOT + '/qml'
DIRECTORY_QML_TESTS := DIRECTORY_ROOT + '/qml'
##### #####
##### Existing Files #####
##### #####
FILE_APP_ENTRY := DIRECTORY_ROOT + '/' + NAME_FILE_MAIN_ENTRY
##### #####
##### Generated Directories #####
##### #####
DIRECTORY_BUILD := DIRECTORY_ROOT + '/' + NAME_DIRECTORY_BUILD
DIRECTORY_BUILD_PY := DIRECTORY_BUILD_RELEASE + '/' + NAME_DIRECTORY_PY_SOURCES
#
DIRECTORY_BUILD_QRC_DATA := DIRECTORY_BUILD + '/qrc-data'
DIRECTORY_BUILD_QRC_I18N := DIRECTORY_BUILD + '/qrc-i18n'
DIRECTORY_BUILD_QRC_QML := DIRECTORY_BUILD + '/qrc-qml'
DIRECTORY_BUILD_RELEASE := DIRECTORY_BUILD + '/release'
DIRECTORY_BUILD_RESOURCES := DIRECTORY_BUILD + '/resources'
DIRECTORY_BUILD_TRANSLATIONS := DIRECTORY_BUILD + '/translations'
##### #####
##### Generated Files #####
##### #####
FILE_BUILD_QRC_DATA := DIRECTORY_BUILD_QRC_DATA + '/data.qrc'
FILE_BUILD_QRC_I18N := DIRECTORY_BUILD_QRC_I18N + '/i18n.qrc'
FILE_BUILD_QRC_I18N_JSON := DIRECTORY_BUILD_QRC_I18N + '/myapp.json'
FILE_BUILD_QRC_QML := DIRECTORY_BUILD_QRC_QML + '/qml.qrc'
FILE_BUILD_RESOURCES := DIRECTORY_BUILD_RESOURCES + '/' + NAME_FILE_GENERATED_RESOURCES
FILE_BUILD_TRANSLATIONS_JSON := DIRECTORY_BUILD_TRANSLATIONS + '/myapp.json'
FILE_PY_SOURCES_RESOURCES := DIRECTORY_PY_SOURCES + '/' + NAME_FILE_GENERATED_RESOURCES
FILE_PY_TEST_RESOURCES := DIRECTORY_PY_TESTS + '/' + NAME_FILE_GENERATED_RESOURCES
_default:
@just --list
# Format code
format:
@{{ PYTHON }} -m ruff check --fix
@{{ PYTHON }} -m ruff format
# Install dependencies into the virtual environment
install-dependencies:
#!/usr/bin/env bash
if [[ -z "${VIRTUAL_ENV}" ]]; then
echo "Please activate virtual environment first"
exit 1
fi
python build-aux/generate-dependency-versions.py \
--pyproject-file pyproject.toml \
--optional-group dev \
extract | xargs pip install
# Build full project into build/release
[group('build')]
build: _check-pyside-setup _clean-build _clean-develop _compile-resources
@rm -rf \
{{ DIRECTORY_BUILD_PY }}
@mkdir -p \
{{ DIRECTORY_BUILD_PY }}
@cp -r \
{{ DIRECTORY_PY_SOURCES }}/. \
{{ DIRECTORY_BUILD_PY }}
@cp \
{{ FILE_BUILD_RESOURCES }} \
{{ DIRECTORY_BUILD_PY }}
@cp \
{{ FILE_APP_ENTRY }} \
{{ DIRECTORY_BUILD_RELEASE }}
@echo ''; \
echo 'Please find the finished project in {{ DIRECTORY_BUILD_RELEASE }}'
# Build and compile resources into source directory
[group('build')]
build-develop: _check-pyside-setup _clean-develop _compile-resources
@# Generates resources and copies them into the source directory
@# This allows to develop/debug the project normally
@cp \
{{ FILE_BUILD_RESOURCES }} {{ DIRECTORY_PY_SOURCES }}
# Remove ALL generated files
[group('build')]
clean: _clean-build _clean-develop _clean-test
# Add new language
[group('i18n')]
add-translation locale: _check-pyside-setup _prepare-translation-extractions
@cd {{ DIRECTORY_BUILD_TRANSLATIONS }}; \
{{ TOOL_CLI_LUPDATE }} \
-verbose \
-source-language en_US \
-target-language {{ locale }} \
-ts {{ DIRECTORY_I18N }}/{{ locale }}.ts
@echo ''
@just update-translations
# Update *.ts files by traversing the source code
[group('i18n')]
update-translations: _check-pyside-setup _clean-develop _prepare-translation-extractions
@# Traverses *.qml and *.py files to update translation files
@# Requires translations in .py: QCoreApplication.translate("context", "string")
@# Requires translations in .qml: qsTranslate("context", "string")
@cd {{ DIRECTORY_BUILD_TRANSLATIONS }}; \
{{ TOOL_CLI_LUPDATE }} \
-locations none \
-project {{ FILE_BUILD_TRANSLATIONS_JSON }}
@cp -r \
{{ DIRECTORY_BUILD_TRANSLATIONS }}/i18n/*.ts \
{{ DIRECTORY_I18N }}
# Lint Python files
[group('lint')]
lint-python:
@{{ PYTHON }} -m ruff check
# Lint QML files
[group('lint')]
lint-qml: _check-qml-setup
@find {{ DIRECTORY_QML_TESTS }} -type f -name '*.qml' -exec {{ TOOL_CLI_QML_LINTER }} -I {{ DIRECTORY_QML_TESTS }} {} \;
# Run Python and QML tests
[group('test')]
test: test-python test-qml
# Run Python tests
[group('test')]
test-python: _check-pyside-setup _clean-test _compile-resources
@cp \
{{ FILE_BUILD_RESOURCES }} \
{{ FILE_PY_TEST_RESOURCES }}
@{{ PYTHON }} -m pytest test
# Run QML tests
[group('test')]
test-qml: _check-qml-setup
{{ TOOL_CLI_QML_TESTRUNNER }} \
-silent \
-input {{ DIRECTORY_QML_TESTS }}
_clean-build:
@rm -rf \
{{ DIRECTORY_BUILD }}
_clean-develop:
@rm -rf \
{{ FILE_PY_SOURCES_RESOURCES }}
_clean-test:
@rm -rf \
{{ FILE_PY_TEST_RESOURCES }}
_check-pyside-setup:
@which {{ PYTHON }}
@which {{ TOOL_CLI_LUPDATE }}
@which {{ TOOL_CLI_LRELEASE }}
@which {{ TOOL_CLI_RCC }}
@echo ''
_check-qml-setup:
@which {{ TOOL_CLI_QML_TESTRUNNER }}
@echo ''
_compile-resources: _generate-qrc-data _generate-qrc-i18n _generate-qrc-qml
@rm -rf \
{{ DIRECTORY_BUILD_RESOURCES }}
@mkdir -p \
{{ DIRECTORY_BUILD_RESOURCES }}
@cp -r \
{{ DIRECTORY_BUILD_QRC_QML }}/. \
{{ DIRECTORY_BUILD_QRC_DATA }}/. \
{{ DIRECTORY_BUILD_QRC_I18N }}/. \
{{ DIRECTORY_BUILD_RESOURCES }}
@{{ TOOL_CLI_RCC }} \
{{ DIRECTORY_BUILD_RESOURCES }}/data.qrc \
{{ DIRECTORY_BUILD_RESOURCES }}/i18n.qrc \
{{ DIRECTORY_BUILD_RESOURCES }}/qml.qrc \
-o {{ FILE_BUILD_RESOURCES }}
_generate-qrc-data:
@rm -rf \
{{ DIRECTORY_BUILD_QRC_DATA }}
@mkdir -p \
{{ DIRECTORY_BUILD_QRC_DATA }}
@cp -r \
{{ DIRECTORY_DATA }} \
{{ DIRECTORY_BUILD_QRC_DATA }}
@cd \
{{ DIRECTORY_BUILD_QRC_DATA }}/data; \
{{ TOOL_CLI_RCC }} \
--project | sed 's,<file>./,<file>data/,' > {{ FILE_BUILD_QRC_DATA }}
_generate-qrc-i18n:
@rm -rf \
{{ DIRECTORY_BUILD_QRC_I18N }}
@mkdir -p \
{{ DIRECTORY_BUILD_QRC_I18N }}
@cp -r \
{{ DIRECTORY_I18N }} {{ DIRECTORY_BUILD_QRC_I18N }}
@{{ DIRECTORY_BUILD_HELPERS }}/generate-lupdate-project-file.py \
--relative-to {{ DIRECTORY_BUILD_QRC_I18N }} \
--out-file {{ FILE_BUILD_QRC_I18N_JSON }}
@cd \
{{ DIRECTORY_BUILD_QRC_I18N }}; \
{{ TOOL_CLI_LRELEASE }} \
-project {{ FILE_BUILD_QRC_I18N_JSON }}
@cd \
{{ DIRECTORY_BUILD_QRC_I18N }}/i18n; \
rm \
{{ FILE_BUILD_QRC_I18N_JSON }} \
*.ts
@cd \
{{ DIRECTORY_BUILD_QRC_I18N }}/i18n; \
{{ TOOL_CLI_RCC }} \
--project | sed 's,<file>./,<file>i18n/,' > {{ FILE_BUILD_QRC_I18N }}
_generate-qrc-qml:
@rm -rf \
{{ DIRECTORY_BUILD_QRC_QML }}
@mkdir -p \
{{ DIRECTORY_BUILD_QRC_QML }}
@cp -r \
{{ DIRECTORY_QML_SOURCES }} \
{{ DIRECTORY_BUILD_QRC_QML }}
@cd {{ DIRECTORY_BUILD_QRC_QML }}; \
mkdir qt && mv qml qt
@cd \
{{ DIRECTORY_BUILD_QRC_QML }}; \
{{ TOOL_CLI_RCC }} --project \
| sed 's,<file>./,<file>,' \
| grep -v "<file>qml.qrc</file>" > {{ FILE_BUILD_QRC_QML }}
_prepare-translation-extractions:
@rm -rf \
{{ DIRECTORY_BUILD_TRANSLATIONS }}
@mkdir -p \
{{ DIRECTORY_BUILD_TRANSLATIONS }}
@cp -r \
{{ DIRECTORY_I18N }} \
{{ DIRECTORY_PY_SOURCES }} \
{{ DIRECTORY_QML_SOURCES }} \
{{ DIRECTORY_BUILD_TRANSLATIONS }}
@{{ DIRECTORY_BUILD_HELPERS }}/generate-lupdate-project-file.py \
--relative-to {{ DIRECTORY_BUILD_TRANSLATIONS }} \
--out-file {{ FILE_BUILD_TRANSLATIONS_JSON }}