Skip to content

Commit 5de3c77

Browse files
committed
Guard the Windows-only windows_window_manage import
ctypes.WINFUNCTYPE is only defined on Windows; Linux's ctypes raises ``ImportError: cannot import name 'WINFUNCTYPE'`` when ``windows.window.windows_window_manage`` is loaded. My new Docker / Linux CI workflow exposed this pre-existing unconditional import in the package facade. Gate the import on ``sys.platform`` so ``import je_auto_control`` keeps working on macOS / Linux; the wrappers in ``auto_control_window`` already check the platform and raise ``NotImplementedError`` for the Windows-only operations on other OSes, so non-Windows callers see a clean error instead of an import-time crash.
1 parent a7a129a commit 5de3c77

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

je_auto_control/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,16 @@
292292
# test record
293293
from je_auto_control.utils.test_record.record_test_class import \
294294
test_record_instance
295-
# Windows
296-
from je_auto_control.windows.window import windows_window_manage
295+
# Windows-only modules (ctypes.WINFUNCTYPE / Win32 API) — gate the
296+
# import so ``import je_auto_control`` keeps working on macOS / Linux.
297+
# The facade wrappers re-import these on demand and raise
298+
# NotImplementedError for the Windows-only operations on other OSes.
299+
import sys as _sys_for_platform_check # noqa: E402
300+
if _sys_for_platform_check.platform in ("win32", "cygwin", "msys"):
301+
from je_auto_control.windows.window import windows_window_manage # noqa: E402
302+
else:
303+
windows_window_manage = None # type: ignore[assignment]
304+
del _sys_for_platform_check
297305
from je_auto_control.wrapper.auto_control_image import locate_all_image
298306
from je_auto_control.wrapper.auto_control_image import locate_and_click
299307
from je_auto_control.wrapper.auto_control_image import locate_image_center

0 commit comments

Comments
 (0)