20
20
21
21
here = os .path .dirname (os .path .abspath (__file__ ))
22
22
project_root = os .path .dirname (os .path .dirname (os .path .dirname (here )))
23
- jupyterlab_extension_root = os .path .join (
24
- project_root , "packages" , "javascript" , "jupyterlab-plotly"
25
- )
26
- widget_root = os .path .join (here , "js" )
23
+ node_root = os .path .join (project_root , "packages" , "javascript" , "jupyterlab-plotly" )
27
24
is_repo = os .path .exists (os .path .join (project_root , ".git" ))
28
25
29
26
npm_path = os .pathsep .join (
30
27
[
31
- os .path .join (jupyterlab_extension_root , "node_modules" , ".bin" ),
28
+ os .path .join (node_root , "node_modules" , ".bin" ),
32
29
os .environ .get ("PATH" , os .defpath ),
33
30
]
34
31
)
35
32
36
33
labstatic = "jupyterlab_plotly/labextension/static"
37
-
38
34
if not os .path .exists (labstatic ):
39
35
# Ensure the folder exists when we will look for files in it
40
36
os .makedirs (labstatic )
@@ -134,13 +130,12 @@ class NPM(Command):
134
130
135
131
user_options = []
136
132
137
- node_modules = os .path .join (jupyterlab_extension_root , "node_modules" )
133
+ node_modules = os .path .join (node_root , "node_modules" )
138
134
139
135
targets = [
140
136
os .path .join (here , "jupyterlab_plotly" , "nbextension" , "extension.js" ),
141
137
os .path .join (here , "jupyterlab_plotly" , "nbextension" , "index.js" ),
142
138
os .path .join (here , "jupyterlab_plotly" , "labextension" , "package.json" ),
143
- os .path .join (here , "plotly" , "bundle.js" ),
144
139
]
145
140
146
141
def initialize_options (self ):
@@ -164,6 +159,11 @@ def has_npm(self):
164
159
except :
165
160
return False
166
161
162
+ def should_run_npm_install (self ):
163
+ package_json = os .path .join (node_root , "package.json" )
164
+ node_modules_exists = os .path .exists (self .node_modules )
165
+ return self .has_npm ()
166
+
167
167
def run (self ):
168
168
if skip_npm :
169
169
log .info ("Skipping npm-installation" )
@@ -178,40 +178,28 @@ def run(self):
178
178
env = os .environ .copy ()
179
179
env ["PATH" ] = npm_path
180
180
181
- if self .has_npm ():
181
+ if self .should_run_npm_install ():
182
182
log .info (
183
183
"Installing build dependencies with npm. This may take a while..."
184
184
)
185
185
npmName = self .get_npm_name ()
186
186
check_call (
187
187
[npmName , "install" ],
188
- cwd = jupyterlab_extension_root ,
189
- stdout = sys .stdout ,
190
- stderr = sys .stderr ,
191
- )
192
- check_call (
193
- [npmName , "install" ],
194
- cwd = widget_root ,
188
+ cwd = node_root ,
195
189
stdout = sys .stdout ,
196
190
stderr = sys .stderr ,
197
191
)
198
192
if self .local is not None :
199
193
plotly_archive = os .path .join (self .local , "plotly.js.tgz" )
200
194
check_call (
201
195
[npmName , "install" , plotly_archive ],
202
- cwd = jupyterlab_extension_root ,
196
+ cwd = node_root ,
203
197
stdout = sys .stdout ,
204
198
stderr = sys .stderr ,
205
199
)
206
200
check_call (
207
201
[npmName , "run" , "build:prod" ],
208
- cwd = jupyterlab_extension_root ,
209
- stdout = sys .stdout ,
210
- stderr = sys .stderr ,
211
- )
212
- check_call (
213
- [npmName , "run" , "build" ],
214
- cwd = widget_root ,
202
+ cwd = node_root ,
215
203
stdout = sys .stdout ,
216
204
stderr = sys .stderr ,
217
205
)
@@ -462,7 +450,7 @@ def run(self):
462
450
overwrite_schema_local (schema_uri )
463
451
464
452
# Update plotly.js url in package.json
465
- package_json_path = os .path .join (jupyterlab_extension_root , "package.json" )
453
+ package_json_path = os .path .join (node_root , "package.json" )
466
454
with open (package_json_path , "r" ) as f :
467
455
package_json = json .load (f )
468
456
@@ -517,7 +505,7 @@ def run(self):
517
505
from plotly ._version import git_pieces_from_vcs , render
518
506
519
507
# Update plotly.js url in package.json
520
- package_json_path = os .path .join (jupyterlab_extension_root , "package.json" )
508
+ package_json_path = os .path .join (node_root , "package.json" )
521
509
522
510
with open (package_json_path , "r" ) as f :
523
511
package_json = json .load (f )
0 commit comments