-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
noxfile.py
126 lines (111 loc) · 3.17 KB
/
noxfile.py
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
import pathlib
import nox
PYTHON_FILES = [
"yoga_image_optimizer",
"setup.py",
"noxfile.py",
"winbuild/yoga-image-optimizer.py",
]
@nox.session(reuse_venv=True)
def lint(session):
session.install("flake8", "black")
session.run("flake8", *PYTHON_FILES)
session.run("black", "--check", "--diff", "--color", *PYTHON_FILES)
@nox.session(reuse_venv=True)
def black_fix(session):
session.install("black")
session.run("black", *PYTHON_FILES)
# NOTE All Gtk dependencies and introspection files must be installed for this
# to work.
@nox.session(python=["3.9", "3.10", "3.11", "3.12", "3.13"], reuse_venv=True)
def test(session):
session.install("pytest")
session.install("-e", ".")
session.run(
"pytest",
"--doctest-modules",
"yoga_image_optimizer",
env={"LANG": "C"}, # Force using the default strings
)
@nox.session
def locales_update(session):
# Extract messages in .pot
python_files = [
p.as_posix() for p in pathlib.Path("yoga_image_optimizer/").glob("**/*.py")
]
ui_files = [
p.as_posix()
for p in pathlib.Path("yoga_image_optimizer/data/ui").glob("*.glade")
]
session.run(
"xgettext",
"--from-code=UTF-8",
"-o",
"locales/messages.pot",
*ui_files,
*python_files,
external=True,
)
# Updates locales
for po_file in pathlib.Path("locales").glob("*.po"):
session.run(
"msgmerge",
"--update",
"--no-fuzzy-matching",
po_file.as_posix(),
"locales/messages.pot",
external=True,
)
@nox.session
def locales_compile(session):
LOCAL_DIR = pathlib.Path("yoga_image_optimizer/data/locales")
for po_file in pathlib.Path("locales").glob("*.po"):
output_file = (
LOCAL_DIR
/ po_file.name[: -len(po_file.suffix)]
/ "LC_MESSAGES"
/ "org.flozz.yoga-image-optimizer.mo"
)
print(output_file.as_posix())
output_file.parent.mkdir(parents=True, exist_ok=True)
session.run(
"msgfmt",
po_file.as_posix(),
"-o",
output_file.as_posix(),
external=True,
)
# Requires inkscape and icoutils
@nox.session(reuse_venv=True)
def gen_icons(session):
session.install("yoga")
icons = []
for size in [32, 64, 128, 256]:
output_icon = "./yoga_image_optimizer/data/images/icon_%i.png" % size
session.run(
"inkscape",
"--export-area-page",
"--export-filename=%s" % output_icon,
"--export-width=%i" % size,
"--export-height=%i" % size,
"./yoga_image_optimizer/data/images/icon.svg",
external=True,
)
session.run(
"python",
"-m",
"yoga",
"image",
"--png-slow-optimization",
output_icon,
output_icon,
external=True,
)
icons.append(output_icon)
session.run(
"icotool",
"--create",
"--output=winbuild/icon.ico",
*icons,
external=True,
)