Skip to content

Commit 704f587

Browse files
committed
logging: always show source locations as absolute paths
Nodes attached to the parse tree via the `include` directive have their `source` attribute set to the relative path of the included file. Other nodes in the tree use the full absolute path. For consistent logging, ensure that the node location is always expressed as an absolute path, when the filename is known. See sphinx-contrib/spelling#153 for an example of the effect of the original problem.
1 parent 3636776 commit 704f587

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

sphinx/util/logging.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from sphinx.errors import SphinxWarning
1414
from sphinx.util.console import colorize
15+
from sphinx.util.osutil import abspath
1516

1617
if TYPE_CHECKING:
1718
from sphinx.application import Sphinx
@@ -514,6 +515,8 @@ class WarningLogRecordTranslator(SphinxLogRecordTranslator):
514515

515516
def get_node_location(node: Node) -> Optional[str]:
516517
(source, line) = get_source_line(node)
518+
if source:
519+
source = abspath(source)
517520
if source and line:
518521
return "%s:%s" % (source, line)
519522
elif source:

0 commit comments

Comments
 (0)