|
8 | 8 | #----------------------------------------------------------------------------- |
9 | 9 |
|
10 | 10 | import os |
11 | | -from PyInstaller.utils.hooks import collect_data_files, get_qmake_path |
| 11 | +from PyInstaller.utils.hooks import add_qt5_dependencies, \ |
| 12 | + remove_prefix, get_module_file_attribute, pyqt5_library_info, \ |
| 13 | + collect_system_data_files |
| 14 | +from PyInstaller.depend.bindepend import getImports |
12 | 15 | import PyInstaller.compat as compat |
13 | 16 |
|
14 | | -hiddenimports = ["sip", |
15 | | - "PyQt5.QtCore", |
16 | | - "PyQt5.QtGui", |
17 | | - "PyQt5.QtNetwork", |
18 | | - "PyQt5.QtWebChannel", |
19 | | - "PyQt5.QtWebEngineCore", |
20 | | - ] |
| 17 | +hiddenimports, binaries, datas = add_qt5_dependencies(__file__) |
21 | 18 |
|
22 | | -# Find the additional files necessary for QtWebEngine. |
23 | | -datas = (collect_data_files('PyQt5', True, os.path.join('Qt', 'resources')) + |
24 | | - collect_data_files('PyQt5', True, os.path.join('Qt', 'translations')) + |
25 | | - [x for x in collect_data_files('PyQt5', False, os.path.join('Qt', 'bin')) |
26 | | - if x[0].endswith('QtWebEngineProcess.exe')]) |
27 | | - |
28 | | -# Note that for QtWebEngineProcess to be able to find icudtl.dat the bundle_identifier |
29 | | -# must be set to 'org.qt-project.Qt.QtWebEngineCore'. This can be done by passing |
30 | | -# bundle_identifier='org.qt-project.Qt.QtWebEngineCore' to the BUNDLE command in |
31 | | -# the .spec file. FIXME: This is not ideal and a better solution is required. |
32 | | -qmake = get_qmake_path('5') |
33 | | -if qmake: |
34 | | - libdir = compat.exec_command(qmake, "-query", "QT_INSTALL_LIBS").strip() |
35 | | - |
36 | | - if compat.is_darwin: |
37 | | - binaries = [ |
38 | | - (os.path.join(libdir, 'QtWebEngineCore.framework', 'Versions', '5',\ |
39 | | - 'Helpers', 'QtWebEngineProcess.app', 'Contents', 'MacOS', 'QtWebEngineProcess'), |
40 | | - os.path.join('QtWebEngineProcess.app', 'Contents', 'MacOS')) |
41 | | - ] |
42 | | - |
43 | | - resources_dir = os.path.join(libdir, 'QtWebEngineCore.framework', 'Versions', '5', 'Resources') |
44 | | - datas += [ |
45 | | - (os.path.join(resources_dir, 'icudtl.dat'),'.'), |
46 | | - (os.path.join(resources_dir, 'qtwebengine_resources.pak'), '.'), |
47 | | - # The distributed Info.plist has LSUIElement set to true, which prevents the |
48 | | - # icon from appearing in the dock. |
49 | | - (os.path.join(libdir, 'QtWebEngineCore.framework', 'Versions', '5',\ |
50 | | - 'Helpers', 'QtWebEngineProcess.app', 'Contents', 'Info.plist'), |
51 | | - os.path.join('QtWebEngineProcess.app', 'Contents')) |
52 | | - ] |
| 19 | +# Include the web engine process, translations, and resources. |
| 20 | +rel_data_path = 'PyQt5', 'Qt' |
| 21 | +if compat.is_darwin: |
| 22 | + # This is based on the layout of the Mac wheel from PyPi. |
| 23 | + data_path = pyqt5_library_info.location['DataPath'] |
| 24 | + resources = 'lib', 'QtWebEngineCore.framework', 'Resources' |
| 25 | + web_engine_process = ('lib', 'QtWebEngineCore.framework', 'Helpers') |
| 26 | + datas += collect_system_data_files( |
| 27 | + os.path.join(data_path, *resources), |
| 28 | + os.path.join(*rel_data_path, *resources[:-1]), True) |
| 29 | + datas += collect_system_data_files( |
| 30 | + os.path.join(data_path, *web_engine_process), |
| 31 | + os.path.join(*rel_data_path, *web_engine_process[:-1]), True) |
| 32 | +else: |
| 33 | + locales = 'qtwebengine_locales' |
| 34 | + resources = 'resources' |
| 35 | + datas += [ |
| 36 | + # Gather translations needed by Chromium. |
| 37 | + (os.path.join(pyqt5_library_info.location['TranslationsPath'], |
| 38 | + locales), |
| 39 | + os.path.join('PyQt5', 'Qt', 'translations', locales)), |
| 40 | + # Per the `docs <https://doc.qt.io/qt-5.10/qtwebengine-deploying.html#deploying-resources>`_, |
| 41 | + # ``DataPath`` is the base directory for ``resources``. |
| 42 | + (os.path.join(pyqt5_library_info.location['DataPath'], resources), |
| 43 | + os.path.join(*rel_data_path, resources)), |
| 44 | + # Include the webengine process. The ``LibraryExecutablesPath`` is only |
| 45 | + # valid on Windows and Linux. |
| 46 | + (os.path.join(pyqt5_library_info.location['LibraryExecutablesPath'], |
| 47 | + 'QtWebEngineProcess*'), |
| 48 | + os.path.join(*rel_data_path, |
| 49 | + remove_prefix(pyqt5_library_info.location['LibraryExecutablesPath'], |
| 50 | + pyqt5_library_info.location['PrefixPath'] + '/'))) |
| 51 | + ] |
53 | 52 |
|
| 53 | +# Add Linux-specific libraries. |
| 54 | +if compat.is_linux: |
| 55 | + # The automatic library detection fails for `NSS |
| 56 | + # <https://packages.ubuntu.com/search?keywords=libnss3>`_, which is used by |
| 57 | + # QtWebEngine. |
| 58 | + # |
| 59 | + # First, find the location of NSS. |
| 60 | + for imp in getImports(get_module_file_attribute('PyQt5.QtWebEngineWidgets')): |
| 61 | + if 'libnss3.so' in os.path.basename(imp): |
| 62 | + # Given a ``/path/to/libnss.so``, add ``/path/to/nss/*.so`` to get |
| 63 | + # the missing NSS libraries. |
| 64 | + binaries.append((os.path.join(os.path.dirname(imp), 'nss', '*.so'), |
| 65 | + 'nss')) |
0 commit comments