Skip to content

Commit 00a37d3

Browse files
committed
_pty.py: Re-write PTY approach
1 parent 0f08288 commit 00a37d3

File tree

3 files changed

+16
-81
lines changed

3 files changed

+16
-81
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ authors = [
3131
requires-python = ">=3.9"
3232
dependencies = [
3333
"coloredlogs>=15.0.1",
34-
"pexpect>=4.9.0",
3534
]
3635
keywords = ["Wine", "sandbox", "sandboxing", "bubblewrap", "bwrap"]
3736
classifiers = [

sandwine/_main.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
import coloredlogs
3535

36-
from sandwine._pty import pty_spawn_argv
3736
from sandwine._x11 import X11Display, X11Mode, create_x11_context, detect_and_require_nested_x11
3837

3938
_logger = logging.getLogger(__name__)
@@ -411,12 +410,24 @@ def create_bwrap_argv(config):
411410
if config.second_try:
412411
argv.add('sh', '-c', '"$0" "$@" || exec "$0" "$@"')
413412

414-
# Add Wine
413+
# Add Wine and PTY
415414
if config.argv_0 is not None:
415+
# Add Wine
416+
inner_argv = []
416417
if config.with_wine:
417-
argv.add('wine', config.argv_0, *config.argv_1_plus)
418+
inner_argv.append('wine')
419+
inner_argv.append(config.argv_0)
420+
inner_argv.extend(config.argv_1_plus)
421+
422+
# Add PTY
423+
if config.with_pty:
424+
# NOTE: This implementation is known to not support Ctrl+Z (SIGTSTP).
425+
# Implementing something with Ctrl+Z support is complex and planned for later.
426+
# The current approach is inspired by ptysolate by Jakub Wilk:
427+
# https://github.com/jwilk/ptysolate
428+
argv.add('script', '-e', '-q', '-c', f'exec {shlex.join(inner_argv)}', '/dev/null')
418429
else:
419-
argv.add(config.argv_0, *config.argv_1_plus)
430+
argv.add(*inner_argv)
420431
else:
421432
argv.add('true')
422433

@@ -431,13 +442,6 @@ def require_recent_bubblewrap():
431442
sys.exit(1)
432443

433444

434-
def spawn_argv(argv: list[str], with_pty: bool) -> int:
435-
if not with_pty:
436-
return subprocess.call(argv)
437-
438-
return pty_spawn_argv(argv)
439-
440-
441445
def main():
442446
exit_code = 0
443447
try:
@@ -472,7 +476,7 @@ def main():
472476

473477
with x11context:
474478
try:
475-
exit_code = spawn_argv(argv, with_pty=config.with_pty)
479+
exit_code = subprocess.call(argv)
476480
except FileNotFoundError:
477481
_logger.error(f'Command {argv[0]!r} is not available, aborting.')
478482
exit_code = 127

sandwine/_pty.py

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)