win32.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # ----------------------------------------------------------------------------
  2. # Copyright (c) 2005-2021, PyInstaller Development Team.
  3. #
  4. # Distributed under the terms of the GNU General Public License (version 2
  5. # or later) with exception for distributing the bootloader.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  10. # ----------------------------------------------------------------------------
  11. def get_pywin32_module_file_attribute(module_name):
  12. """
  13. Get the absolute path of the PyWin32 DLL specific to the PyWin32 module
  14. with the passed name.
  15. On import, each PyWin32 module:
  16. * Imports a DLL specific to that module.
  17. * Overwrites the values of all module attributes with values specific to
  18. that DLL. This includes that module's `__file__` attribute, which then
  19. provides the absolute path of that DLL.
  20. This function safely imports that module in a PyWin32-aware subprocess and
  21. returns the value of that module's `__file__` attribute.
  22. Parameters
  23. ----------
  24. module_name : str
  25. Fully-qualified name of that module.
  26. Returns
  27. ----------
  28. str
  29. Absolute path of that DLL.
  30. See Also
  31. ----------
  32. `PyInstaller.utils.win32.winutils.import_pywin32_module()`
  33. For further details.
  34. """
  35. from PyInstaller.utils.hooks import exec_statement
  36. statement = """
  37. from PyInstaller.utils.win32 import winutils
  38. module = winutils.import_pywin32_module('%s')
  39. print(module.__file__)
  40. """
  41. return exec_statement(statement % module_name)
  42. __all__ = ('get_pywin32_module_file_attribute', )