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

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

Merged
merged 12 commits into from Oct 29, 2013

Conversation

jdfreder
Copy link
Member

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
Member 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).

@@ -32,6 +29,9 @@
nbformat_minor,
)

import reader
Copy link
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
Member 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
Member 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.

nb = v2.to_notebook_py(s, **kwargs)
elif nbf == 3:
nb = v3.to_notebook_py(s, **kwargs)
if nbf == 2 or nbf == 3:
Copy link
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
Member 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
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
Member 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
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
Member Author

Ah, like this:

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

@jdfreder
Copy link
Member Author

Tests added and comments addressed

try:
nb_dict = json.loads(s, **kwargs)
except ValueError:
raise NotJSONError("Notebook does not appear to be JSON: %r" % s[:16])
Copy link
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
Member 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
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
Member

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

@jdfreder
Copy link
Member Author

jdfreder commented Oct 7, 2013

Thanks all, comments addressed

@jdfreder
Copy link
Member Author

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

@minrk
Copy link
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
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
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
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
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
Member 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.

None yet

5 participants