-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJustfile
More file actions
247 lines (210 loc) · 7.78 KB
/
Justfile
File metadata and controls
247 lines (210 loc) · 7.78 KB
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
# SPDX-FileCopyrightText: mpvQC developers
#
# SPDX-License-Identifier: MIT
set dotenv-load := true
set lazy := true
GIT_TAG := `git describe --tags --abbrev=0`
GIT_COMMIT := `git rev-parse HEAD | head -c 8`
alias fmt := format
@_default:
just --list --unsorted
# Install dependencies and configure basic stuff
[group('dev')]
init ARGS='--group dev':
#!/usr/bin/env bash
uv sync {{ ARGS }}
if [[ "{{ ARGS }}" == "--group dev" ]]; then
QMLLS_INI=".qmlls.ini"
echo "[General]" > "$QMLLS_INI"
echo "DisableDefaultImports=false" >> "$QMLLS_INI"
echo "no-cmake-calls=true" >> "$QMLLS_INI"
echo "importPaths={{ justfile_directory() }}" >> "$QMLLS_INI"
echo "buildDir={{ justfile_directory() }}" >> "$QMLLS_INI"
echo "just init: Created $QMLLS_INI ..."
echo "Created by command: just init" > portable
echo "Runs application in portable mode by storing all files in the <git-repo>/appdata directory" >> portable
echo "just init: Configured portable mode ..."
mkdir -p appdata/export-templates
cp data/config/backup-template.jinja appdata/export-templates/export-working.jinja
echo '{{ '{{' }}' > appdata/export-templates/export-error.jinja
fi
[group('dev')]
format:
uv run prek --config .config/prek.toml run --all-files
[group('dev')]
update-python-dependencies:
uv sync --upgrade
just _update-dependency-versions
[group('dev')]
update-git-hook-dependencies:
uv run prek --config .config/prek.toml auto-update
# Stamp version info into data/build-info.toml
[group('build')]
set-build-info:
#!/usr/bin/env bash
set -euo pipefail
if git describe --exact-match HEAD 2>/dev/null; then
IS_RELEASE="true"
else
IS_RELEASE="false"
fi
if [ -n "${FLATPAK_ID:-}" ]; then
VERSION="{{ GIT_TAG }}-flatpak"
else
VERSION="{{ GIT_TAG }}"
fi
sed -i "1,13s/^version = .*/version = \"$VERSION\"/" data/build-info.toml
sed -i "1,13s/^commit = .*/commit = \"{{ GIT_COMMIT }}\"/" data/build-info.toml
sed -i "1,13s/^is_release = .*/is_release = $IS_RELEASE/" data/build-info.toml
cat data/build-info.toml
# Build full project into build/release
[group('build')]
@build: clean
just build-develop
mkdir -p build/release
cp -r mpvqc build/release
cp main.py build/release
cp rc_project.py build/release
# Build and compile resources into source directory
[group('build')]
@build-develop: _update_pyproject_file
uv run pyside6-project build
# Remove ALL generated files
[group('build')]
@clean:
find i18n -name "*.qm" -type f -delete
find qt/qml -name "*.qmlc" -type f -delete
rm -rf build pyobjects test/rc_project.py rc_project.py project.json project.qrc
# Build release artifact (⚠️ modifies working tree)
[group('ci')]
build-release:
#!/usr/bin/env bash
set -euo pipefail
function execute() { echo -e "\033[0;34m$*\033[0m"; "$@"; }
execute find . -type f -name 'tst_*' -delete
execute find . -type f -name 'TestHelpers.qml' -delete
execute export MPVQC_COMPILE_QML=true
execute export UV_NO_SYNC="1"
execute export UV_OFFLINE="1"
execute just set-build-info
execute just build
execute find build/release -type d -name "__pycache__" -print0 | xargs -0 rm -rf
# Run Python and QML tests
[group('test')]
@test: _prepare-tests (test-python 'no-prep') (test-qml 'no-prep')
[group('test')]
test-python SKIP_PREPARATION='false':
#!/usr/bin/env bash
if [[ "{{ SKIP_PREPARATION }}" == "false" ]] then
just _prepare-tests
fi
export QT_QPA_PLATFORM=offscreen
uv run pytest build-aux test
[group('test')]
test-qml SKIP_PREPARATION='false':
#!/usr/bin/env bash
if [[ "{{ SKIP_PREPARATION }}" == "false" ]] then
just _prepare-tests
fi
uv run python -c '
import sys
from PySide6.QtQuickTest import QUICK_TEST_MAIN_WITH_SETUP
from test.prepare_qml import MpvqcTestSetup
# Pass additional arguments to qmltestrunner:
sys.argv += ["-platform", "offscreen"]
sys.argv += ["-silent"]
sys.argv += ["-input", "qt/qml"]
# sys.argv += ["-eventdelay", "50"] # Simulate slower systems
ex = QUICK_TEST_MAIN_WITH_SETUP("qmltestrunner", MpvqcTestSetup, argv=sys.argv)
sys.exit(ex)
'
# Lint Python files (type checker only)
[group('lint')]
lint-python *ARGS:
uv run pyrefly check --config .config/pyrefly.toml {{ ARGS }}
# Lint QML files
[group('lint')]
@lint-qml: build-develop
uv run pyside6-project qmllint
# Add language 'LOCALE' e.g. 'fr-FR' (ISO 639-1, ISO 3166-1)
[group('i18n')]
@add-translation LOCALE: _update_pyproject_file
uv run pyside6-lupdate -source-language en-US -target-language {{ LOCALE }} -ts i18n/{{ LOCALE }}.ts
just update-translations
# Update translation strings
[group('i18n')]
@update-translations: _update_pyproject_file _update_lupdate_project_file
uv run pyside6-lupdate -locations none -project project.json
@_prepare-tests: build-develop
rm -f test/rc_project.py
cp rc_project.py test/rc_project.py
@_update_pyproject_file: _generate-qrc-file
uv run python build-aux/update_pyproject_file.py \
--relative-to . \
--include-directory qt/qml \
--include-directory data \
--include-directory mpvqc \
--include-directory i18n \
--include-file main.py \
--include-file project.qrc
_generate-qrc-file:
#!/usr/bin/env bash
if [[ "${MPVQC_COMPILE_QML}" == "true" ]]; then
echo "Compiling QML files to cache..."
find qt/qml -name "*.qml" -not -name "tst_*.qml" -type f | while read qml_file; do
qmlc_file="${qml_file}c"
echo " Compiling $(basename "$qml_file")..."
uv run pyside6-qmlcachegen --only-bytecode "$qml_file" -o "$qmlc_file" || exit 1
done
echo " Removing .aotstats files..."
find qt/qml -name "*.aotstats" -type f -delete
echo "QML compilation complete!"
else
echo "Skipping QML cache generation. Can be enabled by setting env var MPVQC_COMPILE_QML=true"
fi
uv run python build-aux/generate-qrc-file.py \
--relative-to . \
--include-directory qt/qml \
--include-directory data \
--include-directory i18n \
--out-file project.qrc
@_update_lupdate_project_file:
uv run python build-aux/generate-lupdate-project-file.py \
--relative-to . \
--include-directory qt/qml \
--include-directory mpvqc \
--include-directory i18n \
--include-file main.py \
--include-file project.qrc \
--out-file project.json
# Update dependency versions in build-info.toml
_update-dependency-versions:
#!/usr/bin/env bash
uv --offline export --no-hashes --no-annotate | uv run python -c '
import re, sys, tomllib
from pathlib import Path
# Parse versions from stdin
versions = {}
for line in sys.stdin:
line = line.strip()
if line and not line.startswith("#"):
package_spec = line.split(";")[0].strip()
if "==" in package_spec:
package, version = package_spec.split("==", 1)
versions[package.lower()] = version
# Update build-info.toml
toml_path = Path() / "data" / "build-info.toml"
content = toml_path.read_text()
with toml_path.open("rb") as f:
data = tomllib.load(f)
for dep_list in ["dependency", "dev_dependency"]:
for dep in data[dep_list]:
package_key = dep["package"].lower()
if package_key in versions:
v = versions[package_key]
name_escaped = re.escape(dep["name"])
pattern = "(name = \"" + name_escaped + "\".*?version = )\"[^\"]*\""
replacement = r"\1" + "\"" + v + "\""
content = re.sub(pattern, replacement, content, flags=re.DOTALL)
toml_path.write_text(content)
'