Skip to content

Commit

Permalink
Merge pull request #6 from Carreau/fix-jon
Browse files Browse the repository at this point in the history
Fix undefined variables
  • Loading branch information
jdfreder committed Feb 29, 2016
2 parents 6288b7a + 976687e commit 13c20df
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 37 deletions.
49 changes: 21 additions & 28 deletions notebook/nbextensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from __future__ import print_function

import logging
import os
import shutil
import sys
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand All @@ -351,6 +343,7 @@ def _log_format_default(self):
}}, "Create symlink instead of copying files"
),
})

flags['s'] = flags['symlink']

aliases = {
Expand Down
4 changes: 2 additions & 2 deletions notebook/serverextensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions notebook/static/base/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand All @@ -852,7 +852,7 @@ define([
} else {
return (order == 1) ? 1 : -1;
}
}
};

var utils = {
load_extension: load_extension,
Expand Down
2 changes: 1 addition & 1 deletion notebook/static/notebook/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion notebook/static/terminal/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions notebook/tests/test_nbextensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import glob
import os
import re
import sys
import tarfile
import zipfile
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 13c20df

Please sign in to comment.