-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsetup.py
More file actions
73 lines (54 loc) · 1.83 KB
/
Copy pathsetup.py
File metadata and controls
73 lines (54 loc) · 1.83 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
"""Builds the React app into the Python package."""
import subprocess
import sys
from pathlib import Path
from typing import Self
from setuptools import setup
from setuptools.command.build_py import build_py
from setuptools.command.develop import develop
from setuptools.command.sdist import sdist
def build_frontend() -> None:
"""Builds the frontend.
Output from this function (print statements, output from pnpm) can only be viewed
when the '-v' flag is given to 'pip install'.
"""
root = Path(__file__).parent
static = root / "src/fmu_settings_gui/static"
frontend_dir = Path(root / "frontend")
if not all((frontend_dir.exists(), frontend_dir.is_dir())):
raise OSError("Frontend directory does not exist or is not a directory")
try:
print("Installing frontend packages...", file=sys.stderr)
subprocess.run(["pnpm", "install"], cwd=frontend_dir, check=True)
print("Building frontend...", file=sys.stderr)
subprocess.run(["pnpm", "run", "build"], cwd=frontend_dir, check=True)
# Restore removed .gitkeep
(static / ".gitkeep").touch()
except subprocess.CalledProcessError as e:
print(f"Frontend build failed: {e}", file=sys.stderr)
raise
class BuildPyCommand(build_py):
"""Build for py."""
def run(self: Self) -> None:
"""Run."""
build_frontend()
super().run()
class DevelopCommand(develop):
"""Build for develop."""
def run(self: Self) -> None:
"""Run."""
build_frontend()
super().run()
class SdistCommand(sdist):
"""Build the sdist."""
def run(self: Self) -> None:
"""Run."""
build_frontend()
super().run()
setup(
cmdclass={
"build_py": BuildPyCommand,
"develop": DevelopCommand,
"sdist": SdistCommand,
},
)