hook-pythoncom.py 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2020 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. # pywin32 supports frozen mode; in that mode, it is looking at sys.path for pythoncomXY.dll. However, as of
  13. # PyInstaller 5.4, we may collect that DLL into its original pywin32_system32 sub-directory as part of the
  14. # binary dependency analysis (and add it to sys.path by means of a runtime hook).
  15. import pathlib
  16. from PyInstaller.utils.hooks import is_module_satisfies, get_pywin32_module_file_attribute
  17. dll_filename = get_pywin32_module_file_attribute('pythoncom')
  18. dst_dir = '.' # Top-level application directory
  19. if is_module_satisfies('PyInstaller >= 5.4'):
  20. # Try preserving the original pywin32_system directory, if applicable (it is not applicable in Anaconda,
  21. # where the DLL is located in Library/bin).
  22. dll_path = pathlib.Path(dll_filename)
  23. if dll_path.parent.name == 'pywin32_system32':
  24. dst_dir = 'pywin32_system32'
  25. binaries = [(dll_filename, dst_dir)]