Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Cell title is not saved #29

@Paul-Aime

Description

@Paul-Aime

When creating a notebook with vim and jupytext.vim (vim notebook.ipynb), if not any cell has a title when first writing the file (:w), then following writings of the file will make titles disappear. It does not happen if a title was present the first time the notebook was written.

What I call a title here is the short description of the cell that can be written next to # %% in a py:percent format.

# %% imports        <-- "title"
import os, sys

All of my configuration wrt jupytext is as follows:

Plug 'goerz/jupytext.vim'
let g:jupytext_fmt = 'py:percent'

Reproduce

  1. vi notebook.ipynb, then type:
# %%
import os, sys
  1. :w write the file
  2. Add an header
# %% imports        <-- title added
import os, sys
  1. :w write the file
  2. :e reload the file, the header disappeared

Diagnostics

vim --version VIM - Vi IMproved 8.1 (2018 May 18, compiled Sep 20 2021 11:42:42) Included patches: 1-2269 Modified by [email protected] Compiled by [email protected] Huge version with GTK3 GUI. Features included (+) or not (-): +acl -farsi -mouse_sysmouse -tag_any_white +arabic +file_in_path +mouse_urxvt +tcl +autocmd +find_in_path +mouse_xterm +termguicolors +autochdir +float +multi_byte +terminal -autoservername +folding +multi_lang +terminfo +balloon_eval -footer -mzscheme +termresponse +balloon_eval_term +fork() +netbeans_intg +textobjects +browse +gettext +num64 +textprop ++builtin_terms -hangul_input +packages +timers +byte_offset +iconv +path_extra +title +channel +insert_expand +perl +toolbar +cindent +job +persistent_undo +user_commands +clientserver +jumplist +postscript +vartabs +clipboard +keymap +printer +vertsplit +cmdline_compl +lambda +profile +virtualedit +cmdline_hist +langmap -python +visual +cmdline_info +libcall +python3 +visualextra +comments +linebreak +quickfix +viminfo +conceal +lispindent +reltime +vreplace +cryptv +listcmds +rightleft +wildignore +cscope +localmap -ruby +wildmenu +cursorbind +lua +scrollbind +windows +cursorshape +menu +signs +writebackup +dialog_con_gui +mksession +smartindent +X11 +diff +modify_fname +sound -xfontset +digraphs +mouse +spell +xim +dnd +mouseshape +startuptime +xpm -ebcdic +mouse_dec +statusline +xsmp_interact +emacs_tags +mouse_gpm -sun_workshop +xterm_clipboard +eval -mouse_jsbterm +syntax -xterm_save +ex_extra +mouse_netterm +tag_binary +extra_search +mouse_sgr -tag_old_static system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" user exrc file: "$HOME/.exrc" system gvimrc file: "$VIM/gvimrc" user gvimrc file: "$HOME/.gvimrc" 2nd user gvimrc file: "~/.vim/gvimrc" defaults file: "$VIMRUNTIME/defaults.vim" system menu file: "$VIMRUNTIME/menu.vim" fall-back for $VIM: "/usr/share/vim" Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Wdate-time -g -O2 -fdebug-prefix-map=/build/vim-RjZCd2/vim-8.1.2269=. -fstack-protector-strong -Wformat -Werror=format-security -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 Linking: gcc -Wl,-E -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lnsl -lselinux -lcanberra -lacl -lattr -lgpm -ldl -L/usr/lib -llua5.2 -Wl,-E -fstack-protector-strong -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu/perl/5.30/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python3.8/config-3.8-x86_64-linux-gnu -lpython3.8 -lcrypt -lpthread -ldl -lutil -lm -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lm
  • Operating system information (e.g. uname -a):
$ uname -a
Linux IMT-21092020 5.11.0-38-generic #42~20.04.1-Ubuntu SMP Tue Sep 28 20:41:07 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • python --VV:
$ python -V
Python 3.9.7
  • Are you using Anaconda?
$ which jupytext
/home/p20aime/miniconda3/bin/jupytext
  • Put let g:jupytext_print_debug_msgs = 1 in your ~/.vimrc. What is the output of :messages when reproducing the problem?

Writing the file the first time (:w) without header:

DBG: overwriting /tmp/python/nb3.py
DBG: Updating notebook from /tmp/python/nb3.py
DBG: cmd: jupytext --from=py:percent --to=ipynb --update '/tmp/python/nb3.py'
DBG: [jupytext] Reading /tmp/python/nb3.py in format py:percent^@[jupytext] Writing /tmp/python/nb3.ipynb
nb3.ipynb saved via jupytext.

Writing an header and writing the file (:w):

DBG: overwriting /tmp/python/nb3.py
DBG: Updating notebook from /tmp/python/nb3.py
DBG: cmd: jupytext --from=py:percent --to=ipynb --update '/tmp/python/nb3.py'
DBG: [jupytext] Reading /tmp/python/nb3.py in format py:percent^@[jupytext] Writing /tmp/python/nb3.ipynb (destination f
ile updated)
nb3.ipynb saved via jupytext.
  • Does converting the notebook to/from ipynb with jupytext on the command line work? Does it work when you set g:jupytext_command in ~/.vimrc to be the exact some jupytext that you used manually, with the exact same version of Python?

When trying to replicate steps with command line it does work. That is weird because when doing through vim only then an inspection of the temporary .py file shows that it indeed contains the headers.

$ vi notebook.ipynb

$ jupytext --to py:percent notebook.ipynb
[jupytext] Reading notebook.ipynb in format ipynb
[jupytext] Writing notebook.py in format py:percent

$ cat notebook.ipynb
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00069045",
   "metadata": {},                    <-- no title
   "outputs": [],
   "source": [
    "import os"
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "cell_metadata_filter": "-all",
   "main_language": "python",
   "notebook_metadata_filter": "-all"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

$ vi notebook.py
# Adding a title to the cell

$ cat notebook.py
# %% imports
import os

$ jupytext --from py:percent --to notebook --update notebook.py
[jupytext] Reading notebook.py in format py:percent
[jupytext] Writing notebook.ipynb (destination file updated)

$ cat notebook.ipynb
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00069045",
   "metadata": {
    "title": "imports"                    <- title
   },
   "outputs": [],
   "source": [
    "import os"
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "cell_metadata_filter": "-all",
   "main_language": "python",
   "notebook_metadata_filter": "-all"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

$ vi notebook.ipynb
# I can see the title OK

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions