Skip to content

Commit

Permalink
Move isatty and get_blocking to mock termios lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
antarcticrainforest committed Jul 22, 2024
1 parent 1d09248 commit 14f131d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
16 changes: 16 additions & 0 deletions assets/unix_mock/src/termios/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Simulation of the termios unix library for Windows."""

import msvcrt

# Constants for when argument in tcsetattr()
TCSANOW = 0
TCSADRAIN = 1
Expand Down Expand Up @@ -49,6 +51,20 @@
default_mode[CC] = [0] * 32


def isatty(fd):
"""Check if the file descriptor is a terminal."""

try:
return msvcrt.get_osfhandle(fd) is not None
except Exception:
return False


def get_blocking(fd):
"""The os.get_blocking functionality from unix."""
return True


def tcgetattr(fd):
"""Get the parameters associated with the terminal."""
# This is a mock implementation, returning a default mode array.
Expand Down
16 changes: 0 additions & 16 deletions assets/unix_mock/src/tty/__init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
"""Simulation of the tty unix library for Windows."""

import msvcrt
import termios


IFLAG = termios.IFLAG
OFLAG = termios.OFLAG
CFLAG = termios.CFLAG
LFLAG = termios.LFLAG
CC = termios.CC


def isatty(fd):
"""Check if the file descriptor is a terminal."""

try:
return msvcrt.get_osfhandle(fd) is not None
except Exception:
return False


def get_blocking(fd):
"""The os.get_blocking functionality from unix."""
return True


def setraw(fd, when=termios.TCSANOW):
"""Put terminal into raw mode."""
mode = termios.tcgetattr(fd)
Expand Down
10 changes: 4 additions & 6 deletions pyinstaller/pre-win.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
try:
import ansible

ansible_cli_path = (
Path(ansible.__file__).parent / "cli" / "__init__.py"
)
ansible_cli_path = Path(ansible.__file__).parent / "cli" / "__init__.py"
finally:
sys.getfilesystemencoding = getfilesystemencoding
locale.getlocale = getlocale
Expand All @@ -28,9 +26,9 @@
for call in ("isatty", "get_blocking"):
if f"os.{call}" in content:
write = True
if "import os, tty" not in content:
content = content.replace("import os", "import os, tty")
content = content.replace(f"os.{call}", f"tty.{call}")
if "import os, termios" not in content:
content = content.replace("import os", "import os, termios")
content = content.replace(f"os.{call}", f"termios.{call}")
if write:
inp_file.write_text(content, encoding="utf-8")
else:
Expand Down

0 comments on commit 14f131d

Please sign in to comment.