Skip to content

Run stubtest for psutil on all platforms #9169

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

Merged
merged 6 commits into from
Nov 13, 2022
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
15 changes: 12 additions & 3 deletions stubs/psutil/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# These super() dunders don't seem to be particularly useful,
# and having them pop up on autocomplete suggestions would be annoying
psutil._compat.super.__self__
psutil._compat.super.__self_class__
psutil._compat.super.__thisclass__

# Stubtest does not support these platforms
psutil._psaix
psutil._psbsd
psutil._psosx
psutil._psutil_windows
psutil._pswindows
psutil._pssunos

# Test utilities
psutil.tests.*
4 changes: 4 additions & 0 deletions stubs/psutil/@tests/stubtest_allowlist_darwin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
psutil._pslinux
psutil._psutil_linux
psutil._psutil_windows
psutil._pswindows
4 changes: 4 additions & 0 deletions stubs/psutil/@tests/stubtest_allowlist_linux.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
psutil._psosx
psutil._psutil_windows
psutil._psutil_osx
psutil._pswindows
6 changes: 6 additions & 0 deletions stubs/psutil/@tests/stubtest_allowlist_win32.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
psutil._pslinux
psutil._psosx

psutil._psutil_linux
psutil._psutil_osx
psutil._psutil_posix
4 changes: 4 additions & 0 deletions stubs/psutil/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
version = "5.9.*"

[tool.stubtest]
ignore_missing_stub = false
platforms = ["win32", "linux", "darwin"]
67 changes: 28 additions & 39 deletions stubs/psutil/psutil/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from contextlib import AbstractContextManager
from typing import Any, overload
from typing_extensions import Literal, TypeAlias

