Skip to content

Commit

Permalink
Merge pull request ipython#3298 from abakan/master
Browse files Browse the repository at this point in the history
Some fixes in IPython Sphinx directive

Made two fixes in plot_directive module:

 - a problem with interpreting pure python code with multiple levels of indentation
 - a problem with keeping track of visited files when restarting ipython line numbers
  • Loading branch information
minrk committed Jun 15, 2013
2 parents 9e08026 + 68c7a66 commit 93e6765
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions docs/sphinxext/ipython_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,12 @@ def process_pure_python(self, content):
else: # still on a multiline
modified = u'%s %s' % (continuation, line)
output.append(modified)

# if the next line is indented, it should be part of multiline
if len(content) > lineno + 1:
nextline = content[lineno + 1]
if len(nextline) - len(nextline.lstrip()) > 3:
continue
try:
mod = ast.parse(
'\n'.join(content[multiline_start:lineno+1]))
Expand Down Expand Up @@ -532,6 +538,8 @@ class IpythonDirective(Directive):

shell = EmbeddedSphinxShell()

seen_docs = set()

def get_config_options(self):
# contains sphinx configuration variables
config = self.state.document.settings.env.config
Expand All @@ -558,16 +566,13 @@ def setup(self):
# reset the execution count if we haven't processed this doc
#NOTE: this may be borked if there are multiple seen_doc tmp files
#check time stamp?
seen_docs = [i for i in os.listdir(tempfile.tempdir)
if i.startswith('seen_doc')]
if seen_docs:
fname = os.path.join(tempfile.tempdir, seen_docs[0])
docs = open(fname).read().split('\n')
if not self.state.document.current_source in docs:


if not self.state.document.current_source in self.seen_docs:
self.shell.IP.history_manager.reset()
self.shell.IP.execution_count = 1
else: # haven't processed any docs yet
docs = []
self.seen_docs.add(self.state.document.current_source)



# get config values
Expand All @@ -588,13 +593,6 @@ def setup(self):
store_history=False)
self.shell.clear_cout()

# write the filename to a tempfile because it's been "seen" now
if not self.state.document.current_source in docs:
fd, fname = tempfile.mkstemp(prefix="seen_doc", text=True)
fout = open(fname, 'a')
fout.write(self.state.document.current_source+'\n')
fout.close()

return rgxin, rgxout, promptin, promptout


Expand Down

0 comments on commit 93e6765

Please sign in to comment.