-
Notifications
You must be signed in to change notification settings - Fork 579
Expand file tree
/
Copy pathsetup.py
More file actions
37 lines (28 loc) · 1.05 KB
/
Copy pathsetup.py
File metadata and controls
37 lines (28 loc) · 1.05 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
"""Require qualified assets in distributions, while editable source setup stays cheap."""
from pathlib import Path
import importlib.util
import shutil
from setuptools import setup
from setuptools.command.build_py import build_py
from setuptools.command.sdist import sdist
def verify_frontend():
root = Path(__file__).parent
spec = importlib.util.spec_from_file_location(
"chat_bundle_contract", root / "loopx/presentation/chat_bundle.py"
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
module.validate_bundle(root / "loopx/web/chat", source_root=root)
class BuildWithFrontend(build_py):
def run(self):
if not self.editable_mode:
verify_frontend()
stale = Path(self.build_lib) / "loopx/web/chat"
if stale.exists():
shutil.rmtree(stale)
super().run()
class SourceWithFrontend(sdist):
def run(self):
verify_frontend()
super().run()
setup(cmdclass={"build_py": BuildWithFrontend, "sdist": SourceWithFrontend})