diff --git a/notebook/nbextensions.py b/notebook/nbextensions.py index dc5966d342..345c6226e6 100644 --- a/notebook/nbextensions.py +++ b/notebook/nbextensions.py @@ -6,7 +6,6 @@ from __future__ import print_function -import logging import os import shutil import sys @@ -22,15 +21,15 @@ from urllib import urlretrieve from jupyter_core.paths import ( - jupyter_data_dir, jupyter_path, jupyter_config_dir, jupyter_config_path, + jupyter_data_dir, jupyter_config_dir, jupyter_config_path, SYSTEM_JUPYTER_PATH, ENV_JUPYTER_PATH, ENV_CONFIG_PATH, SYSTEM_CONFIG_PATH ) from ipython_genutils.path import ensure_dir_exists -from ipython_genutils.py3compat import string_types, cast_unicode_py2, PY3 +from ipython_genutils.py3compat import string_types, cast_unicode_py2 from ipython_genutils.tempdir import TemporaryDirectory from ._version import __version__ -from traitlets.config.manager import BaseJSONConfigManager, recursive_update +from traitlets.config.manager import BaseJSONConfigManager from tornado.log import LogFormatter @@ -186,7 +185,6 @@ def install_nbextension(path, overwrite=False, symlink=False, os.makedirs(dest_dir) for file in files: src = pjoin(parent, file) - # logger.info("%r, %r" % (dest_dir, file)) dest_file = pjoin(dest_dir, file) _maybe_copy(src, dest_file, logger=logger) else: @@ -206,7 +204,7 @@ def install_nbextension_python(package, overwrite=False, symlink=False, src = os.path.join(base_path, nbext['src']) dest = nbext['dest'] require = nbext['require'] - log(src, dest, require) + logger(src, dest, require) install_nbextension(src, overwrite=overwrite, symlink=symlink, user=user, sys_prefix=sys_prefix, prefix=prefix, nbextensions_dir=nbextensions_dir, destination=dest, logger=logger @@ -265,40 +263,38 @@ def uninstall_nbextension_python(package, logger=None): """Uninstall an nbextension bundled in a Python package.""" m, nbexts = _get_nbextension_metadata(package) - base_path = os.path.split(m.__file__)[0] for nbext in nbexts: dest = nbext['dest'] require = nbext['require'] logger.info("{} {}".format(dest, require)) uninstall_nbextension(dest, require, user=user, sys_prefix=sys_prefix, prefix=prefix, nbextensions_dir=nbextensions_dir, logger=logger) - -def enable_nbextension_python(package, user=False, sys_prefix=False): - """Enable an nbextension associated with a Python package.""" +def _set_nbextension_state_python(state, package, user, sys_prefix): + """ + Enable or disable a nbextension + """ m, nbexts = _get_nbextension_metadata(package) - base_path = os.path.split(m.__file__)[0] + config_dir = os.path.join(_get_config_dir(user=user, sys_prefix=sys_prefix), 'nbconfig') + cm = BaseJSONConfigManager(config_dir=config_dir) for nbext in nbexts: - config_dir = os.path.join(_get_config_dir(user=user, sys_prefix=sys_prefix), 'nbconfig') - cm = BaseJSONConfigManager(config_dir=config_dir) - cm.update(nbext['section'], {"load_extensions": {nbext['require']: True}}) + cm.update(nbext['section'], {"load_extensions": {nbext['require']: state}}) + +def enable_nbextension_python(package, user=False, sys_prefix=False): + """Enable an nbextension associated with a Python package.""" + _set_nbextension_state_python(True, package, user, sys_prefix) def disable_nbextension_python(package, user=False, sys_prefix=False): """Disable an nbextension associated with a Python package.""" - m, nbexts = _get_nbextension_metadata(package) - base_path = os.path.split(m.__file__)[0] - for nbext in nbexts: - config_dir = os.path.join(_get_config_dir(user=user, sys_prefix=sys_prefix), 'nbconfig') - cm = BaseJSONConfigManager(config_dir=config_dir) - cm.update(nbext['section'], {"load_extensions": {nbext['require']: False}}) + _set_nbextension_state_python(False, package, user, sys_prefix) #---------------------------------------------------------------------- # Applications #---------------------------------------------------------------------- -from traitlets import Bool, Enum, Unicode +from traitlets import Bool, Unicode from jupyter_core.application import JupyterApp @@ -329,17 +325,13 @@ class BaseNBExtensionApp(JupyterApp): sys_prefix = Bool(False, config=True, help="Use the sys.prefix as the prefix") python = Bool(False, config=True, help="Install from a Python package") - def _log_level_default(self): - return logging.INFO - - def _log_datefmt_default(self): - return "%Y-%m-%d %H:%M:%S" - def _log_format_default(self): return "%(color)s[%(name)s]%(end_color)s %(message)s" -flags = _base_flags.update({ +flags = {} +flags.update(_base_flags) +flags.update({ "overwrite" : ({ "InstallNBExtensionApp" : { "overwrite" : True, @@ -351,6 +343,7 @@ def _log_format_default(self): }}, "Create symlink instead of copying files" ), }) + flags['s'] = flags['symlink'] aliases = { diff --git a/notebook/serverextensions.py b/notebook/serverextensions.py index c1e73de5e2..de58382583 100644 --- a/notebook/serverextensions.py +++ b/notebook/serverextensions.py @@ -12,8 +12,8 @@ from jupyter_core.paths import jupyter_config_path from ._version import __version__ from .nbextensions import ( - BaseNBExtensionApp, ToggleNBExtensionApp, _get_config_dir, _read_config_data, - _write_config_data, GREEN_ENABLED, RED_DISABLED + BaseNBExtensionApp, ToggleNBExtensionApp, _get_config_dir, + GREEN_ENABLED, RED_DISABLED ) from traitlets import Bool diff --git a/notebook/static/base/js/utils.js b/notebook/static/base/js/utils.js index 8a1fa42c69..4ce55278d7 100644 --- a/notebook/static/base/js/utils.js +++ b/notebook/static/base/js/utils.js @@ -842,7 +842,7 @@ define([ var format_datetime = function(date) { var text = moment(date).fromNow(); return text === 'a few seconds ago' ? 'seconds ago' : text; - } + }; var datetime_sort_helper = function(a, b, order) { if (moment(a).isBefore(moment(b))) { @@ -852,7 +852,7 @@ define([ } else { return (order == 1) ? 1 : -1; } - } + }; var utils = { load_extension: load_extension, diff --git a/notebook/static/notebook/js/main.js b/notebook/static/notebook/js/main.js index 1630dec328..b800d6f00b 100644 --- a/notebook/static/notebook/js/main.js +++ b/notebook/static/notebook/js/main.js @@ -93,7 +93,7 @@ require([ var save_widget = new savewidget.SaveWidget('span#save_widget', { events: events, keyboard_manager: keyboard_manager}); - acts.extend_env({save_widget:save_widget}) + acts.extend_env({save_widget:save_widget}); var contents = new contentsModule.Contents({ base_url: common_options.base_url, common_config: common_config diff --git a/notebook/static/terminal/js/main.js b/notebook/static/terminal/js/main.js index 7bac667e49..56a11fde56 100644 --- a/notebook/static/terminal/js/main.js +++ b/notebook/static/terminal/js/main.js @@ -35,7 +35,8 @@ require([ var ws_url = location.protocol.replace('http', 'ws') + "//" + location.host + base_url + ws_path; - var header = $("#header")[0] + var header = $("#header")[0]; + function calculate_size() { var height = $(window).height() - header.offsetHeight; var width = $('#terminado-container').width(); diff --git a/notebook/tests/test_nbextensions.py b/notebook/tests/test_nbextensions.py index 5da56b29ce..1ebb5566f6 100644 --- a/notebook/tests/test_nbextensions.py +++ b/notebook/tests/test_nbextensions.py @@ -6,7 +6,6 @@ import glob import os -import re import sys import tarfile import zipfile @@ -51,7 +50,7 @@ def tempdir(self): def setUp(self): self.tempdirs = [] - src = self.src = self.tempdir() + self.src = self.tempdir() self.files = files = [ pjoin(u'ƒile'), pjoin(u'∂ir', u'ƒile1'), @@ -201,7 +200,7 @@ def test_update_file(self): install_nbextension(src) self.assert_installed(fname) dest = pjoin(self.system_nbext, fname) - old_mtime = os.stat(dest).st_mtime + os.stat(dest).st_mtime with open(src, 'w') as f: f.write('overwrite') touch(src, mtime + 10)