readthedocs / sphinx-hoverxref

Sphinx extension to show tooltips with content embedded when hover a reference.
https://sphinx-hoverxref.readthedocs.io/
MIT License
100 stars 41 forks source link

Override domains and translator only in HTML output #62

Open humitos opened 4 years ago

humitos commented 4 years ago

We need to override the Domains and Translators only when building app.builder.format == 'html', otherwise it makes no sense and it could produce issues.

Reference: https://github.com/CEED/libCEED/issues/506#issuecomment-614405887

humitos commented 4 years ago

I built the project locally by myself and this is the whole output:

Traceback (most recent call last):
  File "/home/humitos/.pyenv/versions/3.8.2/envs/libCEED/lib/python3.8/site-packages/sphinx/cmd/build.py", line 280, in build_main
    app.build(args.force_all, filenames)
  File "/home/humitos/.pyenv/versions/3.8.2/envs/libCEED/lib/python3.8/site-packages/sphinx/application.py", line 348, in build
    self.builder.build_update()
  File "/home/humitos/.pyenv/versions/3.8.2/envs/libCEED/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 294, in build_update
    self.build(['__all__'], to_build)
  File "/home/humitos/.pyenv/versions/3.8.2/envs/libCEED/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 361, in build
    self.write(docnames, list(updated_docnames), method)
  File "/home/humitos/.pyenv/versions/3.8.2/envs/libCEED/lib/python3.8/site-packages/sphinx/builders/latex/__init__.py", line 283, in write
    doctree = self.assemble_doctree(
  File "/home/humitos/.pyenv/versions/3.8.2/envs/libCEED/lib/python3.8/site-packages/sphinx/builders/latex/__init__.py", line 344, in assemble_doctree
    self.env.resolve_references(largetree, indexfile, self)
  File "/home/humitos/.pyenv/versions/3.8.2/envs/libCEED/lib/python3.8/site-packages/sphinx/environment/__init__.py", line 572, in resolve_references
    self.apply_post_transforms(doctree, fromdocname)
  File "/home/humitos/.pyenv/versions/3.8.2/envs/libCEED/lib/python3.8/site-packages/sphinx/environment/__init__.py", line 584, in apply_post_transforms
    transformer.apply_transforms()
  File "/home/humitos/.pyenv/versions/3.8.2/envs/libCEED/lib/python3.8/site-packages/sphinx/transforms/__init__.py", line 86, in apply_transforms
    super().apply_transforms()
  File "/home/humitos/.pyenv/versions/3.8.2/envs/libCEED/lib/python3.8/site-packages/docutils/transforms/__init__.py", line 171, in apply_transforms
    transform.apply(**kwargs)
  File "/home/humitos/.pyenv/versions/3.8.2/envs/libCEED/lib/python3.8/site-packages/sphinx/transforms/post_transforms/__init__.py", line 44, in apply
    self.run(**kwargs)
  File "/home/humitos/.pyenv/versions/3.8.2/envs/libCEED/lib/python3.8/site-packages/sphinx/transforms/post_transforms/__init__.py", line 87, in run
    newnode = domain.resolve_xref(self.env, refdoc, self.app.builder,
  File "/home/humitos/rtfd/code/sphinx-hoverxref/hoverxref/domains.py", line 120, in resolve_xref
    return super().resolve_xref(env, fromdocname, builder, typ, target, node, contnode)
  File "/home/humitos/.pyenv/versions/3.8.2/envs/libCEED/lib/python3.8/site-packages/sphinx/domains/std.py", line 795, in resolve_xref
    return resolver(env, fromdocname, builder, typ, target, node, contnode)
  File "/home/humitos/rtfd/code/sphinx-hoverxref/hoverxref/domains.py", line 137, in _resolve_ref_xref
    docpath = self._get_docpath(builder, docname)
  File "/home/humitos/rtfd/code/sphinx-hoverxref/hoverxref/domains.py", line 50, in _get_docpath
    docpath = builder.get_outfilename(docname)
AttributeError: 'LaTeXBuilder' object has no attribute 'get_outfilename'
humitos commented 4 years ago

A temporal hacky solution at https://github.com/readthedocs/sphinx-hoverxref/pull/63