Skip to content

Commit

Permalink
logging: always show source locations as absolute paths
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dhellmann committed May 20, 2022
1 parent 3636776 commit 704f587
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sphinx/util/logging.py
Expand Up @@ -12,6 +12,7 @@

from sphinx.errors import SphinxWarning
from sphinx.util.console import colorize
from sphinx.util.osutil import abspath

if TYPE_CHECKING:
from sphinx.application import Sphinx
Expand Down Expand Up @@ -514,6 +515,8 @@ class WarningLogRecordTranslator(SphinxLogRecordTranslator):

def get_node_location(node: Node) -> Optional[str]:
(source, line) = get_source_line(node)
if source:
source = abspath(source)
if source and line:
return "%s:%s" % (source, line)
elif source:
Expand Down

0 comments on commit 704f587

Please sign in to comment.