mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge pull request #383 from Textualize/fix-devtools-paths
Ensure filename is passed to devtools from __init__
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import inspect
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from rich.console import RenderableType
|
from rich.console import RenderableType
|
||||||
@@ -9,7 +10,9 @@ def log(*args: object, verbosity: int = 0, **kwargs) -> None:
|
|||||||
from ._context import active_app
|
from ._context import active_app
|
||||||
|
|
||||||
app = active_app.get()
|
app = active_app.get()
|
||||||
app.log(*args, verbosity=verbosity, **kwargs)
|
|
||||||
|
caller = inspect.stack()[1]
|
||||||
|
app.log(*args, verbosity=verbosity, _textual_calling_frame=caller, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def panic(*args: RenderableType) -> None:
|
def panic(*args: RenderableType) -> None:
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ class App(DOMNode):
|
|||||||
self,
|
self,
|
||||||
*objects: Any,
|
*objects: Any,
|
||||||
verbosity: int = 1,
|
verbosity: int = 1,
|
||||||
caller: inspect.FrameInfo | None = None,
|
_textual_calling_frame: inspect.FrameInfo | None = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Write to logs.
|
"""Write to logs.
|
||||||
@@ -216,6 +216,8 @@ class App(DOMNode):
|
|||||||
Args:
|
Args:
|
||||||
*objects (Any): Positional arguments are converted to string and written to logs.
|
*objects (Any): Positional arguments are converted to string and written to logs.
|
||||||
verbosity (int, optional): Verbosity level 0-3. Defaults to 1.
|
verbosity (int, optional): Verbosity level 0-3. Defaults to 1.
|
||||||
|
_textual_calling_frame (inspect.FrameInfo | None): The frame info to include in
|
||||||
|
the log message sent to the devtools server.
|
||||||
"""
|
"""
|
||||||
output = ""
|
output = ""
|
||||||
try:
|
try:
|
||||||
@@ -224,11 +226,11 @@ class App(DOMNode):
|
|||||||
key_values = " ".join(f"{key}={value}" for key, value in kwargs.items())
|
key_values = " ".join(f"{key}={value}" for key, value in kwargs.items())
|
||||||
output = " ".join((output, key_values))
|
output = " ".join((output, key_values))
|
||||||
|
|
||||||
if not caller:
|
if not _textual_calling_frame:
|
||||||
caller = inspect.stack()[1]
|
_textual_calling_frame = inspect.stack()[1]
|
||||||
|
|
||||||
calling_path = caller.filename
|
calling_path = _textual_calling_frame.filename
|
||||||
calling_lineno = caller.lineno
|
calling_lineno = _textual_calling_frame.lineno
|
||||||
|
|
||||||
if self.devtools.is_connected and verbosity <= self.log_verbosity:
|
if self.devtools.is_connected and verbosity <= self.log_verbosity:
|
||||||
if len(objects) > 1 or len(kwargs) >= 1 and output:
|
if len(objects) > 1 or len(kwargs) >= 1 and output:
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class MessagePump:
|
|||||||
return self._running
|
return self._running
|
||||||
|
|
||||||
def log(self, *args, **kwargs) -> None:
|
def log(self, *args, **kwargs) -> None:
|
||||||
return self.app.log(*args, **kwargs, caller=inspect.stack()[1])
|
return self.app.log(*args, **kwargs, _textual_calling_frame=inspect.stack()[1])
|
||||||
|
|
||||||
def set_parent(self, parent: MessagePump) -> None:
|
def set_parent(self, parent: MessagePump) -> None:
|
||||||
self._parent = parent
|
self._parent = parent
|
||||||
|
|||||||
Reference in New Issue
Block a user