Skip to content

Commit 75a74ff

Browse files
authored
Run stubtest for psutil on all platforms (#9169)
1 parent c0f96e1 commit 75a74ff

18 files changed

+485
-51
lines changed
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1+
# These super() dunders don't seem to be particularly useful,
2+
# and having them pop up on autocomplete suggestions would be annoying
3+
psutil._compat.super.__self__
4+
psutil._compat.super.__self_class__
5+
psutil._compat.super.__thisclass__
6+
7+
# Stubtest does not support these platforms
8+
psutil._psaix
19
psutil._psbsd
2-
psutil._psosx
3-
psutil._psutil_windows
4-
psutil._pswindows
10+
psutil._pssunos
11+
12+
# Test utilities
13+
psutil.tests.*
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
psutil._pslinux
2+
psutil._psutil_linux
3+
psutil._psutil_windows
4+
psutil._pswindows
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
psutil._psosx
2+
psutil._psutil_windows
3+
psutil._psutil_osx
4+
psutil._pswindows
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
psutil._pslinux
2+
psutil._psosx
3+
4+
psutil._psutil_linux
5+
psutil._psutil_osx
6+
psutil._psutil_posix

stubs/psutil/METADATA.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
version = "5.9.*"
2+
3+
[tool.stubtest]
4+
ignore_missing_stub = false
5+
platforms = ["win32", "linux", "darwin"]

stubs/psutil/psutil/__init__.pyi

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from contextlib import AbstractContextManager
55
from typing import Any, overload
66
from typing_extensions import Literal, TypeAlias
77

8-
from ._common import (
8+
from psutil._common import (
99
AIX as AIX,
1010
BSD as BSD,
1111
CONN_CLOSE as CONN_CLOSE,
@@ -59,7 +59,6 @@ from ._common import (
5959
popenfile,
6060
pthread,
6161
puids,
62-
sbattery,
6362
sconn,
6463
scpufreq,
6564
scpustats,
@@ -82,6 +81,26 @@ if sys.platform == "linux":
8281
IOPRIO_CLASS_NONE as IOPRIO_CLASS_NONE,
8382
IOPRIO_CLASS_RT as IOPRIO_CLASS_RT,
8483
)
84+
def sensors_temperatures(fahrenheit: bool = ...) -> dict[str, list[shwtemp]]: ...
85+
def sensors_fans() -> dict[str, list[sfan]]: ...
86+
PROCFS_PATH: str
87+
RLIMIT_AS: int
88+
RLIMIT_CORE: int
89+
RLIMIT_CPU: int
90+
RLIMIT_DATA: int
91+
RLIMIT_FSIZE: int
92+
RLIMIT_LOCKS: int
93+
RLIMIT_MEMLOCK: int
94+
RLIMIT_MSGQUEUE: int
95+
RLIMIT_NICE: int
96+
RLIMIT_NOFILE: int
97+
RLIMIT_NPROC: int
98+
RLIMIT_RSS: int
99+
RLIMIT_RTPRIO: int
100+
RLIMIT_RTTIME: int
101+
RLIMIT_SIGPENDING: int
102+
RLIMIT_STACK: int
103+
RLIM_INFINITY: int
85104
if sys.platform == "win32":
86105
from ._psutil_windows import (
87106
ABOVE_NORMAL_PRIORITY_CLASS as ABOVE_NORMAL_PRIORITY_CLASS,
@@ -102,18 +121,18 @@ if sys.platform == "win32":
102121
)
103122

104123
if sys.platform == "linux":
105-
from ._pslinux import pfullmem, pmem, svmem
124+
from ._pslinux import pfullmem, pmem, sensors_battery as sensors_battery, svmem
106125
elif sys.platform == "darwin":
107-
from ._psosx import pfullmem, pmem, svmem
126+
from ._psosx import pfullmem, pmem, sensors_battery as sensors_battery, svmem
108127
elif sys.platform == "win32":
109-
from ._pswindows import pfullmem, pmem, svmem
128+
from ._pswindows import pfullmem, pmem, sensors_battery as sensors_battery, svmem
110129
else:
111130
class pmem(Any): ...
112131
class pfullmem(Any): ...
113132
class svmem(Any): ...
114133

115-
if sys.platform == "linux":
116-
PROCFS_PATH: str
134+
def sensors_battery(): ...
135+
117136
AF_LINK: int
118137
version_info: tuple[int, int, int]
119138
__version__: str
@@ -167,11 +186,10 @@ class Process:
167186
if sys.platform != "darwin":
168187
def io_counters(self): ...
169188
def ionice(self, ioclass: int | None = ..., value: int | None = ...) -> pionice: ...
170-
if sys.platform == "linux":
171-
def rlimit(self, resource: int, limits: tuple[int, int] | None = ...) -> tuple[int, int]: ...
172-
if sys.platform != "darwin":
173189
def cpu_affinity(self, cpus: list[int] | None = ...) -> list[int] | None: ...
190+
def memory_maps(self, grouped: bool = ...): ...
174191
if sys.platform == "linux":
192+
def rlimit(self, resource: int, limits: tuple[int, int] | None = ...) -> tuple[int, int]: ...
175193
def cpu_num(self) -> int: ...
176194

177195
def environ(self) -> dict[str, str]: ...
@@ -188,9 +206,6 @@ class Process:
188206
def memory_info_ex(self) -> pmem: ...
189207
def memory_full_info(self) -> pfullmem: ...
190208
def memory_percent(self, memtype: str = ...) -> float: ...
191-
if sys.platform != "darwin":
192-
def memory_maps(self, grouped: bool = ...): ...
193-
194209
def open_files(self) -> list[popenfile]: ...
195210
def connections(self, kind: str = ...) -> list[pconn]: ...
196211
def send_signal(self, sig: int) -> None: ...
@@ -236,31 +251,5 @@ def net_io_counters(pernic: Literal[True], nowrap: bool = ...) -> dict[str, snet
236251
def net_connections(kind: str = ...) -> list[sconn]: ...
237252
def net_if_addrs() -> dict[str, list[snicaddr]]: ...
238253
def net_if_stats() -> dict[str, snicstats]: ...
239-
240-
if sys.platform == "linux":
241-
def sensors_temperatures(fahrenheit: bool = ...) -> dict[str, list[shwtemp]]: ...
242-
def sensors_fans() -> dict[str, list[sfan]]: ...
243-
244-
if sys.platform != "win32":
245-
def sensors_battery() -> sbattery | None: ...
246-
247254
def boot_time() -> float: ...
248255
def users() -> list[suser]: ...
249-
250-
if sys.platform == "linux":
251-
RLIMIT_AS: int
252-
RLIMIT_CORE: int
253-
RLIMIT_CPU: int
254-
RLIMIT_DATA: int
255-
RLIMIT_FSIZE: int
256-
RLIMIT_LOCKS: int
257-
RLIMIT_MEMLOCK: int
258-
RLIMIT_MSGQUEUE: int
259-
RLIMIT_NICE: int
260-
RLIMIT_NOFILE: int
261-
RLIMIT_NPROC: int
262-
RLIMIT_RSS: int
263-
RLIMIT_RTPRIO: int
264-
RLIMIT_SIGPENDING: int
265-
RLIMIT_STACK: int
266-
RLIM_INFINITY: int

stubs/psutil/psutil/_common.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import enum
22
from _typeshed import StrOrBytesPath, SupportsWrite
33
from collections.abc import Callable
4-
from socket import AddressFamily, SocketKind
4+
from socket import AF_INET6 as AF_INET6, AddressFamily, SocketKind
55
from typing import Any, NamedTuple, TypeVar, overload
66
from typing_extensions import Literal
77

@@ -274,6 +274,10 @@ class _WrapNumbers:
274274
def cache_info(self): ...
275275

276276
def wrap_numbers(input_dict, name: str): ...
277+
def open_binary(fname): ...
278+
def open_text(fname): ...
279+
def cat(fname, fallback=..., _open=...): ...
280+
def bcat(fname, fallback=...): ...
277281
def bytes2human(n: int, format: str = ...) -> str: ...
278282
def get_procfs_path() -> str: ...
279283
def term_supports_colors(file: SupportsWrite[str] = ...) -> bool: ...

stubs/psutil/psutil/_compat.pyi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,22 @@ from builtins import (
55
InterruptedError as InterruptedError,
66
PermissionError as PermissionError,
77
ProcessLookupError as ProcessLookupError,
8+
range as range,
9+
super as super,
810
)
11+
from contextlib import redirect_stderr as redirect_stderr
12+
from functools import lru_cache as lru_cache
13+
from shutil import get_terminal_size as get_terminal_size, which as which
14+
from subprocess import TimeoutExpired
15+
from typing_extensions import Literal
16+
17+
PY3: Literal[True]
18+
long = int
19+
xrange = range
20+
unicode = str
21+
basestring = str
22+
23+
def u(s): ...
24+
def b(s): ...
25+
26+
SubprocessTimeoutExpired = TimeoutExpired

stubs/psutil/psutil/_psaix.pyi

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
from _typeshed import Incomplete
2+
from typing import NamedTuple
3+
4+
from psutil._common import (
5+
NIC_DUPLEX_FULL as NIC_DUPLEX_FULL,
6+
NIC_DUPLEX_HALF as NIC_DUPLEX_HALF,
7+
NIC_DUPLEX_UNKNOWN as NIC_DUPLEX_UNKNOWN,
8+
AccessDenied as AccessDenied,
9+
NoSuchProcess as NoSuchProcess,
10+
ZombieProcess as ZombieProcess,
11+
conn_to_ntuple as conn_to_ntuple,
12+
get_procfs_path as get_procfs_path,
13+
memoize_when_activated as memoize_when_activated,
14+
usage_percent as usage_percent,
15+
)
16+
from psutil._compat import (
17+
PY3 as PY3,
18+
FileNotFoundError as FileNotFoundError,
19+
PermissionError as PermissionError,
20+
ProcessLookupError as ProcessLookupError,
21+
)
22+
23+
__extra__all__: Incomplete
24+
HAS_THREADS: Incomplete
25+
HAS_NET_IO_COUNTERS: Incomplete
26+
HAS_PROC_IO_COUNTERS: Incomplete
27+
PAGE_SIZE: Incomplete
28+
AF_LINK: Incomplete
29+
PROC_STATUSES: Incomplete
30+
TCP_STATUSES: Incomplete
31+
proc_info_map: Incomplete
32+
33+
class pmem(NamedTuple):
34+
rss: Incomplete
35+
vms: Incomplete
36+
37+
pfullmem = pmem
38+
39+
class scputimes(NamedTuple):
40+
user: Incomplete
41+
system: Incomplete
42+
idle: Incomplete
43+
iowait: Incomplete
44+
45+
class svmem(NamedTuple):
46+
total: Incomplete
47+
available: Incomplete
48+
percent: Incomplete
49+
used: Incomplete
50+
free: Incomplete
51+
52+
def virtual_memory(): ...
53+
def swap_memory(): ...
54+
def cpu_times(): ...
55+
def per_cpu_times(): ...
56+
def cpu_count_logical(): ...
57+
def cpu_count_cores(): ...
58+
def cpu_stats(): ...
59+
60+
disk_io_counters: Incomplete
61+
disk_usage: Incomplete
62+
63+
def disk_partitions(all: bool = ...): ...
64+
65+
net_if_addrs: Incomplete
66+
net_io_counters: Incomplete
67+
68+
def net_connections(kind, _pid: int = ...): ...
69+
def net_if_stats(): ...
70+
def boot_time(): ...
71+
def users(): ...
72+
def pids(): ...
73+
def pid_exists(pid): ...
74+
def wrap_exceptions(fun): ...
75+
76+
class Process:
77+
pid: Incomplete
78+
def __init__(self, pid) -> None: ...
79+
def oneshot_enter(self) -> None: ...
80+
def oneshot_exit(self) -> None: ...
81+
def name(self): ...
82+
def exe(self): ...
83+
def cmdline(self): ...
84+
def environ(self): ...
85+
def create_time(self): ...
86+
def num_threads(self): ...
87+
def threads(self): ...
88+
def connections(self, kind: str = ...): ...
89+
def nice_get(self): ...
90+
def nice_set(self, value): ...
91+
def ppid(self): ...
92+
def uids(self): ...
93+
def gids(self): ...
94+
def cpu_times(self): ...
95+
def terminal(self): ...
96+
def cwd(self): ...
97+
def memory_info(self): ...
98+
memory_full_info: Incomplete
99+
def status(self): ...
100+
def open_files(self): ...
101+
def num_fds(self): ...
102+
def num_ctx_switches(self): ...
103+
def wait(self, timeout: Incomplete | None = ...): ...
104+
def io_counters(self): ...

stubs/psutil/psutil/_psbsd.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from contextlib import AbstractContextManager
22
from typing import Any, NamedTuple
33

4-
from ._common import (
4+
from psutil._common import (
55
FREEBSD as FREEBSD,
66
NETBSD as NETBSD,
77
OPENBSD as OPENBSD,

stubs/psutil/psutil/_pslinux.pyi

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import enum
2+
from _typeshed import Incomplete
23
from typing import Any, NamedTuple
34

4-
from ._common import (
5+
from psutil._common import (
56
NIC_DUPLEX_FULL as NIC_DUPLEX_FULL,
67
NIC_DUPLEX_HALF as NIC_DUPLEX_HALF,
78
NIC_DUPLEX_UNKNOWN as NIC_DUPLEX_UNKNOWN,
@@ -14,9 +15,12 @@ from ._common import (
1415
supports_ipv6 as supports_ipv6,
1516
usage_percent as usage_percent,
1617
)
18+
from psutil._compat import PY3 as PY3
1719

1820
__extra__all__: Any
1921
POWER_SUPPLY_PATH: str
22+
HAS_PROC_SMAPS: bool
23+
HAS_PROC_SMAPS_ROLLUP: bool
2024
HAS_PROC_IO_PRIORITY: Any
2125
HAS_CPU_AFFINITY: Any
2226
CLOCK_TICKS: Any
@@ -154,6 +158,16 @@ def net_if_stats(): ...
154158
disk_usage: Any
155159

156160
def disk_io_counters(perdisk: bool = ...): ...
161+
162+
class RootFsDeviceFinder:
163+
major: Incomplete
164+
minor: Incomplete
165+
def __init__(self) -> None: ...
166+
def ask_proc_partitions(self): ...
167+
def ask_sys_dev_block(self): ...
168+
def ask_sys_class_block(self): ...
169+
def find(self): ...
170+
157171
def disk_partitions(all: bool = ...): ...
158172
def sensors_temperatures(): ...
159173
def sensors_fans(): ...

stubs/psutil/psutil/_psosx.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, NamedTuple
22

3-
from ._common import (
3+
from psutil._common import (
44
AccessDenied as AccessDenied,
55
NoSuchProcess as NoSuchProcess,
66
ZombieProcess as ZombieProcess,

0 commit comments

Comments
 (0)