Skip to content

Commit

Permalink
Support using pypiwin32 or pywin32-ctypes
Browse files Browse the repository at this point in the history
pypiwin32 doesn't work on msys2 for a variety of reasons, but pywin32-ctypes
supports the minimum API that pyinstaller needs

See also: https://github.com/Alexpux/MINGW-packages/issues/751
  • Loading branch information
virtuald authored and htgoebel committed Jul 28, 2017
1 parent 3c4a980 commit 4f3ea16
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
13 changes: 11 additions & 2 deletions PyInstaller/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,17 @@ def check_requirements():
if is_win:
try:
from PyInstaller.utils.win32 import winutils
pywintypes = winutils.import_pywin32_module('pywintypes')
try:
pywintypes = winutils.import_pywin32_module('pywintypes')
except ImportError:
from win32ctypes.pywin32 import pywintypes
from win32ctypes.pywin32 import win32api

# if this succeeded, then install pywin32-ctypes into sys.modules
sys.modules['win32api'] = win32api
sys.modules['pywintypes'] = pywintypes

except ImportError:
raise SystemExit('PyInstaller cannot check for assembly dependencies.\n'
'Please install PyWin32.\n\n'
'Please install PyWin32 or pywin32-ctypes.\n\n'
'pip install pypiwin32\n')
1 change: 1 addition & 0 deletions PyInstaller/lib/modulegraph/find_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def plat_prepare(includes, packages, excludes):
'nturl2path',
'win32api',
'win32con',
'win32ctypes',
'win32event',
'win32evtlogutil',
'win32evtlog',
Expand Down
10 changes: 7 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@
try:
import pywintypes
except ImportError:
# 'pypiwin32' is PyWin32 package made installable by 'pip install'
# command.
REQUIREMENTS.append('pypiwin32')
# try using pywin32-ctypes, as pypiwin32 doesn't compile for msys2
try:
import win32ctypes.pywin32.pywintypes
except ImportError:
# 'pypiwin32' is PyWin32 package made installable by 'pip install'
# command. Prefer it by default.
REQUIREMENTS.append('pypiwin32')


# Create long description from README.rst and doc/CHANGES.rst.
Expand Down
7 changes: 6 additions & 1 deletion tests/functional/scripts/pyi_win_py3_no_shortpathname.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
# This script is used by multiple tests. It checks that various paths set by the
# bootloader are usable filenames.

import sys, os, win32api
import sys, os

try:
import win32api
except ImportError:
from win32ctypes.pywin32 import win32api

if sys.version_info[0] == 2:
safe_repr = repr
Expand Down

0 comments on commit 4f3ea16

Please sign in to comment.