Skip to content

Commit

Permalink
Mock libc wcwidth.
Browse files Browse the repository at this point in the history
  • Loading branch information
antarcticrainforest committed Jul 22, 2024
1 parent 797cbea commit d70a1bc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion assets/unix_mock/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ classifiers = [
]
version = "0.0.1"
requires-python = ">=3.7"
dependencies = ["pywin32"]
dependencies = ["pywin32", "wcwidth"]
9 changes: 9 additions & 0 deletions assets/unix_mock/src/fcntl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ctypes import c_char

import pywintypes
import wcwidth as ww
import win32api
import win32con
import win32file
Expand All @@ -19,6 +20,14 @@
F_GETFD = 4


def wcwidth(text):
return ww.wcwidth(text)


def wcswidth(text, num=None):
return ww.wcswidth(text)


def fcntl(fd, cmd, arg=0):
"""Perform the operation `cmd` on file descriptor fd.
Expand Down
33 changes: 28 additions & 5 deletions pyinstaller/pre-win.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
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 @@ -27,14 +29,35 @@
if f"os.{call}" in content:
write = True
if "import os, termios" not in content:
content = content.replace("import os", "import os, termios")
content = content.replace(
"import os", "import os, termios"
)
content = content.replace(f"os.{call}", f"termios.{call}")
if "get_context('fork')" in content or 'get_context("fork")' in content:
if (
"get_context('fork')" in content
or 'get_context("fork")' in content
):
write = True
content = content.replace("get_context('fork')", "get_context('spawn')")
content = content.replace('get_context("fork")', 'get_context("spwan")')
content = content.replace(
"get_context('fork')", "get_context('spawn')"
)
content = content.replace(
'get_context("fork")', 'get_context("spwan")'
)
if write:
inp_file.write_text(content, encoding="utf-8")
display = Path(ansible.__file__) / "utils" / "display.py"
content = "\n".join(
[
l
for l in display.read_text().splitlines()
if not l.startswith("_LIBC =")
]
)
content = content.replace(
"import ctypes.util", "ctypes.util\nimport wcwidth"
)
display.write_text(content)
else:
import PyInstaller.depend.bindepend

Expand Down

0 comments on commit d70a1bc

Please sign in to comment.