|
1 | | -from setuptools import setup |
| 1 | +import os |
| 2 | +import shutil |
| 3 | +from subprocess import check_call |
| 4 | +import json |
| 5 | +import time |
| 6 | + |
| 7 | +from setuptools import setup, Command |
| 8 | +from setuptools.command.sdist import sdist |
| 9 | +from setuptools.command.build_py import build_py |
| 10 | +from setuptools.command.egg_info import egg_info |
| 11 | + |
| 12 | +here = os.path.dirname(os.path.abspath(__file__)) |
| 13 | +is_repo = os.path.exists(os.path.join(here, ".git")) |
| 14 | + |
| 15 | + |
| 16 | +def get_labextension_version(): |
| 17 | + if is_repo: |
| 18 | + labextension_dir = os.path.join(here, "extensions", "jupyterlab") |
| 19 | + else: |
| 20 | + labextension_dir = os.path.join(here, "jupyter_dash", "labextension") |
| 21 | + |
| 22 | + package_json = os.path.join(labextension_dir, 'package.json') |
| 23 | + with open(package_json, 'rt') as f: |
| 24 | + package_data = json.load(f) |
| 25 | + |
| 26 | + labextension_version = package_data['version'] |
| 27 | + return labextension_version |
| 28 | + |
| 29 | + |
| 30 | +def js_prerelease(command): |
| 31 | + """decorator for building JavaScript extensions before command""" |
| 32 | + class DecoratedCommand(command): |
| 33 | + def run(self): |
| 34 | + self.run_command("build_js") |
| 35 | + command.run(self) |
| 36 | + return DecoratedCommand |
| 37 | + |
| 38 | + |
| 39 | +class BuildLabextension(Command): |
| 40 | + description = "Build JupyterLab extension" |
| 41 | + user_options = [] |
| 42 | + |
| 43 | + def initialize_options(self): |
| 44 | + pass |
| 45 | + |
| 46 | + def finalize_options(self): |
| 47 | + pass |
| 48 | + |
| 49 | + def run(self): |
| 50 | + if not is_repo: |
| 51 | + # Nothing to do |
| 52 | + return |
| 53 | + |
| 54 | + # Load labextension version from package.json |
| 55 | + out_labextension_dir = os.path.join(here, "jupyter_dash", "labextension") |
| 56 | + os.makedirs(out_labextension_dir, exist_ok=True) |
| 57 | + |
| 58 | + # Copy package.json to labextension directory |
| 59 | + shutil.copy( |
| 60 | + os.path.join(here, "extensions", "jupyterlab", "package.json"), |
| 61 | + out_labextension_dir |
| 62 | + ) |
| 63 | + time.sleep(0.5) |
| 64 | + in_labextension_dir = os.path.join(here, "extensions", "jupyterlab") |
| 65 | + |
| 66 | + # Build filename |
| 67 | + labextension_version = get_labextension_version() |
| 68 | + filename = "jupyterlab-dash-v{ver}.tgz".format( |
| 69 | + ver=labextension_version |
| 70 | + ) |
| 71 | + |
| 72 | + # Build and pack extension |
| 73 | + dist_path = os.path.join(out_labextension_dir, "dist") |
| 74 | + shutil.rmtree(dist_path, ignore_errors=True) |
| 75 | + os.makedirs(dist_path, exist_ok=True) |
| 76 | + |
| 77 | + check_call( |
| 78 | + ['jlpm', "install"], |
| 79 | + cwd=in_labextension_dir, |
| 80 | + ) |
| 81 | + check_call( |
| 82 | + ['jlpm', "build"], |
| 83 | + cwd=in_labextension_dir, |
| 84 | + ) |
| 85 | + check_call( |
| 86 | + ['jlpm', "pack", "--filename", dist_path + "/" + filename], |
| 87 | + cwd=in_labextension_dir, |
| 88 | + ) |
2 | 89 |
|
3 | | -from jupyter_dash import __labextension_version__ |
4 | 90 |
|
5 | 91 | setup( |
6 | 92 | name='jupyter-dash', |
7 | | - version='0.0.1a1', |
| 93 | + version='0.0.1a2', |
8 | 94 | description="Dash support for the Jupyter notebook interface", |
9 | 95 | author='Plotly', |
10 | 96 | packages=['jupyter_dash'], |
11 | 97 | install_requires=['dash', 'requests', 'flask', 'retrying', 'ipython'], |
12 | 98 | include_package_data=True, |
| 99 | + package_data={ |
| 100 | + "jupyter_dash": [ |
| 101 | + "labextension/package.json", |
| 102 | + ], |
| 103 | + }, |
13 | 104 | data_files=[ |
14 | 105 | # like `jupyter nbextension install --sys-prefix` |
15 | 106 | ("share/jupyter/nbextensions/jupyter_dash", [ |
|
21 | 112 | ]), |
22 | 113 | # Place jupyterlab extension in extension directory |
23 | 114 | ("share/jupyter/lab/extensions", [ |
24 | | - "extensions/jupyterlab/jupyterlab-dash-{ver}.tgz".format( |
25 | | - ver=__labextension_version__ |
| 115 | + "jupyter_dash/labextension/dist/jupyterlab-dash-v{ver}.tgz".format( |
| 116 | + ver=get_labextension_version() |
26 | 117 | ) |
27 | 118 | ]), |
28 | | - ] |
| 119 | + ], |
| 120 | + cmdclass=dict( |
| 121 | + build_js=BuildLabextension, |
| 122 | + build_py=js_prerelease(build_py), |
| 123 | + egg_info=js_prerelease(egg_info), |
| 124 | + sdist=js_prerelease(sdist), |
| 125 | + ) |
29 | 126 | ) |
0 commit comments