mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Improve `get_location()
` (#12502)
This commit is contained in:
parent
00cc5f6585
commit
21f7006d22
@ -425,7 +425,14 @@ class SphinxDirective(Directive):
|
||||
|
||||
def get_location(self) -> str:
|
||||
"""Get current location info for logging."""
|
||||
return ':'.join(str(s) for s in self.get_source_info())
|
||||
source, line = self.get_source_info()
|
||||
if source and line:
|
||||
return f'{source}:{line}'
|
||||
if source:
|
||||
return f'{source}:'
|
||||
if line:
|
||||
return f'<unknown>:{line}'
|
||||
return ''
|
||||
|
||||
def parse_content_to_nodes(self) -> list[Node]:
|
||||
"""Parse the directive's content into nodes."""
|
||||
@ -529,7 +536,14 @@ class SphinxRole:
|
||||
|
||||
def get_location(self) -> str:
|
||||
"""Get current location info for logging."""
|
||||
return ':'.join(str(s) for s in self.get_source_info())
|
||||
source, line = self.get_source_info()
|
||||
if source and line:
|
||||
return f'{source}:{line}'
|
||||
if source:
|
||||
return f'{source}:'
|
||||
if line:
|
||||
return f'<unknown>:{line}'
|
||||
return ''
|
||||
|
||||
|
||||
class ReferenceRole(SphinxRole):
|
||||
|
@ -589,12 +589,10 @@ class WarningLogRecordTranslator(SphinxLogRecordTranslator):
|
||||
|
||||
def get_node_location(node: Node) -> str | None:
|
||||
source, line = get_source_line(node)
|
||||
if source:
|
||||
source = abspath(source)
|
||||
if source and line:
|
||||
return f"{source}:{line}"
|
||||
return f"{abspath(source)}:{line}"
|
||||
if source:
|
||||
return f"{source}:"
|
||||
return f"{abspath(source)}:"
|
||||
if line:
|
||||
return f"<unknown>:{line}"
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user