Skip to content

Commit

Permalink
activate extension (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
hainm committed May 5, 2020
1 parent e181b16 commit da27e7b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 37 deletions.
5 changes: 5 additions & 0 deletions nglview-js-widgets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"load_extensions": {
"nglview-js-widgets/extension": true
}
}
40 changes: 3 additions & 37 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,13 @@
log.info('setup.py entered')
log.info('$PATH=%s' % os.environ['PATH'])


try:
sys.argv.remove('--npm')
rebuild_nglview_js = True
except ValueError:
rebuild_nglview_js = False
try:
sys.argv.remove('--conda')
conda_build = True
except ValueError:
conda_build = False

def enable_extentions():
print("Trying to enable extensions")
# this is for normal users
# for developers, you should know what to do. :D
try:
# enable_nbextension_python does not exist in older notebook
# use try ... except in case users do not have notebook yet
from notebook.nbextensions import enable_nbextension_python
enable_nbextension_python('widgetsnbextension', user=False, sys_prefix=True)

subprocess.check_call([
'jupyter', 'nbextension', 'install', '--py',
'--sys-prefix', 'nglview'
])

subprocess.check_call([
'jupyter', 'nbextension', 'enable', '--py',
'--sys-prefix', 'nglview'
])
print("Seems OK")
except (ImportError, OSError, subprocess.CalledProcessError) as e:
# TODO: add type of exception here?
# Case:
# - notebook is not installed before nglview
# - permission denied?
print('Failed to enable extensions.')
print('Skip. Tips: Do it yourself')
print(' nglview install')
print(' nglview enable')


def js_prerelease(command, strict=False):
"""decorator for building minified js/css prior to another command"""
Expand Down Expand Up @@ -176,6 +143,7 @@ def run(self):
'nglview/static/index.js',
'nglview/static/index.js.map',
]),
('etc/jupyter/nbconfig/notebook.d' , ['nglview-js-widgets.json'])
],
'tests_require': [
'pytest'
Expand Down Expand Up @@ -245,5 +213,3 @@ def run(self):
}

setup(**setup_args)
if not conda_build:
enable_extentions()

0 comments on commit da27e7b

Please sign in to comment.