Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hooks for psutil #623

Merged
merged 7 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/623.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a hook for ``psutil``, which has platform-dependent exclude list.
1 change: 1 addition & 0 deletions requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ xyzservices==2023.7.0
mistune==3.0.1
pydantic==2.1.1
jsonschema==4.19.0
psutil==5.9.5
byehack marked this conversation as resolved.
Show resolved Hide resolved

# ------------------- Platform (OS) specifics

Expand Down
50 changes: 50 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-psutil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# ------------------------------------------------------------------
# Copyright (c) 2023 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------
import os
import sys

# see https://github.com/giampaolo/psutil/blob/release-5.9.5/psutil/_common.py#L82
WINDOWS = os.name == "nt"
LINUX = sys.platform.startswith("linux")
MACOS = sys.platform.startswith("darwin")
FREEBSD = sys.platform.startswith(("freebsd", "midnightbsd"))
OPENBSD = sys.platform.startswith("openbsd")
NETBSD = sys.platform.startswith("netbsd")
BSD = FREEBSD or OPENBSD or NETBSD
SUNOS = sys.platform.startswith(("sunos", "solaris"))
AIX = sys.platform.startswith("aix")

excludedimports = [
"psutil._pslinux",
"psutil._pswindows",
"psutil._psosx",
"psutil._psbsd",
"psutil._pssunos",
"psutil._psaix",
]

# see https://github.com/giampaolo/psutil/blob/release-5.9.5/psutil/__init__.py#L97
if LINUX:
excludedimports.remove("psutil._pslinux")
elif WINDOWS:
excludedimports.remove("psutil._pswindows")
# see https://github.com/giampaolo/psutil/blob/release-5.9.5/psutil/_common.py#L856
# This will exclude `curses` for windows
excludedimports.append("curses")
elif MACOS:
excludedimports.remove("psutil._psosx")
elif BSD:
excludedimports.remove("psutil._psbsd")
elif SUNOS:
excludedimports.remove("psutil._pssunos")
elif AIX:
excludedimports.remove("psutil._psaix")
7 changes: 7 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1695,3 +1695,10 @@ def test_jsonschema(pyi_builder):
except jsonschema.ValidationError as e:
print(f"Validation error: {e}")
""")


@importorskip('psutil')
def test_psutil(pyi_builder):
pyi_builder.test_source("""
import psutil
""")
Loading