Skip to content

Commit 1c576cd

Browse files
committed
Abbreviate Memray's path displayed in the TUI
When the TUI shows a command line that indicates that Memray is running (either a command named `memray` or a file named `memray/__main__.py` as the first argument), shorten this to just "memray" to save room for more valuable information. Signed-off-by: Matt Wozniski <[email protected]>
1 parent 38e9ac8 commit 1c576cd

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/memray/reporters/tui.py

+7
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,13 @@ def on_mount(self) -> None:
751751
if self._cmdline_override is not None
752752
else self._reader.command_line
753753
)
754+
755+
if cmd_line is not None and "/memray" in cmd_line:
756+
cmd_args = cmd_line.split()
757+
if any(cmd_args[0].endswith(p) for p in ("/memray", "/memray/__main__.py")):
758+
cmd_args[0] = "memray"
759+
cmd_line = " ".join(cmd_args)
760+
754761
self.tui = TUI(
755762
pid=self._reader.pid,
756763
cmd_line=cmd_line,

tests/unit/test_tui_reporter.py

+15
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,21 @@ async def run_test():
496496
"command_line, display_val",
497497
[
498498
pytest.param("foo bar baz", "CMD: foo bar baz", id="Known command"),
499+
pytest.param(
500+
"/path/to/foo bar baz",
501+
"CMD: /path/to/foo bar baz",
502+
id="Known command with path",
503+
),
504+
pytest.param(
505+
"/path/to/memray bar baz",
506+
"CMD: memray bar baz",
507+
id="Memray script with path",
508+
),
509+
pytest.param(
510+
"/path/to/memray/__main__.py bar baz",
511+
"CMD: memray bar baz",
512+
id="Memray module with path",
513+
),
499514
pytest.param(None, "CMD: ???", id="Unknown command"),
500515
],
501516
)

0 commit comments

Comments
 (0)