failed WRONG_FIX wrong_fix · 11 tool calls · 22 s · Textualize/rich
TTY_COMPATIBLE Implement new `TTY_COMPATIBLE` environment variable @ofek @webknjaz @hugovk Relevant discussion: https://github.com/Textualize/rich/issues/2924
| # | Tool | Arguments | Result |
|---|---|---|---|
| 1 | run_command | {
"command": "grep -rn \"is_atty\" rich | head -20"
} | {"status": "ok", "stdout": "", "exit_code": 0}full{"status": "ok", "stdout": "", "exit_code": 0} |
| 2 | run_command | {
"command": "grep -rn \"os.isatty\" rich | head -20"
} | {"status": "ok", "stdout": "", "exit_code": 0}full{"status": "ok", "stdout": "", "exit_code": 0} |
| 3 | run_command | {
"command": "find . -maxdepth 2 -name \"*.py\""
} | {"status": "ok", "stdout": "./benchmarks/__init__.py\n./benchmarks/snippets.py\n./benchmarks/benchmarks.py\n./tests/test_live_render.py\n./tests/test_card.py\n.full{"status": "ok", "stdout": "./benchmarks/__init__.py\n./benchmarks/snippets.py\n./benchmarks/benchmarks.py\n./tests/test_live_render.py\n./tests/test_card.py\n./tests/test_windows_renderer.py\n./tests/test_progress.py\n./tests/test_cells.py\n./tests/test_table.py\n./tests/test_pretty.py\n./tests/__init__.py\n./tests/test_logging.py\n./tests/test_style.py\n./tests/render.py\n./tests/test_columns_align.py\n./tests/test_ratio.py\n./tests/test_styled.py\n./tests/test_align.py\n./tests/test_color.py\n./tests/test_constrain.py\n./tests/test_stack.py\n./tests/test_null_file.py\n./tests/test_color_triplet.py\n./tests/test_rule_in_table.py\n./tests/test_console.py\n./tests/test_ansi.py\n./tests/test_containers.py\n./tests/test_screen.py\n./tests/test_panel.py\n./tests/test_jupyter.py\n./tests/test_highlighter.py\n./tests/test_json.py\n./tests/test_filesize.py\n./tests/test_columns.py\n./tests/test_getfileno.py\n./tests/test_block_bar.py\n./tests/test_prompt.py\n./tests/test_inspect.py\n./tests/test_protocol.py\n./tests/test_spinner.py\n./tests/test_bar.py\n./tests/conftest.py\n./tests/test_win32_console.py\n./tests/test_theme.py\n./tests/test_syntax.py\n./tests/test_live.py\n./tests/test_log.py\n./tests/test_rule.py\n./tests/test_rich_print.py\n./tests/test_control.py\n./tests/test_layout.py\n./tests/test_tree.py\n./tests/test_box.py\n./tests/_card_render.py\n./tests/test_pick.py\n./tests/test_repr.py\n./tests/test_markdown_no_hyperlinks.py\n./tests/test_text.py\n./tests/test_emoji.py\n./tests/test_segment.py\n./tests/test_file_proxy.py\n./tests/test_padding.py\n./tests/test_measure.py\n./tests/test_palette.py\n./tests/test_markdown.py\n./tests/test_markup.py\n./tests/test_tools.py\n./tests/test_traceback.py\n./tests/test_status.py\n./examples/padding.py\n./examples/justify.py\n./examples/table.py\n./examples/spinners.py\n./examples/print_calendar.py\n./examples/downloader.py\n./examples/recursive_error.py\n./examples/fullscreen.py\n./examples/live_progress.py\n./examples/ex |
| 4 | run_command | {
"command": "grep -rn \"isatty\" rich | head -20"
} | {"status": "ok", "stdout": "rich/console.py:957: isatty: Optional[Callable[[], bool]] = getattr(self.file, \"isatty\", None)\nrich/console.py:959: return False full{"status": "ok", "stdout": "rich/console.py:957: isatty: Optional[Callable[[], bool]] = getattr(self.file, \"isatty\", None)\nrich/console.py:959: return False if isatty is None else isatty()\nrich/console.py:961: # in some situation (at the end of a pytest run for example) isatty() can raise\nrich/_null_file.py:9: def isatty(self) -> bool:\nrich/progress.py:227: def isatty(self) -> bool:\nrich/progress.py:228: return self.handle.isatty()\n", "exit_code": 0} |
| 5 | read_file | {
"filepath": "rich/console.py",
"start_line": 950,
"end_line": 970
} | {"status": "ok", "filepath": "rich/console.py", "content": "\n # If FORCE_COLOR env var has any value at all, we assume a terminal.\n force_color = self._envirofull{"status": "ok", "filepath": "rich/console.py", "content": "\n # If FORCE_COLOR env var has any value at all, we assume a terminal.\n force_color = self._environ.get(\"FORCE_COLOR\")\n if force_color is not None:\n self._force_terminal = True\n return True\n\n isatty: Optional[Callable[[], bool]] = getattr(self.file, \"isatty\", None)\n try:\n return False if isatty is None else isatty()\n except ValueError:\n # in some situation (at the end of a pytest run for example) isatty() can raise\n # ValueError: I/O operation on closed file\n # return False because we aren't in a terminal anymore\n return False\n\n @property\n def is_dumb_terminal(self) -> bool:\n \"\"\"Detect dumb terminal.\n\n Returns:\n", "start_line": 950, "end_line": 970, "total_lines": 2661, "is_truncated": false} |
| 6-7 ×2 | read_file | {
"end_line": 960,
"filepath": "rich/console.py",
"start_line": 940
} | {"status": "ok", "filepath": "rich/console.py", "content": "\n if hasattr(sys.stdin, \"__module__\") and sys.stdin.__module__.startswith(\n \"idlelib\"\n ):\n #full{"status": "ok", "filepath": "rich/console.py", "content": "\n if hasattr(sys.stdin, \"__module__\") and sys.stdin.__module__.startswith(\n \"idlelib\"\n ):\n # Return False for Idle which claims to be a tty but can't handle ansi codes\n return False\n\n if self.is_jupyter:\n # return False for Jupyter, which may have FORCE_COLOR set\n return False\n\n # If FORCE_COLOR env var has any value at all, we assume a terminal.\n force_color = self._environ.get(\"FORCE_COLOR\")\n if force_color is not None:\n self._force_terminal = True\n return True\n\n isatty: Optional[Callable[[], bool]] = getattr(self.file, \"isatty\", None)\n try:\n return False if isatty is None else isatty()\n except ValueError:\n", "start_line": 940, "end_line": 960, "total_lines": 2661, "is_truncated": false} |
| 8 | read_file | {
"end_line": 980,
"filepath": "rich/console.py",
"start_line": 930
} | {"status": "ok", "filepath": "rich/console.py", "content": " @property\n def is_terminal(self) -> bool:\n \"\"\"Check if the console is writing to a terminal.\nfull{"status": "ok", "filepath": "rich/console.py", "content": " @property\n def is_terminal(self) -> bool:\n \"\"\"Check if the console is writing to a terminal.\n\n Returns:\n bool: True if the console writing to a device capable of\n understanding terminal codes, otherwise False.\n \"\"\"\n if self._force_terminal is not None:\n return self._force_terminal\n\n if hasattr(sys.stdin, \"__module__\") and sys.stdin.__module__.startswith(\n \"idlelib\"\n ):\n # Return False for Idle which claims to be a tty but can't handle ansi codes\n return False\n\n if self.is_jupyter:\n # return False for Jupyter, which may have FORCE_COLOR set\n return False\n\n # If FORCE_COLOR env var has any value at all, we assume a terminal.\n force_color = self._environ.get(\"FORCE_COLOR\")\n if force_color is not None:\n self._force_terminal = True\n return True\n\n isatty: Optional[Callable[[], bool]] = getattr(self.file, \"isatty\", None)\n try:\n return False if isatty is None else isatty()\n except ValueError:\n # in some situation (at the end of a pytest run for example) isatty() can raise\n # ValueError: I/O operation on closed file\n # return False because we aren't in a terminal anymore\n return False\n\n @property\n def is_dumb_terminal(self) -> bool:\n \"\"\"Detect dumb terminal.\n\n Returns:\n bool: True if writing to a dumb terminal, otherwise False.\n\n \"\"\"\n _term = self._environ.get(\"TERM\", \"\")\n is_dumb = _term.lower() in (\"dumb\", \"unknown\")\n return self.is_terminal and is_dumb\n\n @property\n def options(self) -> ConsoleOptions:\n \"\"\"Get default console options.\"\"\"\n", "start_line": 930, "end_line": 980, "total_lines": 2661, "is_t |
| 9 | edit_file | {
"filepath": "rich/console.py",
"new_string": " # If FORCE_COLOR env var has any value at all, we assume a terminal.\n force_color = self._environ.get(\"FORCE_COLOR\")\n if force_color is not None:\n self._force_terminal = True\n return True\n\n # If TTY_COMPATIBLE env var is set, we assume a terminal.\n tty_compatible = self._environ.get(\"TTY_COMPATIBLE\")\n if tty_compatible is not None:\n self._force_terminal = True\n return True\n\n isatty: Optional[Callable[[], bool]] = getattr(self.file, \"isatty\", None)",
"old_string": " # If FORCE_COLOR env var has any value at all, we assume a terminal.\n force_color = self._environ.get(\"FORCE_COLOR\")\n if force_color is not None:\n self._force_terminal = True\n return True\n\n isatty: Optional[Callable[[], bool]] = getattr(self.file, \"isatty\", None)"
} | {"status": "ok", "filepath": "rich/console.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/console.py\n+++ b/rich/console.py\n@@ -954,6 +954,12 full{"status": "ok", "filepath": "rich/console.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/console.py\n+++ b/rich/console.py\n@@ -954,6 +954,12 @@\n self._force_terminal = True\n return True\n \n+ # If TTY_COMPATIBLE env var is set, we assume a terminal.\n+ tty_compatible = self._environ.get(\"TTY_COMPATIBLE\")\n+ if tty_compatible is not None:\n+ self._force_terminal = True\n+ return True\n+\n isatty: Optional[Callable[[], bool]] = getattr(self.file, \"isatty\", None)\n try:\n return False if isatty is None else isatty()\n", "is_truncated": false} |
| 10 | run_command | {
"command": "python3 -c \"import os; from rich.console import Console; os.environ['TTY_COMPATIBLE'] = '1'; console = Console(file=open('/tmp/test_tty', 'w')); print(f'is_terminal: {console.is_terminal}'); os.close(console.file.fileno()); open('/tmp/test_tty', 'w').close()\""
} | {"status": "ok", "stdout": "is_terminal: True\n", "exit_code": 0}full{"status": "ok", "stdout": "is_terminal: True\n", "exit_code": 0} |
| 11 | run_command | {
"command": "python3 -c \"import os; from rich.console import Console; os.environ.pop('TTY_COMPATIBLE', None); console = Console(file=open('/tmp/test_tty_no', 'w')); print(f'is_terminal: {console.is_terminal}'); os.close(console.file.fileno()); open('/tmp/test_tty_no', 'w').close()\""
} | {"status": "ok", "stdout": "is_terminal: False\n", "exit_code": 0}full{"status": "ok", "stdout": "is_terminal: False\n", "exit_code": 0} |
| 12 | submit_patch | [] | {"status": "ok", "patch_size": 619, "files_changed": 1}full{"status": "ok", "patch_size": 619, "files_changed": 1} |
diff --git a/rich/console.py b/rich/console.py
index 3ec9a8aa..d89a359e 100644
--- a/rich/console.py
+++ b/rich/console.py
@@ -954,6 +954,12 @@ class Console:
self._force_terminal = True
return True
+ # If TTY_COMPATIBLE env var is set, we assume a terminal.
+ tty_compatible = self._environ.get("TTY_COMPATIBLE")
+ if tty_compatible is not None:
+ self._force_terminal = True
+ return True
+
isatty: Optional[Callable[[], bool]] = getattr(self.file, "isatty", None)
try:
return False if isatty is None else isatty()
........................................................................ [ 72%]
..........................F
=================================== FAILURES ===================================
_____________________________ test_tty_compatible ______________________________
def test_tty_compatible() -> None:
"""Check TTY_COMPATIBLE environment var."""
class FakeTTY:
"""An file file-like which reports it is a TTY."""
def __init__(self) -> None:
self.called_isatty = False
def isatty(self) -> bool:
self.called_isatty = True
return True
class FakeFile:
"""A file object that reports False for isatty"""
def __init__(self) -> None:
self.called_isatty = False
def isatty(self) -> bool:
self.called_isatty = True
return False
# Console file is not a TTY
console = Console(file=FakeFile())
# Not a TTY, so is_terminal should be False
assert not console.is_terminal
# Should have called isatty to auto-detect tty support
assert console.file.called_isatty
# Not a terminal
console = Console(file=FakeFile(), _environ={"TTY_COMPATIBLE": "1"})
# env TTY_COMPATIBLE=1 should report that it is a terminal
assert console.is_terminal
# Should not have called file.isattry
assert not console.file.called_isatty
# File is a fake TTY
console = Console(file=FakeTTY())
# Should report True
assert console.is_terminal
# SHould have auto-detected
assert console.file.called_isatty
# File is a fake TTY
console = Console(file=FakeTTY(), _environ={"TTY_COMPATIBLE": ""})
# Blank TTY_COMPATIBLE should auto-detect, so is_terminal is True
assert console.is_terminal
# Should have auto-detected
> assert console.file.called_isatty
E assert False
E + where False = <tests.test_console.test_tty_compatible.<locals>.FakeTTY object at 0x7a781c5f4910>.called_isatty
E + where <tests.test_console.test_tty_compatible.<locals>.FakeTTY object at 0x7a781c5f4910> = <console width=80 ColorSystem.STANDARD>.file
tests/test_console.py:1098: AssertionError
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 failed, 98 passed in 1.12s