-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.py
More file actions
79 lines (66 loc) · 2.28 KB
/
setup.py
File metadata and controls
79 lines (66 loc) · 2.28 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
from pathlib import Path
import subprocess
import sys
from setuptools import setup
from setuptools.command.build_py import build_py as _build_py
from setuptools.command.sdist import sdist as _sdist
def _build_frontend() -> None:
repo_root = Path(__file__).resolve().parent
frontend_dir = repo_root / "frontend"
dist_dir = repo_root / "pixlstash" / "frontend" / "dist"
required_frontend_sources = [
frontend_dir / "package.json",
frontend_dir / "index.html",
frontend_dir / "vite.config.js",
frontend_dir / "src",
]
if not frontend_dir.is_dir():
# Running from an installed/unpacked sdist that already has the built dist
if dist_dir.is_dir():
return
raise FileNotFoundError(
"frontend/ source directory not found and pixlstash/frontend/dist/ is missing. "
"Cannot build the frontend."
)
# sdists can intentionally ship a prebuilt frontend dist without full source files.
has_full_frontend_source = all(path.exists() for path in required_frontend_sources)
if not has_full_frontend_source:
if dist_dir.is_dir():
print(
"setup.py: frontend source incomplete; using existing pixlstash/frontend/dist/",
flush=True,
)
return
raise FileNotFoundError(
"frontend/ source is incomplete and pixlstash/frontend/dist/ is missing. "
"Cannot build the frontend."
)
node_modules = frontend_dir / "node_modules"
if not node_modules.is_dir():
print("setup.py: running npm ci in frontend/", flush=True)
subprocess.check_call(
["npm", "ci"],
cwd=str(frontend_dir),
shell=sys.platform == "win32",
)
print("setup.py: running npm run build in frontend/", flush=True)
subprocess.check_call(
["npm", "run", "build"],
cwd=str(frontend_dir),
shell=sys.platform == "win32",
)
class build_py(_build_py):
def run(self):
_build_frontend()
super().run()
class sdist(_sdist):
def run(self):
_build_frontend()
super().run()
if __name__ == "__main__":
setup(
cmdclass={
"build_py": build_py,
"sdist": sdist,
}
)