brechtm/rinohtype

References not resolved correctly for orphan pages

mason3k opened this issue · 2 comments

Is there an existing issue for this?

  • I have searched the existing issues

Sphinx or rinoh output

Traceback (most recent call last):
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/sphinx/events.py", line 96, in emit
    results.append(listener.handler(self.app, *args))
  File "/Users/sjones/Code/ADI/docs/source/_ext/directives/properties.py", line 32, in add_references
    make_refnode(
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/sphinx/util/nodes.py", line 551, in make_refnode
    node['refuri'] = (builder.get_relative_uri(fromdocname, todocname) +
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/rinoh/frontend/sphinx/__init__.py", line 175, in get_relative_uri
    return self.get_target_uri(to, typ)
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/rinoh/frontend/sphinx/__init__.py", line 169, in get_target_uri
    raise NoUri(docname, typ)
sphinx.errors.NoUri: ('shared/terms', None)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/sphinx/cmd/build.py", line 290, in build_main
    app.build(args.force_all, args.filenames)
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/sphinx/application.py", line 347, in build
    self.builder.build_all()
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/sphinx/builders/__init__.py", line 249, in build_all
    self.build(None, summary=__('all source files'), method='all')
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/sphinx/builders/__init__.py", line 360, in build
    self.write(docnames, list(updated_docnames), method)
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/rinoh/frontend/sphinx/__init__.py", line 257, in write
    self.write_document(entry)
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/rinoh/frontend/sphinx/__init__.py", line 263, in write_document
    rinoh_document = self.construct_rinohtype_document(data)
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/rinoh/frontend/sphinx/__init__.py", line 276, in construct_rinohtype_document
    doctree, docnames = self.assemble_doctree(doc, toctree_only)
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/rinoh/frontend/sphinx/__init__.py", line 210, in assemble_doctree
    self.env.resolve_references(largetree, indexfile, self)
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/sphinx/environment/__init__.py", line 658, in resolve_references
    self.apply_post_transforms(doctree, fromdocname)
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/sphinx/environment/__init__.py", line 675, in apply_post_transforms
    self.events.emit('doctree-resolved', doctree, docname)
  File "/Users/sjones/Code/ADI/.venv/lib/python3.9/site-packages/sphinx/events.py", line 107, in emit
    raise ExtensionError(__("Handler %r for event %r threw an exception") %
sphinx.errors.ExtensionError: Handler <function add_references at 0x1097abf70> for event 'doctree-resolved' threw an exception (exception: ('shared/terms', None))

Extension error (directives.properties):
Handler <function add_references at 0x1097abf70> for event 'doctree-resolved' threw an exception (exception: ('shared/terms', None))

Source files

rinoh/frontend/sphinx/__init__.py get_target_uri

Versions

rinohtype 0.5.4 (2022-06-17)
Sphinx 7.1.1
Python 3.9.6 (default, Nov 10 2023, 13:38:27) 
[Clang 15.0.0 (clang-1500.1.0.2.5)]
macOS-14.2.1-arm64-arm-64bit

I think this is because the page in question is an orphan. Thus, it will not be located when traversing the table of contents. I suggest the following change:

    def get_target_uri(self, docname, typ=None):
        if docname not in self.env.all_docs: # this is my code replacing the line below
        # if docname not in self._docnames:
            raise NoUri(docname, typ)
        else:
            return '%' + docname

Thanks for the bug report and suggested fix!

Can you provide a (preferably minimal) Sphinx project that triggers the bug?