[IPython-dev] ipython sphinx directive

VáclavŠmilauer eudoxos@arcig...
Sun Dec 13 09:07:07 CST 2009


> The directive does not yet live in any public repo, but we can/should
> correct that fairly easily.  I can add it to the mpl sphinxext for the
> time being, or would you rather it live in ipython bzr Fernando?  Like
> pylab, it is currently a hybrid monster between ipython and pyplot.
> It does need some cleaning -- primarily we should factor out the pure
> ipython directive from the part that is mpl/pyplot aware, or at least
> set it up so it can run w/o mpl for folks who just want to the ipython
> part.   The current version is also just for the 0.10 line and not
> ipython HEAD, so we need to figure out what branch it should be on,
> and eventually port it to the HEAD (or whatever it is you bzr types
> call the current development branch)
We call it trunk, also ;-) I don't mind which repo it is in, I have no
write access to either.
 
> If you could
> incorporate your changes into the latest and then post a patch, that
> would be most helpful.

For now, I just added rc_override as module variable, which can
be overridden (as in the file I referenced in my last post); it
is diff'ed against the version you just posted.

--- ipython_directive.py.new.orig	2009-12-13 15:45:53.000000000 +0100
+++ ipython_directive.py	2009-12-13 15:59:48.838998325 +0100
@@ -21,6 +21,7 @@
 
 
 COMMENT, INPUT, OUTPUT =  range(3)
+rc_override={}
 rgxin = re.compile('In \[(\d+)\]:\s?(.*)\s*')
 rgxout = re.compile('Out\[(\d+)\]:\s?(.*)\s*')
 fmtin = 'In [%d]:'
@@ -145,7 +146,7 @@
             argv, self.user_ns, self.user_glocal_ns, embedded=True,
             #shell_class=IPython.Shell.InteractiveShell,
             shell_class=MatplotlibShell,
-            rc_override=dict(colors = 'NoColor'))
+            rc_override=dict(colors = 'NoColor', **rc_override ))
 
         self.input = ''
         self.output = ''

> I'm pretty sure the output prompt is formatted properly in the version
> I posted and the one attached here, so I'd like to clear up that
> problem before integrating your work.  I knew someone would want a
> custom prompt -- I just didn't expect it so soon 

It must be some problem on ipython's part... I don't put the Out lines
to the block at all. As much as I try to override the output prompt,
it doesn't do anything (input is overridden just fine, though);

Yade has by default Yade [1]: input promps and ' ->  [1]:' output
prompts; it is no big deal, but I wanted to keep that in the docs
the same.

# in sphinx config file:

  import ipython_directive as id
  id.rgxin =re.compile(r'(?:In |Yade )\[(\d+)\]:\s?(.*)\s*')
  id.rgxout=re.compile(r'(?:Out| ->  )\[(\d+)\]:\s?(.*)\s*')
  id.fmtin ='Yade [%d]:'
  id.fmtout=' ->  [%d]:'

  id.rc_override=dict(
    prompt_in1="Yade [\#]:",
    prompt_in2="     .\D..",
    prompt_out=" ->  [\#]:"
  )

  import ipython_console_highlighting as ich
  ich.IPythonConsoleLexer.input_prompt=
     re.compile("(Yade \[[0-9]+\]: )|(   \.\.\.+:)")
  ich.IPythonConsoleLexer.output_prompt=
     re.compile("(( ->  )|(Out)\[[0-9]+\]: )|(   \.\.\.+:)")
  ich.IPythonConsoleLexer.continue_prompt=re.compile("   \.\.\.+:")


Cheers, Vaclav



More information about the IPython-dev mailing list