from ._common import (
from psutil._common import (
AIX as AIX,
BSD as BSD,
CONN_CLOSE as CONN_CLOSE,
Expand Down Expand Up @@ -59,7 +59,6 @@ from ._common import (
popenfile,
pthread,
puids,
sbattery,
sconn,
scpufreq,
scpustats,
Expand All @@ -82,6 +81,26 @@ if sys.platform == "linux":
IOPRIO_CLASS_NONE as IOPRIO_CLASS_NONE,
IOPRIO_CLASS_RT as IOPRIO_CLASS_RT,
)
def sensors_temperatures(fahrenheit: bool = ...) -> dict[str, list[shwtemp]]: ...
def sensors_fans() -> dict[str, list[sfan]]: ...
PROCFS_PATH: str
RLIMIT_AS: int
RLIMIT_CORE: int
RLIMIT_CPU: int
RLIMIT_DATA: int
RLIMIT_FSIZE: int
RLIMIT_LOCKS: int
RLIMIT_MEMLOCK: int
RLIMIT_MSGQUEUE: int
RLIMIT_NICE: int
RLIMIT_NOFILE: int
RLIMIT_NPROC: int
RLIMIT_RSS: int
RLIMIT_RTPRIO: int
RLIMIT_RTTIME: int
RLIMIT_SIGPENDING: int
RLIMIT_STACK: int
RLIM_INFINITY: int
if sys.platform == "win32":
from ._psutil_windows import (
ABOVE_NORMAL_PRIORITY_CLASS as ABOVE_NORMAL_PRIORITY_CLASS,
Expand All @@ -102,18 +121,18 @@ if sys.platform == "win32":
)

if sys.platform == "linux":
from ._pslinux import pfullmem, pmem, svmem
from ._pslinux import pfullmem, pmem, sensors_battery as sensors_battery, svmem
elif sys.platform == "darwin":
from ._psosx import pfullmem, pmem, svmem
from ._psosx import pfullmem, pmem, sensors_battery as sensors_battery, svmem
elif sys.platform == "win32":
from ._pswindows import pfullmem, pmem, svmem
from ._pswindows import pfullmem, pmem, sensors_battery as sensors_battery, svmem
else:
class pmem(Any): ...
class pfullmem(Any): ...
class svmem(Any): ...

if sys.platform == "linux":
PROCFS_PATH: str
def sensors_battery(): ...

AF_LINK: int
version_info: tuple[int, int, int]
__version__: str
Expand Down Expand Up @@ -167,11 +186,10 @@ class Process:
if sys.platform != "darwin":
def io_counters(self): ...
def ionice(self, ioclass: int | None = ..., value: int | None = ...) -> pionice: ...
if sys.platform == "linux":
def rlimit(self, resource: int, limits: tuple[int, int] | None = ...) -> tuple[int, int]: ...
if sys.platform != "darwin":
def cpu_affinity(self, cpus: list[int] | None = ...) -> list[int] | None: ...
def memory_maps(self, grouped: bool = ...): ...
if sys.platform == "linux":
def rlimit(self, resource: int, limits: tuple[int, int] | None = ...) -> tuple[int, int]: ...
def cpu_num(self) -> int: ...

def environ(self) -> dict[str, str]: ...
Expand All @@ -188,9 +206,6 @@ class Process:
def memory_info_ex(self) -> pmem: ...
def memory_full_info(self) -> pfullmem: ...
def memory_percent(self, memtype: str = ...) -> float: ...
if sys.platform != "darwin":
def memory_maps(self, grouped: bool = ...): ...

def open_files(self) -> list[popenfile]: ...
def connections(self, kind: str = ...) -> list[pconn]: ...
def send_signal(self, sig: int) -> None: ...
Expand Down Expand Up @@ -236,31 +251,5 @@ def net_io_counters(pernic: Literal[True], nowrap: bool = ...) -> dict[str, snet
def net_connections(kind: str = ...) -> list[sconn]: ...
def net_if_addrs() -> dict[str, list[snicaddr]]: ...
def net_if_stats() -> dict[str, snicstats]: ...

if sys.platform == "linux":
def sensors_temperatures(fahrenheit: bool = ...) -> dict[str, list[shwtemp]]: ...
def sensors_fans() -> dict[str, list[sfan]]: ...

if sys.platform != "win32":
def sensors_battery() -> sbattery | None: ...

def boot_time() -> float: ...
def users() -> list[suser]: ...

if sys.platform == "linux":
RLIMIT_AS: int
RLIMIT_CORE: int
RLIMIT_CPU: int
RLIMIT_DATA: int
RLIMIT_FSIZE: int
RLIMIT_LOCKS: int
RLIMIT_MEMLOCK: int
RLIMIT_MSGQUEUE: int
RLIMIT_NICE: int
RLIMIT_NOFILE: int
RLIMIT_NPROC: int
RLIMIT_RSS: int
RLIMIT_RTPRIO: int
RLIMIT_SIGPENDING: int
RLIMIT_STACK: int
RLIM_INFINITY: int
6 changes: 5 additions & 1 deletion stubs/psutil/psutil/_common.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import enum
from _typeshed import StrOrBytesPath, SupportsWrite
from collections.abc import Callable
from socket import AddressFamily, SocketKind
from socket import AF_INET6 as AF_INET6, AddressFamily, SocketKind
from typing import Any, NamedTuple, TypeVar, overload
from typing_extensions import Literal

Expand Down Expand Up @@ -274,6 +274,10 @@ class _WrapNumbers:
def cache_info(self): ...

def wrap_numbers(input_dict, name: str): ...
def open_binary(fname): ...
def open_text(fname): ...
def cat(fname, fallback=..., _open=...): ...
def bcat(fname, fallback=...): ...
def bytes2human(n: int, format: str = ...) -> str: ...
def get_procfs_path() -> str: ...
def term_supports_colors(file: SupportsWrite[str] = ...) -> bool: ...
Expand Down
18 changes: 18 additions & 0 deletions stubs/psutil/psutil/_compat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,22 @@ from builtins import (
InterruptedError as InterruptedError,
PermissionError as PermissionError,
ProcessLookupError as ProcessLookupError,
range as range,
super as super,
)
from contextlib import redirect_stderr as redirect_stderr
from functools import lru_cache as lru_cache
from shutil import get_terminal_size as get_terminal_size, which as which
from subprocess import TimeoutExpired
from typing_extensions import Literal

PY3: Literal[True]
long = int
xrange = range
unicode = str
basestring = str

def u(s): ...
def b(s): ...

SubprocessTimeoutExpired = TimeoutExpired
104 changes: 104 additions & 0 deletions stubs/psutil/psutil/_psaix.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from _typeshed import Incomplete
from typing import NamedTuple

from psutil._common import (
NIC_DUPLEX_FULL as NIC_DUPLEX_FULL,
NIC_DUPLEX_HALF as NIC_DUPLEX_HALF,
NIC_DUPLEX_UNKNOWN as NIC_DUPLEX_UNKNOWN,
AccessDenied as AccessDenied,
NoSuchProcess as NoSuchProcess,
ZombieProcess as ZombieProcess,
conn_to_ntuple as conn_to_ntuple,
get_procfs_path as get_procfs_path,
memoize_when_activated as memoize_when_activated,
usage_percent as usage_percent,
)
from psutil._compat import (
PY3 as PY3,
FileNotFoundError as FileNotFoundError,
PermissionError as PermissionError,
ProcessLookupError as ProcessLookupError,
)

__extra__all__: Incomplete
HAS_THREADS: Incomplete
HAS_NET_IO_COUNTERS: Incomplete
HAS_PROC_IO_COUNTERS: Incomplete
PAGE_SIZE: Incomplete
AF_LINK: Incomplete
PROC_STATUSES: Incomplete
TCP_STATUSES: Incomplete
proc_info_map: Incomplete

class pmem(NamedTuple):
rss: Incomplete
vms: Incomplete

pfullmem = pmem

class scputimes(NamedTuple):
user: Incomplete
system: Incomplete
idle: Incomplete
iowait: Incomplete

class svmem(NamedTuple):
total: Incomplete
available: Incomplete
percent: Incomplete
used: Incomplete
free: Incomplete

def virtual_memory(): ...
def swap_memory(): ...
def cpu_times(): ...
def per_cpu_times(): ...
def cpu_count_logical(): ...
def cpu_count_cores(): ...
def cpu_stats(): ...

disk_io_counters: Incomplete
disk_usage: Incomplete

def disk_partitions(all: bool = ...): ...

net_if_addrs: Incomplete
net_io_counters: Incomplete

def net_connections(kind, _pid: int = ...): ...
def net_if_stats(): ...
def boot_time(): ...
def users(): ...
def pids(): ...
def pid_exists(pid): ...
def wrap_exceptions(fun): ...

class Process:
pid: Incomplete
def __init__(self, pid) -> None: ...
def oneshot_enter(self) -> None: ...
def oneshot_exit(self) -> None: ...
def name(self): ...
def exe(self): ...
def cmdline(self): ...
def environ(self): ...
def create_time(self): ...
def num_threads(self): ...
def threads(self): ...
def connections(self, kind: str = ...): ...
def nice_get(self): ...
def nice_set(self, value): ...
def ppid(self): ...
def uids(self): ...
def gids(self): ...
def cpu_times(self): ...
def terminal(self): ...
def cwd(self): ...
def memory_info(self): ...
memory_full_info: Incomplete
def status(self): ...
def open_files(self): ...
def num_fds(self): ...
def num_ctx_switches(self): ...
def wait(self, timeout: Incomplete | None = ...): ...
def io_counters(self): ...
2 changes: 1 addition & 1 deletion stubs/psutil/psutil/_psbsd.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from contextlib import AbstractContextManager
from typing import Any, NamedTuple

from ._common import (
from psutil._common import (
FREEBSD as FREEBSD,
NETBSD as NETBSD,
OPENBSD as OPENBSD,
Expand Down
16 changes: 15 additions & 1 deletion stubs/psutil/psutil/_pslinux.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import enum
from _typeshed import Incomplete
from typing import Any, NamedTuple

from ._common import (
from psutil._common import (
NIC_DUPLEX_FULL as NIC_DUPLEX_FULL,
NIC_DUPLEX_HALF as NIC_DUPLEX_HALF,
NIC_DUPLEX_UNKNOWN as NIC_DUPLEX_UNKNOWN,
Expand All @@ -14,9 +15,12 @@ from ._common import (
supports_ipv6 as supports_ipv6,
usage_percent as usage_percent,
)
from psutil._compat import PY3 as PY3

__extra__all__: Any
POWER_SUPPLY_PATH: str
HAS_PROC_SMAPS: bool
HAS_PROC_SMAPS_ROLLUP: bool
HAS_PROC_IO_PRIORITY: Any
HAS_CPU_AFFINITY: Any
CLOCK_TICKS: Any
Expand Down Expand Up @@ -154,6 +158,16 @@ def net_if_stats(): ...
disk_usage: Any

def disk_io_counters(perdisk: bool = ...): ...

class RootFsDeviceFinder:
major: Incomplete
minor: Incomplete
def __init__(self) -> None: ...
def ask_proc_partitions(self): ...
def ask_sys_dev_block(self): ...
def ask_sys_class_block(self): ...
def find(self): ...

def disk_partitions(all: bool = ...): ...
def sensors_temperatures(): ...
def sensors_fans(): ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/psutil/psutil/_psosx.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, NamedTuple

from ._common import (
from psutil._common import (
AccessDenied as AccessDenied,
NoSuchProcess as NoSuchProcess,
ZombieProcess as ZombieProcess,
Expand Down
Loading