Skip to content

Commit caf1b0b

Browse files
WolffMreisepassneubig
authored
fix(tools): guard Unix-only imports in terminal package for Windows (#2096)
Co-authored-by: Rb <rubenwolff@gmail.com> Co-authored-by: Graham Neubig <neubig@gmail.com>
1 parent 60347e9 commit caf1b0b

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

openhands-tools/openhands/tools/terminal/terminal/__init__.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1+
import platform
2+
from typing import TYPE_CHECKING
3+
14
from openhands.tools.terminal.terminal.factory import create_terminal_session
25
from openhands.tools.terminal.terminal.interface import (
36
TerminalInterface,
47
TerminalSessionBase,
58
)
6-
from openhands.tools.terminal.terminal.subprocess_terminal import (
7-
SubprocessTerminal,
8-
)
99
from openhands.tools.terminal.terminal.terminal_session import (
1010
TerminalCommandStatus,
1111
TerminalSession,
1212
)
13-
from openhands.tools.terminal.terminal.tmux_terminal import TmuxTerminal
13+
14+
15+
# These backends depend on Unix-only modules (fcntl, pty, libtmux)
16+
if platform.system() != "Windows":
17+
from openhands.tools.terminal.terminal.subprocess_terminal import (
18+
SubprocessTerminal,
19+
)
20+
from openhands.tools.terminal.terminal.tmux_terminal import TmuxTerminal
21+
22+
if TYPE_CHECKING:
23+
from openhands.tools.terminal.terminal.subprocess_terminal import (
24+
SubprocessTerminal,
25+
)
26+
from openhands.tools.terminal.terminal.tmux_terminal import TmuxTerminal
1427

1528

1629
__all__ = [

openhands-tools/openhands/tools/terminal/terminal/subprocess_terminal.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
"""PTY-based terminal backend implementation (replaces pipe-based subprocess)."""
22

3-
import fcntl
43
import os
5-
import pty
4+
import platform
65
import re
7-
import select
86
import shutil
97
import signal
108
import subprocess
119
import threading
1210
import time
1311
from collections import deque
1412

13+
14+
if platform.system() == "Windows":
15+
raise ImportError(
16+
"SubprocessTerminal is not supported on Windows "
17+
"(requires Unix-only modules: fcntl, pty, select)"
18+
)
19+
20+
import fcntl
21+
import pty
22+
import select
23+
1524
from openhands.sdk.logger import get_logger
1625
from openhands.sdk.utils import sanitized_env
1726
from openhands.tools.terminal.constants import (

0 commit comments

Comments
 (0)