Hi All,
I've developed a "bokeh-gallery" extension to help with automating our
project documentation. It is used to generate the gallery below:
http://bokeh.pydata.org/en/latest/docs/gallery.html
After trying to update from Sphinx 1.5.x to 1.6.x, I get the following
exception:
Exception occurred:
File
"/Users/bryan/anaconda/lib/python3.6/site-packages/Sphinx-1.6.2-py3.6.egg/sphinx/environment/__init__.py"
, line 785, in docname
return self.temp_data['docname']
KeyError: 'docname'
The full code for the extension is here:
https://github.com/bokeh/bokeh/blob/master/bokeh/sphinxext/bokeh_gallery.py
But i've included the just the "run: code, which seems the be the problem
below. (It's been updated with a workaround I describe below) The extension
works by reading a JSON config that lists gallery files, then reading doc
for all these in a loop. Then it generates some RST txt with ".. image"
links to the docs generated in the links, which it passes to self._parse.
It's this step that fails. Evidently now the value of env.docname is erased
during the loop that reads docs. When self._parse is called with the
generated RST txt, the image collector tries to access env.docname,
resulting in the exception above.
I can "fix" this by saving the docname before the loop, then setting env.
temp_data['docname'] = current_docname as seen below. But this seems like a
pretty bad workaround. What is the right way to do what I am doing, which
is basically:
* read in a bunch of files and generate docs for them
* generate a string of RST text for the current doc
* parse that dynamically generated RST text
Thanks for any guidance,
Bryan
class BokehGalleryDirective(BokehDirective):
has_content = False
required_arguments = 1
def run(self):
env = self.state.document.settings.env
app = env.app
current_docname = env.docname
docdir = dirname(env.doc2path(current_docname))
dest_dir = join(docdir, "gallery")
ensuredir(dest_dir)
specpath = join(docdir, self.arguments[0])
env.note_dependency(specpath)
spec = json.load(open(specpath))
details = spec['details']
details_iter = status_iterator(details,
'copying gallery files... ',
"brown",
len(details),
app.verbosity,
lambda x: x['name'] + ".py")
env.gallery_updated = []
for detail in details_iter:
src_path = abspath(join("..", detail['path']))
dest_path = join(dest_dir, detail['name'] + ".py")
# sphinx pickled env works only with forward slash
docname = join(env.app.config.bokeh_gallery_dir, detail['name'
]).replace("\\","/")
try:
copyfile(src_path, dest_path)
except OSError as e:
raise SphinxError('cannot copy gallery file %r, reason: %s'
% (src_path, e))
try:
env.clear_doc(docname)
env.read_doc(docname, app=app)
env.gallery_updated.append(docname)
except Exception as e:
raise SphinxError('failed to read gallery doc %r, reason:
%s' % (docname, e))
names = [detail['name']for detail in details]
rst_text = GALLERY_PAGE.render(names=names)
# current docname has been cleared, not sure a better way to restore
env.temp_data['docname'] = current_docname
return self._parse(rst_text, "<bokeh-gallery>")
--
You received this message because you are subscribed to the Google Groups
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.