-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
52 lines (36 loc) · 1.51 KB
/
Copy pathsetup.py
File metadata and controls
52 lines (36 loc) · 1.51 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
from __future__ import annotations
import os
import subprocess
from pathlib import Path
from setuptools import setup
from setuptools.command.build_py import build_py as _build_py
from setuptools.command.sdist import sdist as _sdist
_NPM_BUILD_DONE = False
class _FrontendBuildMixin:
def _run_frontend_build(self) -> None:
global _NPM_BUILD_DONE
if _NPM_BUILD_DONE:
return
if os.environ.get("WIRECLOUD_SKIP_NPM_BUILD") == "1":
self.announce("Skipping frontend build because WIRECLOUD_SKIP_NPM_BUILD=1", level=2)
_NPM_BUILD_DONE = True
return
project_root = Path(__file__).resolve().parent
self.announce("Running frontend build: npm run build", level=2)
npm = "npm.cmd" if os.name == "nt" else "npm"
try:
subprocess.check_call([npm, "run", "build"], cwd=str(project_root), env=os.environ.copy())
except FileNotFoundError as exc:
raise RuntimeError("npm is required to build Wirecloud frontend assets") from exc
except subprocess.CalledProcessError as exc:
raise RuntimeError(f"npm run build failed with exit code {exc.returncode}") from exc
_NPM_BUILD_DONE = True
class build_py(_FrontendBuildMixin, _build_py):
def run(self):
self._run_frontend_build()
super().run()
class sdist(_FrontendBuildMixin, _sdist):
def run(self):
self._run_frontend_build()
super().run()
setup(cmdclass={"build_py": build_py, "sdist": sdist})