win32.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 with the passed name.
  14. On import, each PyWin32 module:
  15. * Imports a DLL specific to that module.
  16. * Overwrites the values of all module attributes with values specific to that DLL. This includes that module's
  17. `__file__` attribute, which then provides the absolute path of that DLL.
  18. This function safely imports that module in a PyWin32-aware subprocess and returns the value of that module's
  19. `__file__` attribute.
  20. Parameters
  21. ----------
  22. module_name : str
  23. Fully-qualified name of that module.
  24. Returns
  25. ----------
  26. str
  27. Absolute path of that DLL.
  28. See Also
  29. ----------
  30. `PyInstaller.utils.win32.winutils.import_pywin32_module()`
  31. For further details.
  32. """
  33. from PyInstaller.utils.hooks import exec_statement
  34. statement = """
  35. from PyInstaller.utils.win32 import winutils
  36. module = winutils.import_pywin32_module('%s')
  37. print(module.__file__)
  38. """
  39. return exec_statement(statement % module_name)
  40. __all__ = ('get_pywin32_module_file_attribute',)