hook-pyqtgraph.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2021 PyInstaller Development Team.
  3. #
  4. # This file is distributed under the terms of the GNU General Public
  5. # License (version 2.0 or later).
  6. #
  7. # The full license is available in LICENSE, distributed with
  8. # this software.
  9. #
  10. # SPDX-License-Identifier: GPL-2.0-or-later
  11. # ------------------------------------------------------------------
  12. from PyInstaller.utils.hooks import collect_data_files, collect_submodules
  13. # Collect all data files, excluding the examples' data
  14. datas = collect_data_files('pyqtgraph', excludes=['**/examples/*'])
  15. # pyqtgraph uses Qt-version-specific templates for the UI elements.
  16. # There are templates for different versions of PySide and PyQt, e.g.
  17. #
  18. # - pyqtgraph.graphicsItems.ViewBox.axisCtrlTemplate_pyqt5
  19. # - pyqtgraph.graphicsItems.ViewBox.axisCtrlTemplate_pyqt6
  20. # - pyqtgraph.graphicsItems.ViewBox.axisCtrlTemplate_pyside2
  21. # - pyqtgraph.graphicsItems.ViewBox.axisCtrlTemplate_pyside6
  22. # - pyqtgraph.graphicsItems.PlotItem.plotConfigTemplate_pyqt5
  23. # - pyqtgraph.graphicsItems.PlotItem.plotConfigTemplate_pyqt6
  24. # - pyqtgraph.graphicsItems.PlotItem.plotConfigTemplate_pyside2
  25. # - pyqtgraph.graphicsItems.PlotItem.plotConfigTemplate_pyside6
  26. #
  27. # To be future-proof, we collect all modules by
  28. # using collect-submodules, and filtering the modules
  29. # which appear to be templates.
  30. # We need to avoid recursing into `pyqtgraph.examples`, because that
  31. # triggers instantiation of `QApplication` (which requires X/Wayland
  32. # session on linux).
  33. # Tested with pyqtgraph master branch (commit c1900aa).
  34. all_imports = collect_submodules("pyqtgraph", filter=lambda name: name != "pyqtgraph.examples")
  35. hiddenimports = [name for name in all_imports if "Template" in name]
  36. # Collect the pyqtgraph/multiprocess/bootstrap.py as a module; this is required by our pyqtgraph.multiprocess runtime
  37. # hook to handle the pyqtgraph's multiprocessing implementation. The pyqtgraph.multiprocess seems to be imported
  38. # automatically on the import of pyqtgraph itself, so there is no point in creating a separate hook for this.
  39. hiddenimports += ['pyqtgraph.multiprocess.bootstrap']
  40. # Attempt to auto-select applicable Qt bindings and exclude extraneous Qt bindings.
  41. # Available in PyInstaller >= 6.5, which has `PyInstaller.utils.hooks.qt.exclude_extraneous_qt_bindings` helper.
  42. try:
  43. from PyInstaller.utils.hooks.qt import exclude_extraneous_qt_bindings
  44. except ImportError:
  45. pass
  46. else:
  47. # Use the helper's default preference order, to keep it consistent across multiple hooks that use the same helper.
  48. excludedimports = exclude_extraneous_qt_bindings(
  49. hook_name="hook-pyqtgraph",
  50. qt_bindings_order=None,
  51. )