-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hooks to support PyUSB #6
Conversation
This is great work! It's seldom one takes the time implementing a more complex hook. Thanks a lot! |
hi, I updated my code by your comments. :) |
I'm not quiet familiar with pull request, so not sure about should I add a another commit for fixing those or not. I did a rebase on it with those fixes so the commits rev numbers are now changed. |
What python version have you tested it with? |
It looks mostly ok to me. |
# NOTE: mind updating run-time hook when adding further libs | ||
libusb_candidates = ( | ||
# libusb10 | ||
'usb-1.0', 'usb', 'libusb-1.0', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method _resolveCtypesImports was not able to resolve these libraries?
Do you have an idea how it could be fixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that method work alright, I actually used that method later to resolve the library once I figured out which one to be included.
The problem is that libusb used this syntax to load library:
def _load_library():
candidates = ('usb-1.0', 'libusb-1.0', 'usb')
for candidate in candidates:
libname = ctypes.util.find_library(candidate)
if libname is not None: break
else:
# ...
# Windows backend uses stdcall calling convention
if sys.platform == 'win32':
l = WinDLL(libname)
else:
l = CDLL(libname)
# ...
return l
The filename given in CDLL or WinDLL is not a constant, so the code scanner in pyinstaller can't figured out what has been passed in. As for fixes, I don't see how this can be easily fixed. It may require a complex static analysis to make sure things go right in my opinion.
I tested with Python 2.5 on Win32, Python 2.7.1 on Mac OS X and Python 2.7.2 on Linux. |
Do you have any simple code example to create a test case from that? This test case would be a part of our test suite could be run regularly in our continuous integration system. |
# from ctypes.util.find_library. | ||
bins = [os.path.basename(libname)] | ||
mod.binaries.extend(_resolveCtypesImports(bins)) | ||
elif sys.platform == 'cygwin': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here could be used code like
from PyInstaller.compat import is_cygwin
Hi, I tried to address all of the issues mentioned before. Please take a look in case I missed something. :) and... I found a bug in the pyinstaller cause the cygwin library lookup might not work sometimes. cygusb-1.0.dll(and cygusb0.dll, if libusb 0.1 is installed) is put into /usr/bin (can be obtained/verified by install libusb1.0 pkg in cygwin) and this library cannot be resolved by _resolveCtypesImports. I removed cygwin part code in my package hook since it's written as constant in PyUSB, so it should be work just fine if the pyinstaller's _resolveCtypesImports works. |
|
Add: Add hooks to support PyUSB.
More Python 3 fixes and Python 3.4 compatibility.
Closes pyinstaller#6.
Closes pyinstaller#6.
PyUSB use ctypes.util.find_library to load one of its backend library (libusb1.0, libusb0.1, openusb). It is not supported by the pyinstaller's code scanner so the dependent library will not being picked up by pyinstaller.
I wrote a package-time hook to collect one of the available library into the bundle and a run-time hook to make sure it'll pick up the bundled copy not the system one.
This patch has been tested on Win32, Mac, Linux and works on them.