-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnoxfile.py
138 lines (128 loc) · 4.45 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
127
128
129
130
131
132
133
134
135
136
137
138
"""
I use Nox here to reformat the code, check
the code quality, and build the zipped distributions.
"""
import glob
import os
import sys
import nox
nox.options.sessions = ["format", "lint"]
files = ["noxfile.py", "main.py", "setup.py"]
@nox.session
def format(session):
"Run formatters."
session.install("-r", "test-requirements.txt")
session.run("ruff", "check", *files, "--fix")
@nox.session
def lint(session):
"Check the style and quality."
session.install("-r", "test-requirements.txt")
session.run("ruff", "check", *files)
@nox.session
def package(session):
"Build and package everything up."
# First of all, install the requirements
session.install("-r", "requirements.txt")
# Find all the resource files (using the skin packs spec from 'main.py')
res_files = glob.glob("resource_*.pyxres")
# Look for the 'dist' path, that will store everything
session.warn("Looking for the destination path...")
dist_generation = "import os; os.mkdir('./dist')"
if os.path.exists("./dist"):
if input(
"The destination directory ('./dist') already exists. Do you want to remove it? (y/n) "
).strip().lower() not in ("y", "yes"):
session.warn("Aborting...")
quit()
dist_generation = (
"import os, shutil; shutil.rmtree('./dist'); os.mkdir('./dist')"
)
session.run("python", "-c", dist_generation)
# Zip the source code
session.warn("Generating the source code distribution...")
session.run(
"python",
"-c",
"import os, shutil; shutil.copy('main.py', './dist/main.py'); ",
)
for i in res_files:
session.run(
"python",
"-c",
f"import os, shutil; shutil.copy('{i}', './dist/{i}')",
)
zfiles = ["./dist/source.zip", "./dist/main.py"] + [
f"./dist/{i}" for i in res_files
]
session.run(
"python",
"-m",
"zipfile",
"-c",
*zfiles,
)
# Generate and zip the Pyxel executable
session.warn("Generating the Pyxel executable...")
session.cd("dist")
session.run("pyxel", "package", ".", "main.py")
session.cd("..")
session.run(
"python",
"-c",
"import os; os.rename('./dist/dist.pyxapp', './dist/pyxel_dist.pyxapp')",
)
session.run(
"python",
"-m",
"zipfile",
"-c",
"./dist/pyxel_dist.zip",
"./dist/pyxel_dist.pyxapp",
)
# Generate an HTML using Pyxel's provided strategy
session.warn("Generating the HTML file...")
session.cd("dist")
session.run("pyxel", "app2html", "pyxel_dist.pyxapp")
session.run(
"python", "-c", "import os; os.rename('./pyxel_dist.html', './html_dist.html')"
)
session.run("python", "-m", "zipfile", "-c", "./html_dist.zip", "./html_dist.html")
session.cd("..")
# If Windows, create the cx_Freeze executable
if sys.platform == "win32":
session.warn("Running in Windows, generating the cx_Freeze executable...")
session.install("-r", "requirements-win32.txt")
session.run("python", "setup.py", "build")
for i in res_files:
session.run(
"python",
"-c",
"import os, shutil; exe_path = os.listdir('./build')[0]; "
f"shutil.copy2('{i}', "
"f'./build/{exe_path}/"
f"{i}')",
)
session.run("python", "-m", "zipfile", "-c", "./dist/windows.zip", "./build")
else:
# It's polite to notify when a step is ignored... well, that's what I think.
session.warn(
"Not running in Windows, ignoring the cx_Freeze executable build..."
)
# Before closing, it's cleanup time!
session.warn("Cleaning up the excedents...")
session.run(
"python",
"-c",
"import os; os.remove('./dist/main.py'); "
"os.remove('./dist/pyxel_dist.pyxapp'); os.remove('./dist/html_dist.html')",
)
for i in res_files:
session.run(
"python",
"-c",
f"import os; os.remove('./dist/{i}')",
)
if os.path.exists("./build"):
session.run("python", "-c", "import shutil; shutil.rmtree('./build')")
# Send a success message
session.warn("All done! The contents are ready at './dist'.")