<div dir="ltr">On Fri, Dec 7, 2012 at 1:27 AM, Brian Granger <span dir="ltr"><<a href="mailto:ellisonbg@gmail.com" target="_blank">ellisonbg@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">> I've enhanced the test failure stack traces such that the function's<br>

> "filename" (like <ipython-input-DD-HHHHHHHHHHHH>) links to the cell that<br>
> defines that code. That makes it easy to click close to the definition of a<br>
> failing test or function. Even better would be linking directly to the line<br>
> of code in question… :)  Unfortunately the current implementation has a<br>
> visual bug when linking to an anchor: the top IPython bar shifts up about<br>
> 0.3em (it shifts back if you hit the empty fragment, "#").<br>
<br>
</div>Ahh, this is a nice feature.  Can you describe a bit more about how<br>
you track this information as it flows though the code.  Do the cell<br>
ids get sent to the kernel?  What does the kernet do with them?<br>
</blockquote><div><br></div><div>When each cell gets compiled, ipython generates a (IPython.core.compilerop.code_name, I think) and uses that the (pseudo-)filename associated with the code object. I don't have to track it myself:<br>
</div><div>1. The traceback lists the (pseudo-)filename in a pretty recognizeable way:  re.search(<span class="">r'ipython-input-(?P<cell_eval_order>\d+)-[0-9a-f]{12}'</span><span class=""></span>, …)<br></div>
<div>2. Each cell has the cell_eval_order in square brackets beside it.<br></div><div><br></div><div>All I have to do is link the two. :) The kernel itself doesn't need to know anything, I'm just taking advantage of the predictability of the HTML output. One could as easily do all the linkifying in JS instead of beforehand in the plugin's Python code.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> I do have a few questions up-front:<br><div class="im">
> 1. Is there a better way than peeking at sys.displayhook to determine what<br>
> kind of output to produce?<br>
<br>
</div>I am not quite sure what you mean and how you "peek" and<br>
sys.displayhook for this.<br>
</blockquote><div><br></div><div>For now, I stole a page from <a href="https://github.com/catherinedevlin/ipython_doctester">https://github.com/catherinedevlin/ipython_doctester</a> with respect to displaying text/plain when using ipython console vs displaying text/html+application/javascript in the notebook. But it feels like a REALLY ugly hack (and requires pyzmq to be installed just for an import to see that we're NOT using the notebook…).<br>
<br></div><div>The particular code is <a href="https://github.com/taavi/ipython_nose/blob/master/ipython_nose.py#L293">https://github.com/taavi/ipython_nose/blob/master/ipython_nose.py#L293</a> .<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im">
> 2. I'd really like to have cell anchor generation happen always. Seems like<br>
> it would be useful to provide intra-notebook links to cells. I'm not sure<br>
> how one would manage those links as the execution order evolves, though. For<br>
> this extension, that migration is actually a good thing, as the anchor<br>
> points to the code that was actually run even if it's no longer visible.<br>
<br>
</div>I am trying to understand what the usage cases are.  Would these links<br>
be typed in by hand by a user?  If so, we would want the ids to have a<br>
human readable form.  If they are always generated by code they could<br>
be ugly.<br></blockquote><div><br></div><div>Nope, these are just the automatically-generated links already mentioned above. They're there just so the user can click on a psuedo-filename and (hopefully) have the browser scroll to the cell that contained the test code itself.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
The other thing we have to keep in mind is that we can't ever couple<br>
the kernel to the notebook frontend.  That is, the kernel can't ever<br>
know about these cell ids in any formal way.<br></blockquote><div><br></div><div>That makes sense. I'm more interested in the notebook frontend being able to take advantage of the kernel's existing data, which is sort of the opposite thing (I think).<br>
<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im">> 3. I'd love to have a consistent interface to stream something like stdout<br>
> character-wise instead of line-wise. Right now it's hacked to hook stdout<br>
> directly on the console, and with even more horrible jQuery machinations on<br>
> the notebook side.<br>
<br>
</div>Can't you call flush to do this?  Can you describe this a bit more.<br>
Again, not following how all of this is used.  It sounds messy...<br></blockquote><div><br></div><div>Nope, somehow whenever I try to write a single char for each test, it comes out on its own line (wrapped in its own pre tag).<br>
<br></div><div>Huh. But it looks like if I do this in an ipython notebook cell:<br>import sys<br>import time<br>sys.stdout.write('a')<br>sys.stdout.flush()<br>time.sleep(5)<br>sys.stdout.write('b')<br><br>
</div><div>it works! So there must be something else going on causing the extra tags. Thanks for pointing out that it OUGHT to work! <a href="https://github.com/taavi/ipython_nose/issues/4">https://github.com/taavi/ipython_nose/issues/4</a><br>
</div><div> <br></div>-- <br></div>taa<br>/*eof*/<br>
</div></div>