Skip to content

Commit 37f7189

Browse files
committed
Only build widgetsnbextension files if needed.
1 parent be6c3ed commit 37f7189

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

widgetsnbextension/setup.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@
44
# Distributed under the terms of the Modified BSD License.
55

66
from jupyter_packaging import (
7+
combine_commands,
78
create_cmdclass,
8-
install_npm,
99
ensure_targets,
10-
combine_commands,
1110
get_version,
11+
install_npm,
12+
skip_if_exists
1213
)
13-
import os
14+
from pathlib import Path
1415
from setuptools import setup
1516

16-
here = os.path.abspath(os.path.dirname(__file__))
17-
js_dir = os.path.join(here, 'src')
17+
HERE = Path(__file__).parent.resolve()
18+
IS_REPO = (HERE.parent / '.git').exists()
19+
JS_DIR = HERE / 'src'
1820

1921
# Representative files that should exist after a successful build
20-
jstargets = [
21-
os.path.join(here, 'widgetsnbextension', 'static', 'extension.js')
22+
js_targets = [
23+
HERE / 'widgetsnbextension' / 'static' / 'extension.js'
2224
]
2325

2426
data_files_spec = [(
@@ -27,10 +29,15 @@
2729
]
2830

2931
cmdclass = create_cmdclass('jsdeps', data_files_spec=data_files_spec)
30-
cmdclass['jsdeps'] = combine_commands(
31-
install_npm(js_dir, npm=['yarn'], build_cmd='build'), ensure_targets(jstargets),
32+
js_command = combine_commands(
33+
install_npm(js_dir, npm=['yarn'], build_cmd='build'),
34+
ensure_targets(js_targets),
3235
)
3336

37+
if IS_REPO:
38+
cmdclass["jsdeps"] = js_command
39+
else:
40+
cmdclass["jsdeps"] = skip_if_exists(js_targets, js_command)
3441

3542
if __name__ == '__main__':
3643
setup(cmdclass=cmdclass)

0 commit comments

Comments
 (0)