Skip to content

Commit 0920b9d

Browse files
committed
restore changes to setup.py
1 parent 3578bac commit 0920b9d

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

packages/python/plotly/setup.py

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,17 @@
2020

2121
here = os.path.dirname(os.path.abspath(__file__))
2222
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")
2724
is_repo = os.path.exists(os.path.join(project_root, ".git"))
2825

2926
npm_path = os.pathsep.join(
3027
[
31-
os.path.join(jupyterlab_extension_root, "node_modules", ".bin"),
28+
os.path.join(node_root, "node_modules", ".bin"),
3229
os.environ.get("PATH", os.defpath),
3330
]
3431
)
3532

3633
labstatic = "jupyterlab_plotly/labextension/static"
37-
3834
if not os.path.exists(labstatic):
3935
# Ensure the folder exists when we will look for files in it
4036
os.makedirs(labstatic)
@@ -134,13 +130,12 @@ class NPM(Command):
134130

135131
user_options = []
136132

137-
node_modules = os.path.join(jupyterlab_extension_root, "node_modules")
133+
node_modules = os.path.join(node_root, "node_modules")
138134

139135
targets = [
140136
os.path.join(here, "jupyterlab_plotly", "nbextension", "extension.js"),
141137
os.path.join(here, "jupyterlab_plotly", "nbextension", "index.js"),
142138
os.path.join(here, "jupyterlab_plotly", "labextension", "package.json"),
143-
os.path.join(here, "plotly", "bundle.js"),
144139
]
145140

146141
def initialize_options(self):
@@ -164,6 +159,11 @@ def has_npm(self):
164159
except:
165160
return False
166161

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+
167167
def run(self):
168168
if skip_npm:
169169
log.info("Skipping npm-installation")
@@ -178,40 +178,28 @@ def run(self):
178178
env = os.environ.copy()
179179
env["PATH"] = npm_path
180180

181-
if self.has_npm():
181+
if self.should_run_npm_install():
182182
log.info(
183183
"Installing build dependencies with npm. This may take a while..."
184184
)
185185
npmName = self.get_npm_name()
186186
check_call(
187187
[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,
195189
stdout=sys.stdout,
196190
stderr=sys.stderr,
197191
)
198192
if self.local is not None:
199193
plotly_archive = os.path.join(self.local, "plotly.js.tgz")
200194
check_call(
201195
[npmName, "install", plotly_archive],
202-
cwd=jupyterlab_extension_root,
196+
cwd=node_root,
203197
stdout=sys.stdout,
204198
stderr=sys.stderr,
205199
)
206200
check_call(
207201
[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,
215203
stdout=sys.stdout,
216204
stderr=sys.stderr,
217205
)
@@ -462,7 +450,7 @@ def run(self):
462450
overwrite_schema_local(schema_uri)
463451

464452
# 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")
466454
with open(package_json_path, "r") as f:
467455
package_json = json.load(f)
468456

@@ -517,7 +505,7 @@ def run(self):
517505
from plotly._version import git_pieces_from_vcs, render
518506

519507
# 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")
521509

522510
with open(package_json_path, "r") as f:
523511
package_json = json.load(f)

0 commit comments

Comments
 (0)