mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Split `write_temporary_file()
from
save_traceback()
`
This commit is contained in:
@@ -113,10 +113,16 @@ def format_traceback(app: Sphinx | None, exc: BaseException) -> str:
|
||||
def save_traceback(app: Sphinx | None, exc: BaseException) -> str:
|
||||
"""Save the given exception's traceback in a temporary file."""
|
||||
output = format_traceback(app=app, exc=exc)
|
||||
filename = write_temporary_file(output)
|
||||
return filename
|
||||
|
||||
|
||||
def write_temporary_file(content: str) -> str:
|
||||
"""Write content to a temporary file and return the filename."""
|
||||
with tempfile.NamedTemporaryFile(
|
||||
suffix='.log', prefix='sphinx-err-', delete=False
|
||||
'w', encoding='utf-8', suffix='.log', prefix='sphinx-err-', delete=False
|
||||
) as f:
|
||||
f.write(error_info(last_msgs, exts_list, exc_format).encode('utf-8'))
|
||||
f.write(content)
|
||||
|
||||
return f.name
|
||||
|
||||
|
@@ -2,22 +2,10 @@ from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import traceback
|
||||
from tempfile import NamedTemporaryFile
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sphinx._cli.util.errors import format_traceback
|
||||
from sphinx._cli.util.errors import save_traceback
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sphinx.application import Sphinx
|
||||
|
||||
|
||||
def save_traceback(app: Sphinx | None, exc: BaseException) -> str:
|
||||
"""Save the given exception's traceback in a temporary file."""
|
||||
with NamedTemporaryFile(
|
||||
'w', encoding='utf-8', suffix='.log', prefix='sphinx-err-', delete=False
|
||||
) as f:
|
||||
f.write(format_traceback(app, exc))
|
||||
return f.name
|
||||
__all__ = 'save_traceback', 'format_exception_cut_frames'
|
||||
|
||||
|
||||
def format_exception_cut_frames(x: int = 1) -> str:
|
||||
|
Reference in New Issue
Block a user