-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_plugin.py
52 lines (43 loc) · 1.32 KB
/
build_plugin.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
import sys
import tempfile
import zipfile
from pathlib import Path
def main(archive_name: str):
files = [
Path(fp)
for fp in (
"SettingsTemplate.yaml",
"plugin.json",
"main.py",
)
]
ignore_exts = (".dist-info", ".pyc", "__pycache__")
plugin_include_exts = ("py", "html", "css", "js")
files.extend(Path("assets").iterdir())
plugin_dir = Path("plugin")
for ext in plugin_include_exts:
files.extend(plugin_dir.rglob(f"*.{ext}"))
lib_dir = Path("lib")
files.extend(
[
file
for file in lib_dir.rglob("*")
if not file.parent.parent.name.endswith(
ignore_exts # some deps include a licenses dir inside of their dist-info dir
)
and not file.parent.name.endswith(ignore_exts)
and not file.name.endswith(ignore_exts)
]
)
if archive_name == "--debug":
manager = tempfile.TemporaryFile("w") # noqa: SIM115
archive_name = manager.name
else:
manager = zipfile.ZipFile(archive_name, "w")
with manager as f:
for file in files:
f.write(str(file))
print(f"Added {file}")
print(f"\nDone. Archive saved to {archive_name}")
if __name__ == "__main__":
main(sys.argv[-1])