From fd485e23fc8e67d38a04e17ed70f510268c21fc6 Mon Sep 17 00:00:00 2001 From: Fernando Perez Date: Sat, 17 Dec 2011 13:38:52 -0800 Subject: [PATCH 1/3] Add --script flag as shorthand for the script autosave notebook option. --- IPython/frontend/html/notebook/notebookapp.py | 6 ++++-- .../frontend/html/notebook/notebookmanager.py | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index 8fc6e3fcf..2c272736f 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -50,7 +50,7 @@ from .handlers import (LoginHandler, LogoutHandler, MainKernelHandler, KernelHandler, KernelActionHandler, IOPubHandler, ShellHandler, NotebookRootHandler, NotebookHandler, RSTHandler ) -from .notebookmanager import NotebookManager +from .notebookmanager import NotebookManager, manager_flags from IPython.config.application import catch_config_error from IPython.core.application import BaseIPythonApplication @@ -157,10 +157,12 @@ flags['read-only'] = ( """ ) +flags.update(manager_flags) + # the flags that are specific to the frontend # these must be scrubbed before being passed to the kernel, # or it will raise an error on unrecognized flags -notebook_flags = ['no-browser', 'no-mathjax', 'read-only'] +notebook_flags = ['no-browser', 'no-mathjax', 'read-only', 'script'] aliases = dict(ipkernel_aliases) diff --git a/IPython/frontend/html/notebook/notebookmanager.py b/IPython/frontend/html/notebook/notebookmanager.py index f95b7c45a..76b9e9c4a 100644 --- a/IPython/frontend/html/notebook/notebookmanager.py +++ b/IPython/frontend/html/notebook/notebookmanager.py @@ -23,15 +23,22 @@ import glob from tornado import web +from IPython.config.application import boolean_flag from IPython.config.configurable import LoggingConfigurable from IPython.nbformat import current from IPython.utils.traitlets import Unicode, List, Dict, Bool - #----------------------------------------------------------------------------- -# Code +# Aliases and Flags #----------------------------------------------------------------------------- +manager_flags =boolean_flag('script', 'NotebookManager.save_script', + 'Auto-save a .py script everytime the .ipynb notebook is saved', + 'Do not auto-save .py scripts for every notebook') + +#----------------------------------------------------------------------------- +# Classes +#----------------------------------------------------------------------------- class NotebookManager(LoggingConfigurable): @@ -40,10 +47,12 @@ class NotebookManager(LoggingConfigurable): """) save_script = Bool(False, config=True, - help="""Also save notebooks as a Python script. + help="""Automaticall create a Python script when saving the notebook. - For easier use of import/%loadpy across notebooks, a .py - script will be created next to any .ipynb on each save. + For easier use of import, %run and %loadpy across notebooks, a + .py script will be created next to any + .ipynb on each save. This can also be set with the + short `--script` flag. """ ) From b3d57326901e39ac41c4aefff737314a9e8c1957 Mon Sep 17 00:00:00 2001 From: Fernando Perez Date: Sat, 17 Dec 2011 14:31:33 -0800 Subject: [PATCH 2/3] Fix typo in help string --- IPython/frontend/html/notebook/notebookmanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IPython/frontend/html/notebook/notebookmanager.py b/IPython/frontend/html/notebook/notebookmanager.py index 76b9e9c4a..f4f1e3d85 100644 --- a/IPython/frontend/html/notebook/notebookmanager.py +++ b/IPython/frontend/html/notebook/notebookmanager.py @@ -47,7 +47,7 @@ class NotebookManager(LoggingConfigurable): """) save_script = Bool(False, config=True, - help="""Automaticall create a Python script when saving the notebook. + help="""Automatically create a Python script when saving the notebook. For easier use of import, %run and %loadpy across notebooks, a .py script will be created next to any From 7c7a48e2cee21fb33984ff979ea348fb0a182cde Mon Sep 17 00:00:00 2001 From: Fernando Perez Date: Sat, 17 Dec 2011 18:12:41 -0800 Subject: [PATCH 3/3] Define flags in application that's going to use them. --- IPython/frontend/html/notebook/notebookapp.py | 11 +++++++---- IPython/frontend/html/notebook/notebookmanager.py | 9 --------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index 2c272736f..49132eced 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -50,9 +50,9 @@ from .handlers import (LoginHandler, LogoutHandler, MainKernelHandler, KernelHandler, KernelActionHandler, IOPubHandler, ShellHandler, NotebookRootHandler, NotebookHandler, RSTHandler ) -from .notebookmanager import NotebookManager, manager_flags +from .notebookmanager import NotebookManager -from IPython.config.application import catch_config_error +from IPython.config.application import catch_config_error, boolean_flag from IPython.core.application import BaseIPythonApplication from IPython.core.profiledir import ProfileDir from IPython.lib.kernel import swallow_argv @@ -157,12 +157,15 @@ flags['read-only'] = ( """ ) -flags.update(manager_flags) +# Add notebook manager flags +flags.update(boolean_flag('script', 'NotebookManager.save_script', + 'Auto-save a .py script everytime the .ipynb notebook is saved', + 'Do not auto-save .py scripts for every notebook')) # the flags that are specific to the frontend # these must be scrubbed before being passed to the kernel, # or it will raise an error on unrecognized flags -notebook_flags = ['no-browser', 'no-mathjax', 'read-only', 'script'] +notebook_flags = ['no-browser', 'no-mathjax', 'read-only', 'script', 'no-script'] aliases = dict(ipkernel_aliases) diff --git a/IPython/frontend/html/notebook/notebookmanager.py b/IPython/frontend/html/notebook/notebookmanager.py index f4f1e3d85..02295c4aa 100644 --- a/IPython/frontend/html/notebook/notebookmanager.py +++ b/IPython/frontend/html/notebook/notebookmanager.py @@ -23,19 +23,10 @@ import glob from tornado import web -from IPython.config.application import boolean_flag from IPython.config.configurable import LoggingConfigurable from IPython.nbformat import current from IPython.utils.traitlets import Unicode, List, Dict, Bool -#----------------------------------------------------------------------------- -# Aliases and Flags -#----------------------------------------------------------------------------- - -manager_flags =boolean_flag('script', 'NotebookManager.save_script', - 'Auto-save a .py script everytime the .ipynb notebook is saved', - 'Do not auto-save .py scripts for every notebook') - #----------------------------------------------------------------------------- # Classes #-----------------------------------------------------------------------------