Skip to content

Commit 5a31005

Browse files
committed
TST: Replace pywin32 with ctypes wrapper
We only use `pywin32` for one function, and while taking care of all the wrapping is nice, it's easy to just take the information from the MSDN docs [1] and pass it through `ctypes` instead. This avoids the dependency entirely, helping to fix package conflicts with pixi [2]. [1] https://learn.microsoft.com/en-us/windows/console/generateconsolectrlevent [2] matplotlib#30877 (comment)
1 parent 69cc7f8 commit 5a31005

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,11 @@ def _test_sigint_impl(backend, target_name, kwargs):
702702

703703
def interrupter():
704704
if sys.platform == 'win32':
705-
import win32api
706-
win32api.GenerateConsoleCtrlEvent(0, 0)
705+
from ctypes import windll, wintypes
706+
GenerateConsoleCtrlEvent = windll.kernel32.GenerateConsoleCtrlEvent
707+
GenerateConsoleCtrlEvent.argtypes = [wintypes.DWORD, wintypes.DWORD]
708+
GenerateConsoleCtrlEvent.restype = wintypes.BOOL
709+
GenerateConsoleCtrlEvent(0, 0)
707710
else:
708711
import signal
709712
os.kill(os.getpid(), signal.SIGINT)

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ test-extra = [
146146
"pandas!=0.25.0",
147147
"pikepdf",
148148
"pytz",
149-
"pywin32; sys_platform == 'win32'",
150149
"xarray",
151150
]
152151

0 commit comments

Comments
 (0)