2020
2121here = os .path .dirname (os .path .abspath (__file__ ))
2222project_root = os .path .dirname (os .path .dirname (os .path .dirname (here )))
23- node_root = os .path .join (here , "js" )
23+ jupyterlab_extension_root = os .path .join (project_root , "javascript" , "jupyterlab-plotly" )
24+ widget_root = os .path .join (here , "js" )
2425is_repo = os .path .exists (os .path .join (project_root , ".git" ))
2526
2627npm_path = os .pathsep .join (
2728 [
28- os .path .join (node_root , "node_modules" , ".bin" ),
29+ os .path .join (jupyterlab_extension_root , "node_modules" , ".bin" ),
2930 os .environ .get ("PATH" , os .defpath ),
3031 ]
3132)
@@ -131,9 +132,12 @@ class NPM(Command):
131132
132133 user_options = []
133134
134- node_modules = os .path .join (node_root , "node_modules" )
135+ node_modules = os .path .join (jupyterlab_extension_root , "node_modules" )
135136
136137 targets = [
138+ os .path .join (here , "jupyterlab_plotly" , "nbextension" , "extension.js" ),
139+ os .path .join (here , "jupyterlab_plotly" , "nbextension" , "index.js" ),
140+ os .path .join (here , "jupyterlab_plotly" , "labextension" , "package.json" ),
137141 os .path .join (here , "plotly" , "bundle.js" ),
138142 ]
139143
@@ -158,11 +162,6 @@ def has_npm(self):
158162 except :
159163 return False
160164
161- def should_run_npm_install (self ):
162- package_json = os .path .join (node_root , "package.json" )
163- node_modules_exists = os .path .exists (self .node_modules )
164- return self .has_npm ()
165-
166165 def run (self ):
167166 if skip_npm :
168167 log .info ("Skipping npm-installation" )
@@ -177,28 +176,40 @@ def run(self):
177176 env = os .environ .copy ()
178177 env ["PATH" ] = npm_path
179178
180- if self .should_run_npm_install ():
179+ if self .has_npm ():
181180 log .info (
182181 "Installing build dependencies with npm. This may take a while..."
183182 )
184183 npmName = self .get_npm_name ()
185184 check_call (
186185 [npmName , "install" ],
187- cwd = node_root ,
186+ cwd = jupyterlab_extension_root ,
187+ stdout = sys .stdout ,
188+ stderr = sys .stderr ,
189+ )
190+ check_call (
191+ [npmName , "install" ],
192+ cwd = widget_root ,
188193 stdout = sys .stdout ,
189194 stderr = sys .stderr ,
190195 )
191196 if self .local is not None :
192197 plotly_archive = os .path .join (self .local , "plotly.js.tgz" )
193198 check_call (
194199 [npmName , "install" , plotly_archive ],
195- cwd = node_root ,
200+ cwd = jupyterlab_extension_root ,
196201 stdout = sys .stdout ,
197202 stderr = sys .stderr ,
198203 )
204+ check_call (
205+ [npmName , "run" , "build:prod" ],
206+ cwd = jupyterlab_extension_root ,
207+ stdout = sys .stdout ,
208+ stderr = sys .stderr ,
209+ )
199210 check_call (
200211 [npmName , "run" , "build" ],
201- cwd = node_root ,
212+ cwd = widget_root ,
202213 stdout = sys .stdout ,
203214 stderr = sys .stderr ,
204215 )
@@ -449,7 +460,7 @@ def run(self):
449460 overwrite_schema_local (schema_uri )
450461
451462 # Update plotly.js url in package.json
452- package_json_path = os .path .join (node_root , "package.json" )
463+ package_json_path = os .path .join (jupyterlab_extension_root , "package.json" )
453464 with open (package_json_path , "r" ) as f :
454465 package_json = json .load (f )
455466
@@ -504,7 +515,7 @@ def run(self):
504515 from plotly ._version import git_pieces_from_vcs , render
505516
506517 # Update plotly.js url in package.json
507- package_json_path = os .path .join (node_root , "package.json" )
518+ package_json_path = os .path .join (jupyterlab_extension_root , "package.json" )
508519
509520 with open (package_json_path , "r" ) as f :
510521 package_json = json .load (f )
0 commit comments