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

Code_prettify does not recognize IPython magic commands #1018

Closed
catch22 opened this issue Jul 6, 2017 · 3 comments · Fixed by #1019 or #1162
Closed

Code_prettify does not recognize IPython magic commands #1018

catch22 opened this issue Jul 6, 2017 · 3 comments · Fixed by #1019 or #1162

Comments

@catch22
Copy link

catch22 commented Jul 6, 2017

E.g., using %%time raises the following error, which is probably straight from PyYapf:

[code_prettify]
Error: SyntaxError
invalid syntax (, line 1)

Not sure if you feel this is a code_prettify issue or a yapf issue.

@jfbercher
Copy link
Member

This happens because yapf reformats python code and the IPython magics are not recognized. So this is really a syntax error.

It could be possible to preprocess the text from code cells to remove the magics (while leaving an anchor) and reinsert the magics after reformatting (but clearly this is not at my top todo). if somebody wants to give it a try, welcome!

@jcb91
Copy link
Member

jcb91 commented Jul 6, 2017

I've looked at this before & recall concluding that the necessary preprocessing would have to be done by the relevant kernel. The ipython kernel does this line-by-line, but I couldn't find a simple way to separate the preprocessing from the execution, iirc.

jfbercher added a commit to jfbercher/jupyter_contrib_nbextensions that referenced this issue Jul 8, 2017
jfbercher added a commit that referenced this issue Jul 14, 2017
[code_prettify] added support for IPython magics, cf #1018
@catch22
Copy link
Author

catch22 commented Jul 18, 2017

@jfbercher Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants