[IPython-dev] Thoughts on the notebook format for version control

MinRK benjaminrk at gmail.com
Sat Nov 5 23:14:41 EDT 2011


Shall I push the sort_keys to master? It's a one-line change in
nbformat/v2/nbjson.py:

diff --git a/IPython/nbformat/v2/nbjson.py b/IPython/nbformat/v2/nbjson.py
index b86297d..e67bec3 100644
--- a/IPython/nbformat/v2/nbjson.py
+++ b/IPython/nbformat/v2/nbjson.py
@@ -48,6 +48,7 @@ class JSONWriter(NotebookWriter):
     def writes(self, nb, **kwargs):
         kwargs['cls'] = BytesEncoder
         kwargs['indent'] = 4
+        kwargs['sort_keys'] = True
         return json.dumps(nb, **kwargs)


Since loading from JSON is not sensitive to ordering, this can't have any
effect on the content of existing notebooks, other than a reorder of keys
in the file the first time it is saved.

-MinRK

On Sat, Nov 5, 2011 at 20:08, MinRK <benjaminrk at gmail.com> wrote:

>
>
> On Sat, Nov 5, 2011 at 19:58, Fernando Perez <fperez.net at gmail.com> wrote:
>
>> On Sat, Nov 5, 2011 at 7:41 PM, MinRK <benjaminrk at gmail.com> wrote:
>> > On Sat, Nov 5, 2011 at 18:58, Fernando Perez <fperez.net at gmail.com>
>> wrote:
>> >>
>>
>> > There is a *huge* disadvantage in portability to notebooks not being
>> single
>> > files.  I think this still makes
>> > sense, though.  I would treat the output as a 'cache' (along the lines
>> of
>> > .pyc / __cache__),
>> > rather than considering the notebook itself as a multi-file format.
>>  And you
>> > should be able
>> > to embed the outputs in a single file if you want, for easier
>> portability.
>> > Doing it this way would not require changing the notebook format,
>> because
>> > current (output-included)
>> > notebooks would still comply with the spec.
>>
>> I agree that it's a big inconvenience for everyday, non-VC use.  I
>> like the idea of making it optional, it can be a flag set in the
>> metadata dict, that indicates whether to keep outputs in the cache or
>> internally (and also to offer the single-file download option).
>>
>>
>> > I think this sounds like a good start, with the only change that we
>> still
>> > allow (optionally) outputs in a single file via the download button,
>> rather
>> > than the notebook format being canonically multifile, which is just too
>> > painful.
>>
>> Yes, that sounds like a good balance between everyday usability and
>> being VC-friendly.
>>
>> > I think the key-order issue you mention in the addendum is easily fixed
>> by
>> > specifying `sort_keys=True` in the json dump.
>>
>> That's great to hear, I thought we'd have to do the sorting manually.
>> That's a change we should make right away then, since it doesn't
>> change the format.  People can manually remove outputs from their
>> notebooks and this will help if they use VC a little bit (even if the
>> singe-line cells issue isn't fixed yet).
>>
>
> Yes, and if I recall, for now you can just hit 'ClearAll outputs' prior to
> save/commit, to remove output from VCS.
>
>
>>
>> Thanks for the feedback!
>>
>> Cheers,
>>
>> f
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20111105/c824bbfb/attachment.html>


More information about the IPython-dev mailing list