mirror of https://github.com/Textualize/rich.git
fix traceback chdir issue
This commit is contained in:
parent
c1055cecda
commit
a0b6982092
|
@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- Fix double line tree guides on Windows
|
||||
- Fixed Tracebacks ignoring initial blank lines
|
||||
- Partial fix for tracebacks not finding source after chdir
|
||||
|
||||
### Added
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Rich text and beautiful formatting in the terminal."""
|
||||
|
||||
import os
|
||||
from typing import Any, IO, Optional, TYPE_CHECKING
|
||||
|
||||
__all__ = ["get_console", "reconfigure", "print", "inspect"]
|
||||
|
@ -10,6 +11,8 @@ if TYPE_CHECKING:
|
|||
# Global console used by alternative print
|
||||
_console: Optional["Console"] = None
|
||||
|
||||
_IMPORT_CWD = os.path.abspath(os.getcwd())
|
||||
|
||||
|
||||
def get_console() -> "Console":
|
||||
"""Get a global :class:`~rich.console.Console` instance. This function is used when Rich requires a Console,
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
# pragma: no cover
|
||||
|
||||
from time import time
|
||||
|
||||
import contextlib
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def timer(subject: str = "time"): # pragma: no cover
|
||||
def timer(subject: str = "time"):
|
||||
"""print the elapsed time. (only used in debugging)"""
|
||||
start = time()
|
||||
yield
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import os.path
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
from dataclasses import dataclass, field
|
||||
from textwrap import indent
|
||||
import inspect
|
||||
from traceback import walk_tb
|
||||
from types import TracebackType
|
||||
from typing import Callable, Dict, Iterable, List, Optional, Type
|
||||
|
@ -257,6 +257,8 @@ class Traceback:
|
|||
stacks: List[Stack] = []
|
||||
is_cause = False
|
||||
|
||||
from rich import _IMPORT_CWD
|
||||
|
||||
while True:
|
||||
stack = Stack(
|
||||
exc_type=str(exc_type.__name__),
|
||||
|
@ -279,9 +281,10 @@ class Traceback:
|
|||
for frame_summary, line_no in walk_tb(traceback):
|
||||
filename = frame_summary.f_code.co_filename
|
||||
if filename and not filename.startswith("<"):
|
||||
filename = os.path.abspath(filename) if filename else "?"
|
||||
if not os.path.isabs(filename):
|
||||
filename = os.path.join(_IMPORT_CWD, filename)
|
||||
frame = Frame(
|
||||
filename=filename,
|
||||
filename=filename or "?",
|
||||
lineno=line_no,
|
||||
name=frame_summary.f_code.co_name,
|
||||
locals={
|
||||
|
|
Loading…
Reference in New Issue