generated from 12rambau/pypackage
-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
63 lines (46 loc) · 1.73 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
56
57
58
59
60
61
62
63
import platform
from pathlib import Path
from pynpm import NPMPackage
from setuptools import Command, setup
from setuptools.command.build_py import build_py
from setuptools.command.egg_info import egg_info
from setuptools.command.sdist import sdist
ROOT = Path(__file__).parent
# create a global variable to check if we are on windows
# to pilot the shell option to run the tests
is_windows = platform.system() == "Windows"
def update_package_data(distribution) -> None:
"""Update package_data to catch changes during setup."""
build_py = distribution.get_command_obj("build_py")
build_py.finalize_options()
def js_prerelease(command: Command, strict: bool = False) -> Command:
"""Decorator for building minified js/css prior to another command."""
class DecoratedCommand(command):
"""Decorated command to install jsdeps first."""
def run(self) -> None:
"""Run the command."""
self.distribution.run_command("jsdeps")
command.run(self)
update_package_data(self.distribution)
return DecoratedCommand
class NPM(Command):
"""install package.json dependencies using npm."""
def initialize_options(self):
"""Ignore initialize_options."""
pass
def finalize_options(self):
"""Ignore finalize_options."""
pass
def run(self):
"""Run the command."""
package = ROOT / "sphinxcontrib" / "icon" / "package.json"
NPMPackage(str(package), shell=is_windows).install()
update_package_data(self.distribution)
setup(
cmdclass={
"build_py": js_prerelease(build_py),
"egg_info": js_prerelease(egg_info),
"sdist": js_prerelease(sdist, strict=True),
"jsdeps": NPM,
}
)