ENH: Open a notebook from the command line #1686

Merged
merged 1 commit into from May 13, 2012

Conversation

Projects
None yet
3 participants
Contributor

punchagan commented May 2, 2012

This commit lets you open notebook files from the command line, just
like ipython can open (run) python files. For example:

 ipython notebook foo.ipynb

Fixes #945.

@minrk minrk and 1 other commented on an outdated diff May 2, 2012

IPython/frontend/html/notebook/notebookapp.py
@@ -400,7 +400,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)
+
+ if len(self.extra_args) > 0:
+ file_to_run = os.path.abspath(self.extra_args[0])
+ self.notebook_manager = NotebookManager(config=self.config,
+ log=self.log, notebook_dir=os.path.dirname(file_to_run))
+ else:
+ self.notebook_manager = NotebookManager(config=self.config,
+ log=self.log)
@minrk

minrk May 2, 2012

Owner

Let's do this differently.

Add self.file_to_run as a traitlet, and add this to the end of parse_command_line:

if self.extra_args:
    self.file_to_run = os.path.abspath(self.extra_args[0])
    self.config.NotebookManager.notebook_dir = os.path.dirname(self.file_to_run)

Then the block above in init_configurables need not change at all.

@punchagan

punchagan May 3, 2012

Contributor

Thanks for the comment. Fixed.

Owner

Carreau commented May 4, 2012

How does it behave with non-ipynb-ending files ?
Does it spawn a new server in the file-to-run directory or send it to a currently running server ?

@minrk minrk and 1 other commented on an outdated diff May 4, 2012

IPython/frontend/html/notebook/notebookapp.py
@@ -540,9 +547,20 @@ def start(self):
browser = webbrowser.get(self.browser)
else:
browser = webbrowser.get()
- b = lambda : browser.open("%s://%s:%i%s" % (proto, ip, self.port,
- self.base_project_url),
- new=2)
+
+ if len(self.file_to_run) > 0:
+ filename = os.path.basename(self.file_to_run).split('.ipynb')[0]
@minrk

minrk May 4, 2012

Owner

you can use os.path.split(filename) to return a two-tuple of (base, ext):

filename, _ = os.path.split(os.path.basename(self.file_to_run))

Also, there's no need to check len directly, you can just do: if self.file_to_run:. The same above for if self.extra_args:.

@punchagan

punchagan May 7, 2012

Contributor

Fixed that.

Agreed, there's no need to check len, but some people prefer not to use implicit checks. I should've checked the rest of IPython's code to stick to the standard style.

@punchagan punchagan ENH: Open a notebook from the command line
This commit lets you open notebook files from the command line, just
like ipython can open (run) python files.  For example:

     ipython notebook foo.ipynb

Fixes #945.
4d888f5
Contributor

punchagan commented May 7, 2012

@Carreau currently, it just spawns a server in the file-to-run directory.

@minrk minrk added a commit that referenced this pull request May 13, 2012

@minrk minrk Merge pull request #1686 from punchagan/notebook-cmd-line
ENH: Open a notebook from the command line

open notebook files from the command line, just
like ipython can open (run) python files.  For example:

     ipython notebook foo.ipynb

closes #945
83e0ea6

@minrk minrk merged commit 83e0ea6 into ipython:master May 13, 2012

@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014

@minrk minrk Merge pull request #1686 from punchagan/notebook-cmd-line
ENH: Open a notebook from the command line

open notebook files from the command line, just
like ipython can open (run) python files.  For example:

     ipython notebook foo.ipynb

closes #945
da7e43a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment