forked from j10er/NodeKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.py
More file actions
executable file
·167 lines (144 loc) · 4.69 KB
/
dev.py
File metadata and controls
executable file
·167 lines (144 loc) · 4.69 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
#!/usr/bin/env python
import argparse
import logging
import os
import shutil
import subprocess
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
# Should match the addon name in blender_manifest.toml
ADDON_NAME = "NodeKit"
ADDON_ID = "nodekit"
def build():
_update_mock_module()
source_dir = f"./{ADDON_NAME}"
filename = ADDON_NAME
config_path = f"{source_dir}/config.py"
debug_line = "DEBUG = False"
with open(config_path, "a") as file:
file.write(f"{debug_line}")
build_version = "4.5.0"
log.info(f"Building addon: Using blender version {build_version} to build")
_setup_blender("./blender", build_version)
subprocess.run(
[
f"./blender/blender-{build_version}/blender",
"--command",
"extension",
"build",
"--source-dir",
source_dir,
"--output-filepath",
f"{filename}.zip",
]
)
with open(config_path, "r") as file:
lines = file.readlines()
with open(config_path, "w") as file:
for line in lines:
if line.strip() != debug_line.strip():
file.write(line)
def _run_tests(blender_executable):
# Install addon
subprocess.run(
[
blender_executable,
"--command",
"extension",
"install-file",
"-r",
"user_default",
"-e",
f"{ADDON_NAME}.zip",
]
)
# Run tests
result = subprocess.run(
[
blender_executable,
"--background",
"--python-exit-code",
"1",
"--python",
"run_tests.py",
]
)
if result.returncode != 0:
raise Exception("Tests failed")
log.info("Tests passed")
def _setup_blender(blender_path, version):
major_version = version[:3]
if not os.path.exists(blender_path):
os.makedirs(blender_path)
if not os.path.exists(f"{blender_path}/blender-{version}"):
log.info(f"Downloading Blender {version}.")
subprocess.run(
[
"wget",
"-nv",
f"https://download.blender.org/release/Blender{major_version}/blender-{version}-linux-x64.tar.xz",
]
)
shutil.unpack_archive(f"blender-{version}-linux-x64.tar.xz")
shutil.move(f"blender-{version}-linux-x64", f"{blender_path}/blender-{version}")
os.remove(f"blender-{version}-linux-x64.tar.xz")
os.mkdir(f"{blender_path}/blender-{version}/portable")
else:
log.info(
f"Blender {version} already downloaded. Resetting existing installation."
)
shutil.rmtree(f"{blender_path}/blender-{version}/portable")
os.mkdir(f"{blender_path}/blender-{version}/portable")
def _install_test_deps(blender_path, version):
major_version = version[:3]
python_dir = f"{blender_path}/blender-{version}/{major_version}/python/bin/"
python_executable = f"{python_dir}/{next(name for name in os.listdir(python_dir) if name.startswith('python3.'))}"
subprocess.run(
[python_executable, "-m", "pip", "install", "pytest", "deepdiff", "-q", "-q"]
)
def _update_mock_module() -> None:
"""
Copies the addon contents to the mock module directory for linting purposes.
"""
source_dir = f"./{ADDON_NAME}"
destination_dir = f"./bl_ext/user_default/{ADDON_ID}"
if os.path.exists(destination_dir):
shutil.rmtree(destination_dir)
shutil.copytree(source_dir, destination_dir)
with open("bl_ext/__init__.py", "w") as f:
pass
with open("bl_ext/user_default/__init__.py", "w") as f:
pass
print(f"Copied {source_dir} to {destination_dir} for linting.")
def test():
blender_versions = ["4.5.0"]
blender_path = "./blender"
for version in blender_versions:
_setup_blender(blender_path, version)
_install_test_deps(blender_path, version)
log.info(f"Running tests for Blender version {version}")
_run_tests(blender_executable=f"{blender_path}/blender-{version}/blender")
# COMMAND LINE INTERFACE
parser = argparse.ArgumentParser()
parser.add_argument(
"command",
choices=["build", "test", "release"],
help="""
TEST = build with test files and run tests
BUILD = Create the zip
""",
)
parser.add_argument(
"--skip-rebuild",
action=argparse.BooleanOptionalAction,
help="Do not rebuild the addon when running the tests, only viable when there are no changes in the addon code",
)
args = parser.parse_args()
if args.command == "build":
build()
elif args.command == "test":
if not args.skip_rebuild:
build()
test()
else:
parser.log.info_help()