Skip to content

Version conversion, support for X to Y even if Y < X (nbformat)#4198

Merged
minrk merged 12 commits into
ipython:masterfrom
jdfreder:versionconversion_nbconvert
Oct 29, 2013
Merged

Version conversion, support for X to Y even if Y < X (nbformat)#4198
minrk merged 12 commits into
ipython:masterfrom
jdfreder:versionconversion_nbconvert

Conversation

@jdfreder
Copy link
Copy Markdown
Contributor

This is an implementation that is done in nbformat. I'm still not convinced that the conversion shouldn't be done in nbconvert once the ipynb->ipynb stuff gets checked in.

TODO

  • Test
  • Add tests

@jdfreder
Copy link
Copy Markdown
Contributor Author

FWIW, I started out thinking I was going to implement this in nbconvert but later changed my mind. Consequently my local branch is named versionconversion_nbconvert (misleading, I know, sorry).

Comment thread IPython/nbformat/current.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should be a relative import, I think

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried a relative import, and it did not like my syntax. Did you mean something like from .reader import X, Y, etc?

@jdfreder
Copy link
Copy Markdown
Contributor Author

@minrk I think my code comment (above) may have flew under your radar. I ended up using from a import b as c to resolve the naming conflict of reads in both classes.

Comment thread IPython/nbformat/current.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

generally use in (2,3) for this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Neat trick, thanks for showing me that

@minrk
Copy link
Copy Markdown
Member

minrk commented Sep 23, 2013

With the changes you have here, what would be the code for something like "open a notebook file, give it to me in the current format, noting the original format"?

@jdfreder
Copy link
Copy Markdown
Contributor Author

With the changes you have here, what would be the code for something like "open a notebook file, give it to me in the current format, noting the original format"?

nb = reader.read(...) # will load the file as is
(major, minor) = reader.get_version(nb) # will give you the version 

That way the steps are separate, which is what you suggested, right? Whoever reads the notebook is responsible for keeping track of the version if it matters.

@minrk
Copy link
Copy Markdown
Member

minrk commented Sep 23, 2013

Sorry, by 'current version', I meant the latest version. That is, open the file, read it, upgrade it if necessary, note the original version.

@jdfreder
Copy link
Copy Markdown
Contributor Author

Ah, like this:

nb = reader.read(...)
(major, minor) = reader.get_version(nb)
nb = convert.convert(nb, current.current_nbformat)

@jdfreder
Copy link
Copy Markdown
Contributor Author

Tests added and comments addressed

Comment thread IPython/nbformat/reader.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why 16 in s[:16] ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just to display part of the JSON in the error message, that code came from current.py in master. Sorry it's kind of misleading since git has no way of tracking that I took those lines from that file.

See: https://github.com/ipython/ipython/blob/master/IPython/nbformat/current.py#L55

Just because it's in master doesn't mean it's the right behavior. It seems okay with me, do you think I should change it so it doesn't show any of the JSON?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Then just a comment that say that 16 is "random". That the kind of things you can wonder when you came across that later, like, it might be to avoid new line, you might want `len('Notebook does not appear to be JSON:')+n < 80' to fit on terminal screen..

And for aestetic purpose add a '...' , I guess we can suppose we will never be in a case where the file is smaller than 16 char or empty.

@damianavila
Copy link
Copy Markdown
Member

Overall look good... @minrk and @Carreau addressed the main issues, I just added two typo in comments.

@jdfreder
Copy link
Copy Markdown
Contributor Author

jdfreder commented Oct 7, 2013

Thanks all, comments addressed

@jdfreder
Copy link
Copy Markdown
Contributor Author

@Carreau I just addressed your comment about the print JSON error length.

@minrk
Copy link
Copy Markdown
Member

minrk commented Oct 27, 2013

@ellisonbg do you want to have a look over this one to confirm that it's the way we want to go? Merging this is necessary to get started on the nbformat 4 work.

@ellisonbg
Copy link
Copy Markdown
Member

Sure I will do that tomorrow...

On Sun, Oct 27, 2013 at 3:00 PM, Min RK notifications@github.com wrote:

@ellisonbg https://github.com/ellisonbg do you want to have a look over
this one to confirm that it's the way we want to go? Merging this is
necessary to get started on the nbformat 4 work.


Reply to this email directly or view it on GitHubhttps://github.com//pull/4198#issuecomment-27180544
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@Carreau
Copy link
Copy Markdown
Member

Carreau commented Oct 28, 2013

Detail when you will be working on nbformat v4, IJulia, IRuby, and soon IHaskell store notebook.metadata.language='haskell|ruby|julia' it would be great if the 3->4 converter was able to use that :-)

@ellisonbg
Copy link
Copy Markdown
Member

OK I had a pretty close look at the core APIs in this PR. I think it looks good. I like the idea of having separate upgrade and downgrade functions for the two directions as the logic will be pretty different. I think that moving forward (not in this PR) we want to make sure our APIs define very clearly the difference between the in memory JSON versus the on disk JSON. That is not at all apparent in the to_notebook_json method right now. But overall I am +1 on merging this.

@minrk
Copy link
Copy Markdown
Member

minrk commented Oct 29, 2013

Okay, then merging away. Thanks!

minrk added a commit that referenced this pull request Oct 29, 2013
@minrk minrk merged commit b31eb2f into ipython:master Oct 29, 2013
@jdfreder
Copy link
Copy Markdown
Contributor Author

Woohoo!

@jdfreder jdfreder deleted the versionconversion_nbconvert branch March 10, 2014 18:44
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
…vert

add upgrade / downgrade to nbformat
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.

5 participants