pyi_rth_glib.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2015-2023, PyInstaller Development Team.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: Apache-2.0
  10. #-----------------------------------------------------------------------------
  11. def _pyi_rthook():
  12. import os
  13. import sys
  14. # Prepend the frozen application's data dir to XDG_DATA_DIRS. We need to avoid overwriting the existing paths in
  15. # order to allow the frozen application to run system-installed applications (for example, launch a web browser via
  16. # the webbrowser module on Linux). Should the user desire complete isolation of the frozen application from the
  17. # system, they need to clean up XDG_DATA_DIRS at the start of their program (i.e., remove all entries but first).
  18. pyi_data_dir = os.path.join(sys._MEIPASS, 'share')
  19. xdg_data_dirs = os.environ.get('XDG_DATA_DIRS', None)
  20. if xdg_data_dirs:
  21. if pyi_data_dir not in xdg_data_dirs:
  22. xdg_data_dirs = pyi_data_dir + os.pathsep + xdg_data_dirs
  23. else:
  24. xdg_data_dirs = pyi_data_dir + os.pathsep + '/usr/local/share/' + os.pathsep + '/usr/share/'
  25. os.environ['XDG_DATA_DIRS'] = xdg_data_dirs
  26. # Cleanup aux variables
  27. del xdg_data_dirs
  28. del pyi_data_dir
  29. _pyi_rthook()
  30. del _pyi_rthook