-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
72 lines (63 loc) · 2.03 KB
/
install.py
File metadata and controls
72 lines (63 loc) · 2.03 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
import platform
import os
import tomllib
from shutil import copyfile, copytree, ignore_patterns, copy, rmtree
# source: https://github.com/typst/packages#local-packages
def determine_data_dir() -> str:
if platform.system().lower() == "linux":
return os.path.join(os.environ["HOME"], ".local", "share")
elif platform.system().lower() == "windows":
return os.path.join(os.environ["APPDATA"])
elif platform.system().lower() == "darwin":
return os.path.join(os.environ["HOME"], "Library", "Application Support")
else:
raise NotImplementedError("Unknown platform")
def copy_files(source_dir: str, target_dir: str) -> None:
rmtree(target_dir, ignore_errors=True)
ign = ignore_patterns("*.pyc", "__pycache__", "*.pdf")
# assets
os.makedirs(os.path.join(target_dir, "assets"))
copytree(
os.path.join(source_dir, "assets"),
os.path.join(target_dir, "assets"),
ignore=ign,
dirs_exist_ok=True,
)
# lib
os.makedirs(os.path.join(target_dir, "lib"))
copytree(
os.path.join(source_dir, "lib"),
os.path.join(target_dir, "lib"),
ignore=ign,
dirs_exist_ok=True,
)
# theme
os.makedirs(os.path.join(target_dir, "themes"))
copytree(
os.path.join(source_dir, "themes"),
os.path.join(target_dir, "themes"),
ignore=ign,
dirs_exist_ok=True,
)
# entrypoint
copy(
os.path.join(source_dir, "fau-typst.typ"),
target_dir,
)
# manifest
copy(os.path.join(source_dir, "typst.toml"), target_dir)
if __name__ == "__main__":
name = ""
version = ""
with open("typst.toml", "rb") as f:
toml = tomllib.load(f)
name = toml["package"]["name"]
version = toml["package"]["version"]
# copy files
target_dir = os.path.join(determine_data_dir(), "typst", "packages", "local", name, version)
print("Copying files to", target_dir)
copy_files(
source_dir=os.getcwd(),
target_dir=target_dir
)
print("Done.")