diff --git a/setup.py b/setup.py index 9940e24..e815dde 100644 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ exec(f.read(), {}, VERSION_NS) EXT_DIR = os.path.join(HERE, 'urth_dash_js') +SERVER_EXT_CONFIG = "c.NotebookApp.server_extensions.append('urth.dashboard.nbexts')" def makedirs(path): ''' @@ -34,32 +35,37 @@ def makedirs(path): class InstallCommand(install): def run(self): - # Config managers for frontend and backend - server_cm = ConfigManager(config_dir=jupyter_config_dir()) js_cm = ConfigManager() - - # Ensure directories exist - makedirs(server_cm.config_dir) makedirs(js_cm.config_dir) + # TODO: replace when other extensions move to using JSON config + server_cm = jupyter_config_dir() + makedirs(server_cm) + print('Installing Python server extension') install.run(self) - + print('Installing notebook JS extension') install_nbextension(EXT_DIR, overwrite=True, user=True) print('Enabling notebook JS extension') js_cm.update('notebook', {"load_extensions": {'urth_dash_js/notebook/main': True}}) - print('Enabling Python server extension') - cfg = server_cm.get('jupyter_notebook_config') - server_extensions = ( - cfg.setdefault('NotebookApp', {}) - .setdefault('server_extensions', []) - ) - if 'urth.dashboard.nbexts' not in server_extensions: - cfg['NotebookApp']['server_extensions'] += ['urth.dashboard.nbexts'] - server_cm.update('jupyter_notebook_config', cfg) + print('Installing notebook server extension') + + # TODO: replace when other extensions move to using JSON config + fn = os.path.join(server_cm, 'jupyter_notebook_config.py') + if os.path.isfile(fn): + with open(fn, 'r+') as fh: + lines = fh.read() + if SERVER_EXT_CONFIG not in lines: + fh.seek(0, 2) + fh.write('\n') + fh.write(SERVER_EXT_CONFIG) + else: + with open(fn, 'w') as fh: + fh.write('c = get_config()\n') + fh.write(SERVER_EXT_CONFIG) setup( name='jupyter_dashboards',