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

<Plug>JupyterExecute is executing the next cell instead of the current one #8

Open
IndianBoy42 opened this issue Nov 26, 2021 · 7 comments

Comments

@IndianBoy42
Copy link

vim.api.nvim_buf_set_keymap(0, "n", "<localleader>j", "<Plug>JupyterExecute", {})
# %%
import numpy as np
import scipy as sp

# %%
print("Hello World")

Putting my cursor on import and hitting <localleader>j will cause the second cell to execute. What could be the problem?

@fecet
Copy link

fecet commented Dec 7, 2021

same issue

@fecet
Copy link

fecet commented Dec 8, 2021

A rough workaround is evoke function of vim-ipython-cell:

function! PrevExecNextCell()
    call IPythonCellPrevCell()
    call jupyter_ascending#execute()
    call IPythonCellNextCell()
endfunction

nmap <leader><CR> :call PrevExecNextCell()<CR>

hope someone have a more elegant solution

@jvivian
Copy link

jvivian commented Dec 29, 2021

hope someone have a more elegant solution

@fecet @IndianBoy42

After taking a look at the code, it appears to be an issue with the assumptions for how the file starts: https://github.com/untitled-ai/jupyter_ascending/blob/main/jupyter_ascending/requests/execute.py#L20

I don't know enough about jupytext as this is my first time trying to use it, but I assume you need the header at the top for it to work correctly, so you just need to remove the very first # %% in order to trigger the second specified case.

This worked for me, hopefully it does for you as well.

Cheers

@ViRu-ThE-ViRuS
Copy link

@jvivian this solutions works! Thanks for the this workaround :)

@IndianBoy42
Copy link
Author

So if i'm understanding right, not having the first cell marker on the first line should make it work?

But my notebook files are generally created by jupytext which does add a leading cell marker, so could it be fixed in jupyter_ascending?

@jvivian
Copy link

jvivian commented Dec 30, 2021

So if i'm understanding right, not having the first cell marker on the first line should make it work?

I used the jupyter_ascending.scripts.make_pairs function to generate the .py/ipynb pairs, which puts a jupytext header at the top. If you remove the first # %% below the header (---), it should work. Example below

(base) jvivian@DESKTOP-8U6S9I6:~/Dropbox/Learning/Statistics/Bayesian-modeling-and-computation$ head Notebooks/03_Linear_models.sync.py -n 20
# ---
# jupyter:
#   jupytext:
#     text_representation:   
#       extension: .py       
#       format_name: percent 
#       format_version: '1.3'
#       jupytext_version: 1.3.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd

# %%
print('hello world')

@zplizzi
Copy link
Contributor

zplizzi commented Jan 20, 2023

This was maybe hopefully fixed in the most recent update of the jupyter_ascending plugin - there was a numbering bug. If anyone happens to be able to confirm or deny, lmk!

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

No branches or pull requests

5 participants