Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook to add alternative notebook managers #2155

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions IPython/frontend/html/notebook/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def __init__(self, ipython_app, kernel_manager, notebook_manager,
aliases = dict(ipkernel_aliases)

aliases.update({
'nbmgr': 'NotebookApp.nbmgr',
'ip': 'NotebookApp.ip',
'port': 'NotebookApp.port',
'port-retries': 'NotebookApp.port_retries',
Expand All @@ -241,7 +242,7 @@ def __init__(self, ipython_app, kernel_manager, notebook_manager,
aliases.pop('f', None)

notebook_aliases = [u'port', u'port-retries', u'ip', u'keyfile', u'certfile',
u'notebook-dir']
u'notebook-dir', u'nbmgr']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should get an alias. Remember, everything is always available at the command-line, even without aliases as:

$> ipython notebook --NotebookApp.notebook_manager_class='mymod.MyNotebookManager'


#-----------------------------------------------------------------------------
# NotebookApp
Expand Down Expand Up @@ -277,6 +278,9 @@ class NotebookApp(BaseIPythonApplication):
# file to be opened in the notebook server
file_to_run = Unicode('')

# Which alternative NotebookManager to use
nbmgr = Unicode(u'', config=True, help="""Alternative notebook manager module""")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's follow conventions and call this notebook_manager_class

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note there's also a more specific trait for this sort of thing - DottedObjectName.


# Network related information.

ip = Unicode(LOCALHOST, config=True,
Expand Down Expand Up @@ -430,7 +434,14 @@ def init_configurables(self):
config=self.config, log=self.log, kernel_argv=self.kernel_argv,
connection_dir = self.profile_dir.security_dir,
)
self.notebook_manager = NotebookManager(config=self.config, log=self.log)

# added option to load alternative notebook
if self.nbmgr and self.nbmgr != "":
loader = __import__(self.nbmgr, globals(), locals(), ['get_notebook_manager'], -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use utils.import_string, as elsewhere.

And the default should be set in the notebook_manager_class default value.

self.notebook_manager = loader.get_notebook_manager()
else:
self.notebook_manager = NotebookManager(config=self.config, log=self.log)

self.log.info("Serving notebooks from %s", self.notebook_manager.notebook_dir)
self.notebook_manager.list_notebooks()
self.cluster_manager = ClusterManager(config=self.config, log=self.log)
Expand Down
6 changes: 4 additions & 2 deletions IPython/frontend/terminal/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ class DummyMod(object):
module.__dict__ = global_ns

# Get locals and globals from caller
if (local_ns is None or module is None) and self.default_user_namespaces:
if ((local_ns is None or module is None or compile_flags is None)
and self.default_user_namespaces):
call_frame = sys._getframe(stack_depth).f_back

if local_ns is None:
Expand Down Expand Up @@ -233,7 +234,8 @@ class DummyMod(object):
self.init_user_ns()

# Compiler flags
self.compile.flags = compile_flags
if compile_flags is not None:
self.compile.flags = compile_flags

# Patch for global embedding to make sure that things don't overwrite
# user globals accidentally. Thanks to Richard <rxe@renre-europe.com>
Expand Down
19 changes: 19 additions & 0 deletions docs/source/development/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ the full test suite. You can then run the suite with:

iptest [args]

By default, this excludes the relatively slow tests for ``IPython.parallel``. To
run these, use ``iptest --all``.

Regardless of how you run things, you should eventually see something like:

Expand Down Expand Up @@ -139,6 +141,23 @@ point of the error or failure respectively.

and include the resulting information in your query.

Testing pull requests
---------------------

We have a script that fetches a pull request from Github, merges it with master,
and runs the test suite on different versions of Python. This uses a separate
copy of the repository, so you can keep working on the code while it runs. To
run it::

python tools/test_pr.py -p 1234

The number is the pull request number from Github; the ``-p`` flag makes it post
the results to a comment on the pull request. Any further arguments are passed
to ``iptest``.

This requires the `requests <http://pypi.python.org/pypi/requests>`_ and
`keyring <http://pypi.python.org/pypi/keyring>`_ packages.

For developers: writing tests
=============================

Expand Down
9 changes: 6 additions & 3 deletions tools/test_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def setup(self):
check_call(['git', 'pull', 'origin', 'master'])
except CalledProcessError :
check_call(['git', 'pull', ipy_http_repository, 'master'])
self.master_sha = check_output(['git', 'log', '-1', '--format=%h']).decode('ascii').strip()
os.chdir(basedir)

def get_branch(self):
Expand Down Expand Up @@ -125,7 +126,7 @@ def format_result(result):
return s

if self.pr['mergeable']:
com = self.pr['head']['sha'][:7] + " merged into master"
com = self.pr['head']['sha'][:7] + " merged into master (%s)" % self.master_sha
else:
com = self.pr['head']['sha'][:7] + " (can't merge cleanly)"
lines = ["**Test results for commit %s**" % com,
Expand All @@ -146,10 +147,12 @@ def print_results(self):
pr = self.pr

print("\n")
msg = "**Test results for commit %s" % pr['head']['sha'][:7]
if pr['mergeable']:
print("**Test results for commit %s merged into master**" % pr['head']['sha'][:7])
msg += " merged into master (%s)**" % self.master_sha
else:
print("**Test results for commit %s (can't merge cleanly)**" % pr['head']['sha'][:7])
msg += " (can't merge cleanly)**"
print(msg)
print("Platform:", sys.platform)
for result in self.results:
if result.passed:
Expand Down