Shell transformers ignored by %run script.ipy? #2265

astrozot opened this Issue Aug 7, 2012 · 4 comments


None yet

3 participants

astrozot commented Aug 7, 2012


I am writing an IPython extension that defines a new shell transformer, and I need to use this extension (and the syntax defined by the shell transformer) in a script. However, a simple test shows that the standard IPython %run command does not work as expected: when the commands in the script are pasted directly in the IPython prompt, everything is fine; if instead I run the IPython script with

%run script.ipy

the new syntax is not recognized (i.e., it looks like the new shell transformer is not used). From a check of the source I think the problem is in the run_cell function of core/ At the line 2575 of this file, I see an if test, "if len(cell.splitlines()) == 1", and this prevents the execution of the line

cell = self.prefilter_manager.prefilter_lines(cell) + '\n'

I do not know the IPython source at all, and I am not sure why the original if is at all there, but I think that the line above, if executed, would solve my problem.


The reason we handle single lines differently is because with multi-line blocks, it's very tricky to work out what's in a string, and we must avoid transforming anything in strings:

a = """
should we "transform" this line?
''' or "this" one?
how about this?

But I am hoping to find time to try to improve that part of the code.

minrk commented Jan 20, 2013

@takluyver is this another issue that will be addressed by your #2447?


I'll try to make things better in this respect, but no promises at present.

minrk commented Jan 20, 2013

No worries, I'm just trying to make sure all the appropriate Issues are linked up, so we don't have a bunch of orphans lying open after they have actually been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment