-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnoxfile.py
115 lines (106 loc) · 3.7 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
import os
import sys
import nox
nox.options.sessions = ["format", "lint"]
file_list = ("main.py", "noxfile.py")
@nox.session
def format(session):
"Run formatters, to keep the order."
# Install requirements
session.install("-r", "requirements.txt")
session.install("-r", "requirements-lint.txt")
# Run formatters
session.run("isort", *file_list)
session.run("black", *file_list)
@nox.session
def lint(session):
"Run linters to see if everything's civilized."
# Install requirements
session.install("-r", "requirements.txt")
session.install("-r", "requirements-lint.txt")
# Run linters
session.run("flake8", *file_list, "--max-line-length=127", "--ignore=F841")
session.run("isort", "--check-only", *file_list)
session.run("black", "--check", *file_list)
@nox.session
def package(session):
"Build and package everything up."
# First of all, install the requirements
session.install("-r", "requirements.txt")
# 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 not input(
"The destination directory ('./dist') already exists. Do you want to remove it? (y/n) "
).strip().lower() 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'); "
"shutil.copy('resource.pyxres', './dist/resource.pyxres')",
)
session.run(
"python",
"-m",
"zipfile",
"-c",
"./dist/source.zip",
"./dist/main.py",
"./dist/resource.pyxres",
)
# 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",
)
# If Windows, create the cx_Freeze executable
if sys.platform == "win32":
session.warn("Running in Windows, generating the cx_Freeze executable...")
session.install("cx_Freeze")
session.run("python", "setup.py", "build")
session.run(
"python",
"-c",
"import os, shutil; exe_path = os.listdir('./build')[0]; "
"shutil.copy2('resource.pyxres', f'./build/{exe_path}/resource.pyxres')",
)
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/resource.pyxres'); "
"os.remove('./dist/pyxel_dist.pyxapp')",
)
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'.")