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

ENH: Open a notebook from the command line #1686

Merged
merged 1 commit into from May 13, 2012
Merged

ENH: Open a notebook from the command line #1686

merged 1 commit into from May 13, 2012

Conversation

punchagan
Copy link
Contributor

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.

log=self.log, notebook_dir=os.path.dirname(file_to_run))
else:
self.notebook_manager = NotebookManager(config=self.config,
log=self.log)
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 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment. Fixed.

@Carreau
Copy link
Member

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 ?

new=2)

if len(self.file_to_run) > 0:
filename = os.path.basename(self.file_to_run).split('.ipynb')[0]
Copy link
Member

Choose a reason for hiding this comment

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

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:.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

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.
@punchagan
Copy link
Contributor Author

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

minrk added a commit that referenced this pull request May 13, 2012
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
@minrk minrk merged commit 83e0ea6 into ipython:master May 13, 2012
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
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 ipython#945
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Open a notebook from the command line
3 participants