hook-psutil.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2023 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. import os
  13. import sys
  14. # see https://github.com/giampaolo/psutil/blob/release-5.9.5/psutil/_common.py#L82
  15. WINDOWS = os.name == "nt"
  16. LINUX = sys.platform.startswith(("linux", "android"))
  17. MACOS = sys.platform.startswith("darwin")
  18. FREEBSD = sys.platform.startswith(("freebsd", "midnightbsd"))
  19. OPENBSD = sys.platform.startswith("openbsd")
  20. NETBSD = sys.platform.startswith("netbsd")
  21. BSD = FREEBSD or OPENBSD or NETBSD
  22. SUNOS = sys.platform.startswith(("sunos", "solaris"))
  23. AIX = sys.platform.startswith("aix")
  24. excludedimports = [
  25. "psutil._pslinux",
  26. "psutil._pswindows",
  27. "psutil._psosx",
  28. "psutil._psbsd",
  29. "psutil._pssunos",
  30. "psutil._psaix",
  31. ]
  32. # see https://github.com/giampaolo/psutil/blob/release-5.9.5/psutil/__init__.py#L97
  33. if LINUX:
  34. excludedimports.remove("psutil._pslinux")
  35. elif WINDOWS:
  36. excludedimports.remove("psutil._pswindows")
  37. # see https://github.com/giampaolo/psutil/blob/release-5.9.5/psutil/_common.py#L856
  38. # This will exclude `curses` for windows
  39. excludedimports.append("curses")
  40. elif MACOS:
  41. excludedimports.remove("psutil._psosx")
  42. elif BSD:
  43. excludedimports.remove("psutil._psbsd")
  44. elif SUNOS:
  45. excludedimports.remove("psutil._pssunos")
  46. elif AIX:
  47. excludedimports.remove("psutil._psaix")