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

evaluating cells with cell-level magics with emacs-jupyter raises an UsageError #18

Closed
martibosch opened this issue Feb 16, 2023 · 3 comments

Comments

@martibosch
Copy link

Consider the following notebook with an associated emacs-jupyter REPL:

# %%
%%timeit

N = 10000
list(range(N)) * 2

# %%
%time list(range(10000)) * 2

running code-cells-eval in the first cell raises a Jupyter error "UsageError: Line magic function %%timeit not found.". Instead, manually selecting the four lines of the first cell and running jupyter-eval-region runs correctly, giving the execution time in a buffer named *jupyter-output*.

The second cell runs properly (createing two buffers, one named *jupyter-result* with the result and another named *jupyter-output* with the measured execution time).

How can this be fixed? I suppose that it is an issue of how code-cells sends the cell code to emacs-jupyter given that jupyter-eval-region works properly.

Thank you in advance. Best,
Martí

@astoff
Copy link
Owner

astoff commented Feb 16, 2023

Puzzling. code-cells-eval sends the whole cell, including the comment header # %%, to the REPL. Could that be the cause of the trouble? In this case one would have to argue that this is not a bug in Jupyter...

@martibosch
Copy link
Author

I suppose that including the comment header is indeed the cause of the trouble, because when I select the whole cell including the commend header and run it using jupyter-eval-region, I get the same error.

I therefore do not think that it is a bug in Jupyter as cell magic is supposed to be at the first line of the cell (regardless of comments). In any case, it is not a big deal and for other users encountering this issue, using the jupyter-eval-region approach as workaround is quite straightforward.

@astoff
Copy link
Owner

astoff commented Feb 28, 2023

I guess I could add an option to modify this behavior, or even hard-code it. But I need to think of possible side-effects.

@astoff astoff closed this as completed in a747c81 Nov 19, 2023
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

2 participants