diff --git a/docs/sphinxext/ipython_directive.py b/docs/sphinxext/ipython_directive.py index d18a0be..e103197 100644 --- a/docs/sphinxext/ipython_directive.py +++ b/docs/sphinxext/ipython_directive.py @@ -560,6 +560,21 @@ class IpythonDirective(Directive): return savefig_dir, source_dir, rgxin, rgxout, promptin, promptout 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: + self.shell.IP.history_manager.reset() + self.shell.IP.execution_count = 1 + else: # haven't processed any docs yet + docs = [] + + # get config values (savefig_dir, source_dir, rgxin, rgxout, promptin, promptout) = self.get_config_options() @@ -578,6 +593,13 @@ class IpythonDirective(Directive): 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