From aa616c2f4040e0e06fb6953eb66bf308aa1d24fa Mon Sep 17 00:00:00 2001 From: Peter Parente Date: Tue, 15 Dec 2015 22:06:18 -0500 Subject: [PATCH 1/3] Revert "Python 2/3 makedirs that ignores EEXIST" This reverts commit c2beae9cabba96bb87d5ce70db2f292fb3f5b41c. --- setup.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index 9940e24..456a6b5 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,6 @@ # Distributed under the terms of the Modified BSD License. import os -import errno from setuptools import setup from setuptools.command.install import install @@ -20,18 +19,6 @@ EXT_DIR = os.path.join(HERE, 'urth_dash_js') -def makedirs(path): - ''' - mkdir -p and ignore existence errors compatible with Py2/3. - ''' - try: - os.makedirs(path) - except OSError as e: - if e.errno == errno.EEXIST and os.path.isdir(path): - pass - else: - raise - class InstallCommand(install): def run(self): # Config managers for frontend and backend @@ -39,8 +26,8 @@ def run(self): js_cm = ConfigManager() # Ensure directories exist - makedirs(server_cm.config_dir) - makedirs(js_cm.config_dir) + os.makedirs(server_cm.config_dir, exist_ok=True) + os.makedirs(js_cm.config_dir, exist_ok=True) print('Installing Python server extension') install.run(self) From e0e98047d578031d358422b9fb9130c62e023ffd Mon Sep 17 00:00:00 2001 From: Peter Parente Date: Tue, 15 Dec 2015 22:06:27 -0500 Subject: [PATCH 2/3] Revert "Improve config management on install" This reverts commit 43348fbc458bb210c4d17a07982c039bdef1298c. --- setup.py | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/setup.py b/setup.py index 456a6b5..3ecf8bc 100644 --- a/setup.py +++ b/setup.py @@ -18,35 +18,33 @@ 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')" 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 - os.makedirs(server_cm.config_dir, exist_ok=True) - os.makedirs(js_cm.config_dir, exist_ok=True) - - print('Installing Python server extension') + print('Installing Python module') install.run(self) - - print('Installing notebook JS extension') + + print('Installing notebook extension') install_nbextension(EXT_DIR, overwrite=True, user=True) + cm = ConfigManager() + print('Enabling extension for notebook') + cm.update('notebook', {"load_extensions": {'urth_dash_js/notebook/main': True}}) - print('Enabling notebook JS extension') - js_cm.update('notebook', {"load_extensions": {'urth_dash_js/notebook/main': True}}) + print('Installing notebook server extension') + fn = os.path.join(jupyter_config_dir(), 'jupyter_notebook_config.py') - 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) + 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', From 677c0e35718ad8d70a110f5458cec902e06c1856 Mon Sep 17 00:00:00 2001 From: Peter Parente Date: Mon, 28 Dec 2015 10:47:00 -0500 Subject: [PATCH 3/3] Ensure config directories exist (c) Copyright IBM Corp. 2015 --- setup.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 3ecf8bc..e815dde 100644 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ # Distributed under the terms of the Modified BSD License. import os +import errno from setuptools import setup from setuptools.command.install import install @@ -20,20 +21,40 @@ EXT_DIR = os.path.join(HERE, 'urth_dash_js') SERVER_EXT_CONFIG = "c.NotebookApp.server_extensions.append('urth.dashboard.nbexts')" +def makedirs(path): + ''' + mkdir -p and ignore existence errors compatible with Py2/3. + ''' + try: + os.makedirs(path) + except OSError as e: + if e.errno == errno.EEXIST and os.path.isdir(path): + pass + else: + raise + class InstallCommand(install): def run(self): - print('Installing Python module') + js_cm = ConfigManager() + 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 extension') + print('Installing notebook JS extension') install_nbextension(EXT_DIR, overwrite=True, user=True) - cm = ConfigManager() - print('Enabling extension for notebook') - cm.update('notebook', {"load_extensions": {'urth_dash_js/notebook/main': True}}) - print('Installing notebook server extension') - fn = os.path.join(jupyter_config_dir(), 'jupyter_notebook_config.py') + print('Enabling notebook JS extension') + js_cm.update('notebook', {"load_extensions": {'urth_dash_js/notebook/main': True}}) + 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()