Resolve all paths in the include directive (#11650)

Because pytest's base tmp_path is also in /tmp, ``source`` here is relative path,
and thus is not properly converted to doc name.

So the test fails because `sources_reported` dict has a key like
``../../../pytest/pytest-0/directive-include/baz/baz``,
and ``assert "baz/baz" in sources_reported`` fails.

Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
This commit is contained in:
Dmitry Shachnev 2023-08-28 07:33:42 +03:00 committed by GitHub
parent 3037f8599c
commit 3e943d9e79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
from __future__ import annotations
import re
from os.path import abspath
from typing import TYPE_CHECKING, Any, cast
from docutils import nodes
@ -386,7 +387,7 @@ class Include(BaseInclude, SphinxDirective):
text = "\n".join(include_lines[:-2])
# The docname to pass into the source-read event
docname = self.env.path2doc(os_path(source))
docname = self.env.path2doc(abspath(os_path(source)))
# Emit the "source-read" event
arg = [text]
self.env.app.events.emit("source-read", docname, arg)