|
1 |
| -import os |
| 1 | +from __future__ import print_function |
| 2 | + |
| 3 | +import pipes |
| 4 | +import shutil |
| 5 | +import subprocess |
2 | 6 | import sys
|
| 7 | +import traceback |
| 8 | +from distutils import log |
| 9 | +from distutils.command.build import build # type: ignore |
| 10 | +from distutils.command.sdist import sdist # type: ignore |
3 | 11 | from pathlib import Path
|
4 | 12 |
|
5 | 13 | from setuptools import find_packages, setup
|
| 14 | +from setuptools.command.develop import develop |
| 15 | + |
| 16 | + |
| 17 | +if sys.platform == "win32": |
| 18 | + from subprocess import list2cmdline |
| 19 | +else: |
| 20 | + |
| 21 | + def list2cmdline(cmd_list): |
| 22 | + return " ".join(map(pipes.quote, cmd_list)) |
6 | 23 |
|
7 | 24 |
|
8 | 25 | # the name of the project
|
|
31 | 48 | "license": "MIT",
|
32 | 49 | "platforms": "Linux, Mac OS X, Windows",
|
33 | 50 | "keywords": ["interactive", "widgets", "DOM", "React"],
|
| 51 | + "include_package_data": True, |
34 | 52 | "zip_safe": False,
|
35 | 53 | "classifiers": [
|
36 | 54 | "Framework :: Django",
|
|
52 | 70 | # Library Version
|
53 | 71 | # -----------------------------------------------------------------------------
|
54 | 72 |
|
55 |
| -with open(os.path.join(package_dir, "__init__.py")) as f: |
56 |
| - for line in f.read().split("\n"): |
57 |
| - if line.startswith("__version__ = "): |
58 |
| - package["version"] = eval(line.split("=", 1)[1]) |
59 |
| - break |
60 |
| - else: |
61 |
| - print("No version found in %s/__init__.py" % package_dir) |
62 |
| - sys.exit(1) |
| 73 | + |
| 74 | +for line in (package_dir / "__init__.py").read_text().split("\n"): |
| 75 | + if line.startswith("__version__ = "): |
| 76 | + package["version"] = eval(line.split("=", 1)[1]) |
| 77 | + break |
| 78 | +else: |
| 79 | + print("No version found in %s/__init__.py" % package_dir) |
| 80 | + sys.exit(1) |
63 | 81 |
|
64 | 82 |
|
65 | 83 | # -----------------------------------------------------------------------------
|
|
87 | 105 | package["long_description_content_type"] = "text/markdown"
|
88 | 106 |
|
89 | 107 |
|
| 108 | +# ---------------------------------------------------------------------------- |
| 109 | +# Build Javascript |
| 110 | +# ---------------------------------------------------------------------------- |
| 111 | + |
| 112 | + |
| 113 | +def build_javascript_first(cls): |
| 114 | + class Command(cls): |
| 115 | + def run(self): |
| 116 | + log.info("Installing Javascript...") |
| 117 | + try: |
| 118 | + js_dir = str(src_dir / "js") |
| 119 | + npm = shutil.which("npm") # this is required on windows |
| 120 | + if npm is None: |
| 121 | + raise RuntimeError("NPM is not installed.") |
| 122 | + for args in (f"{npm} install", f"{npm} run build"): |
| 123 | + args_list = args.split() |
| 124 | + log.info(f"> {list2cmdline(args_list)}") |
| 125 | + subprocess.run(args_list, cwd=js_dir, check=True) |
| 126 | + except Exception: |
| 127 | + log.error("Failed to install Javascript") |
| 128 | + log.error(traceback.format_exc()) |
| 129 | + raise |
| 130 | + else: |
| 131 | + log.info("Successfully installed Javascript") |
| 132 | + super().run() |
| 133 | + |
| 134 | + return Command |
| 135 | + |
| 136 | + |
| 137 | +package["cmdclass"] = { |
| 138 | + "sdist": build_javascript_first(sdist), |
| 139 | + "build": build_javascript_first(build), |
| 140 | + "develop": build_javascript_first(develop), |
| 141 | +} |
| 142 | + |
| 143 | + |
90 | 144 | # -----------------------------------------------------------------------------
|
91 | 145 | # Install It
|
92 | 146 | # -----------------------------------------------------------------------------
|
|
0 commit comments