-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.py
55 lines (40 loc) · 1.3 KB
/
setup.py
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
"""
Setup.py to build generated js files with webpack.
Everything else is handled in pyproject.toml
"""
import os
from subprocess import check_call
from setuptools import setup
from setuptools.command.build_py import build_py
from setuptools.command.sdist import sdist
HERE = os.path.dirname(__file__)
def webpacked_command(command):
"""
Return a command that inherits from command, but adds webpack JS building
"""
class WebPackedCommand(command):
"""
Run npm webpack to generate appropriate output files before given command.
This generates all the js & css we need, and that is included via an
entry in MANIFEST.in
"""
description = "build frontend files with webpack"
def run(self):
"""
Call npm install & npm run webpack before packaging
"""
check_call(
["npm", "install", "--progress=false", "--unsafe-perm"],
cwd=HERE,
)
check_call(["npm", "run", "webpack"], cwd=HERE)
return super().run()
return WebPackedCommand
setup(
cmdclass={
# Handles making sdists and wheels
"sdist": webpacked_command(sdist),
# Handles `pip install` directly
"build_py": webpacked_command(build_py),
},
)