Skip to content

Commit 24971ad

Browse files
committed
[psutil] Complete OSX stubs
1 parent 1dad9a5 commit 24971ad

File tree

3 files changed

+200
-158
lines changed

3 files changed

+200
-158
lines changed

stubs/psutil/psutil/_psosx.pyi

Lines changed: 120 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,120 @@
1-
from _typeshed import Incomplete
2-
from typing import NamedTuple
3-
4-
from psutil._common import (
5-
AccessDenied as AccessDenied,
6-
NoSuchProcess as NoSuchProcess,
7-
ZombieProcess as ZombieProcess,
8-
conn_tmap as conn_tmap,
9-
conn_to_ntuple as conn_to_ntuple,
10-
isfile_strict as isfile_strict,
11-
parse_environ_block as parse_environ_block,
12-
usage_percent as usage_percent,
13-
)
14-
15-
__extra__all__: Incomplete
16-
PAGESIZE: Incomplete
17-
AF_LINK: Incomplete
18-
TCP_STATUSES: Incomplete
19-
PROC_STATUSES: Incomplete
20-
kinfo_proc_map: Incomplete
21-
pidtaskinfo_map: Incomplete
22-
23-
class scputimes(NamedTuple):
24-
user: float
25-
nice: float
26-
system: float
27-
idle: float
28-
29-
class svmem(NamedTuple):
30-
total: int
31-
available: int
32-
percent: float
33-
used: int
34-
free: int
35-
active: int
36-
inactive: int
37-
wired: int
38-
39-
class pmem(NamedTuple):
40-
rss: Incomplete
41-
vms: Incomplete
42-
pfaults: Incomplete
43-
pageins: Incomplete
44-
45-
class pfullmem(NamedTuple):
46-
rss: Incomplete
47-
vms: Incomplete
48-
pfaults: Incomplete
49-
pageins: Incomplete
50-
uss: Incomplete
51-
52-
def virtual_memory() -> svmem: ...
53-
def swap_memory(): ...
54-
def cpu_times(): ...
55-
def per_cpu_times(): ...
56-
def cpu_count_logical(): ...
57-
def cpu_count_cores() -> int | None: ...
58-
def cpu_stats(): ...
59-
def cpu_freq(): ...
60-
61-
disk_usage: Incomplete
62-
disk_io_counters: Incomplete
63-
64-
def disk_partitions(all: bool = False): ...
65-
def sensors_battery(): ...
66-
67-
net_io_counters: Incomplete
68-
net_if_addrs: Incomplete
69-
70-
def net_connections(kind: str = "inet"): ...
71-
def net_if_stats(): ...
72-
def boot_time(): ...
73-
def users(): ...
74-
def pids(): ...
75-
76-
pid_exists: Incomplete
77-
78-
def is_zombie(pid): ...
79-
def wrap_exceptions(fun): ...
80-
81-
class Process:
82-
__slots__ = ["_cache", "_name", "_ppid", "pid"]
83-
pid: Incomplete
84-
def __init__(self, pid) -> None: ...
85-
def oneshot_enter(self) -> None: ...
86-
def oneshot_exit(self) -> None: ...
87-
def name(self): ...
88-
def exe(self): ...
89-
def cmdline(self): ...
90-
def environ(self): ...
91-
def ppid(self): ...
92-
def cwd(self): ...
93-
def uids(self): ...
94-
def gids(self): ...
95-
def terminal(self): ...
96-
def memory_info(self): ...
97-
def memory_full_info(self): ...
98-
def cpu_times(self): ...
99-
def create_time(self): ...
100-
def num_ctx_switches(self): ...
101-
def num_threads(self): ...
102-
def open_files(self): ...
103-
def net_connections(self, kind: str = "inet"): ...
104-
def num_fds(self): ...
105-
def wait(self, timeout=None): ...
106-
def nice_get(self): ...
107-
def nice_set(self, value): ...
108-
def status(self): ...
109-
def threads(self): ...
1+
import sys
2+
3+
if sys.platform == "darwin":
4+
from collections.abc import Callable
5+
from typing import Final, NamedTuple, TypeVar
6+
from typing_extensions import ParamSpec
7+
8+
from psutil._common import (
9+
AccessDenied as AccessDenied,
10+
NoSuchProcess as NoSuchProcess,
11+
ZombieProcess as ZombieProcess,
12+
conn_tmap as conn_tmap,
13+
conn_to_ntuple as conn_to_ntuple,
14+
debug as debug,
15+
isfile_strict as isfile_strict,
16+
memoize_when_activated as memoize_when_activated,
17+
parse_environ_block as parse_environ_block,
18+
usage_percent as usage_percent,
19+
)
20+
21+
from . import _common, _psposix, _psutil_osx
22+
23+
_P = ParamSpec("_P")
24+
_R = TypeVar("_R")
25+
26+
__extra__all__: Final[list[str]]
27+
PAGESIZE: Final[int]
28+
AF_LINK: Final[int]
29+
TCP_STATUSES: Final[dict[int, str]]
30+
PROC_STATUSES: Final[dict[int, str]]
31+
kinfo_proc_map: Final[dict[str, int]]
32+
pidtaskinfo_map: Final[dict[str, int]]
33+
34+
class scputimes(NamedTuple):
35+
user: float
36+
nice: float
37+
system: float
38+
idle: float
39+
40+
class svmem(NamedTuple):
41+
total: int
42+
available: int
43+
percent: float
44+
used: int
45+
free: int
46+
active: int
47+
inactive: int
48+
wired: int
49+
50+
class pmem(NamedTuple):
51+
rss: int
52+
vms: int
53+
pfaults: int
54+
pageins: int
55+
56+
class pfullmem(NamedTuple):
57+
rss: int
58+
vms: int
59+
pfaults: int
60+
pageins: int
61+
uss: int
62+
63+
def virtual_memory() -> svmem: ...
64+
def swap_memory() -> _common.sswap: ...
65+
def cpu_times() -> scputimes: ...
66+
def per_cpu_times() -> list[scputimes]: ...
67+
def cpu_count_logical() -> int | None: ...
68+
def cpu_count_cores() -> int | None: ...
69+
def cpu_stats() -> _common.scpustats: ...
70+
def cpu_freq() -> list[_common.scpufreq]: ...
71+
72+
disk_usage = _psposix.disk_usage
73+
disk_io_counters = _psutil_osx.disk_io_counters
74+
75+
def disk_partitions(all: bool = False) -> list[_common.sdiskpart]: ...
76+
def sensors_battery() -> _common.sbattery | None: ...
77+
78+
net_io_counters = _psutil_osx.net_io_counters
79+
net_if_addrs = _psutil_osx.net_if_addrs
80+
81+
def net_connections(kind: str = "inet") -> list[_common.sconn]: ...
82+
def net_if_stats() -> dict[str, _common.snicstats]: ...
83+
def boot_time() -> float: ...
84+
def users() -> list[_common.suser]: ...
85+
def pids() -> list[int]: ...
86+
87+
pid_exists = _psposix.pid_exists
88+
89+
def is_zombie(pid: int) -> bool: ...
90+
def wrap_exceptions(fun: Callable[_P, _R]) -> Callable[_P, _R]: ...
91+
92+
class Process:
93+
__slots__ = ["_cache", "_name", "_ppid", "pid"]
94+
pid: int
95+
def __init__(self, pid: int) -> None: ...
96+
def oneshot_enter(self) -> None: ...
97+
def oneshot_exit(self) -> None: ...
98+
def name(self) -> str: ...
99+
def exe(self) -> str: ...
100+
def cmdline(self) -> list[str]: ...
101+
def environ(self) -> dict[str, str]: ...
102+
def ppid(self) -> int: ...
103+
def cwd(self) -> str: ...
104+
def uids(self) -> _common.puids: ...
105+
def gids(self) -> _common.puids: ...
106+
def terminal(self) -> str | None: ...
107+
def memory_info(self) -> pmem: ...
108+
def memory_full_info(self) -> pfullmem: ...
109+
def cpu_times(self) -> _common.pcputimes: ...
110+
def create_time(self) -> float: ...
111+
def num_ctx_switches(self) -> _common.pctxsw: ...
112+
def num_threads(self) -> int: ...
113+
def open_files(self) -> list[_common.popenfile]: ...
114+
def net_connections(self, kind: str = "inet"): ...
115+
def num_fds(self) -> int: ...
116+
def wait(self, timeout: float | None = None): ...
117+
def nice_get(self): ...
118+
def nice_set(self, value): ...
119+
def status(self) -> str: ...
120+
def threads(self) -> list[_common.pthread]: ...
Lines changed: 79 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,80 @@
1-
PSUTIL_CONN_NONE: int
2-
SIDL: int
3-
SRUN: int
4-
SSLEEP: int
5-
SSTOP: int
6-
SZOMB: int
7-
TCPS_CLOSED: int
8-
TCPS_CLOSE_WAIT: int
9-
TCPS_CLOSING: int
10-
TCPS_ESTABLISHED: int
11-
TCPS_FIN_WAIT_1: int
12-
TCPS_FIN_WAIT_2: int
13-
TCPS_LAST_ACK: int
14-
TCPS_LISTEN: int
15-
TCPS_SYN_RECEIVED: int
16-
TCPS_SYN_SENT: int
17-
TCPS_TIME_WAIT: int
18-
version: int
1+
import sys
192

20-
def boot_time(*args, **kwargs): ...
21-
def check_pid_range(pid: int, /) -> None: ...
22-
def cpu_count_cores(*args, **kwargs): ...
23-
def cpu_count_logical(*args, **kwargs): ...
24-
def cpu_freq(*args, **kwargs): ...
25-
def cpu_stats(*args, **kwargs): ...
26-
def cpu_times(*args, **kwargs): ...
27-
def disk_io_counters(*args, **kwargs): ...
28-
def disk_partitions(*args, **kwargs): ...
29-
def disk_usage_used(*args, **kwargs): ...
30-
def net_io_counters(*args, **kwargs): ...
31-
def per_cpu_times(*args, **kwargs): ...
32-
def pids(*args, **kwargs): ...
33-
def proc_cmdline(*args, **kwargs): ...
34-
def proc_net_connections(*args, **kwargs): ...
35-
def proc_cwd(*args, **kwargs): ...
36-
def proc_environ(*args, **kwargs): ...
37-
def proc_exe(*args, **kwargs): ...
38-
def proc_kinfo_oneshot(*args, **kwargs): ...
39-
def proc_memory_uss(*args, **kwargs): ...
40-
def proc_name(*args, **kwargs): ...
41-
def proc_num_fds(*args, **kwargs): ...
42-
def proc_open_files(*args, **kwargs): ...
43-
def proc_pidtaskinfo_oneshot(*args, **kwargs): ...
44-
def proc_threads(*args, **kwargs): ...
45-
def sensors_battery(*args, **kwargs): ...
46-
def set_debug(*args, **kwargs): ...
47-
def swap_mem(*args, **kwargs): ...
48-
def users(*args, **kwargs): ...
49-
def virtual_mem(*args, **kwargs): ...
3+
# TODO: Detect available POSIX constants/methods and import them in this module
4+
# (see psutil_posix_add_constants / psutil_posix_add_methods)
5+
6+
if sys.platform == "darwin":
7+
from _typeshed import StrOrBytesPath
8+
from collections.abc import Sequence
9+
from socket import AddressFamily, SocketKind
10+
from typing import Final, TypeVar
11+
12+
from ._psutil_posix import (
13+
AF_LINK as AF_LINK,
14+
getpagesize as getpagesize,
15+
net_if_addrs as net_if_addrs,
16+
net_if_duplex_speed as net_if_duplex_speed,
17+
net_if_flags as net_if_flags,
18+
net_if_is_running as net_if_is_running,
19+
net_if_mtu as net_if_mtu,
20+
proc_priority_get as proc_priority_get,
21+
proc_priority_set as proc_priority_set,
22+
)
23+
24+
_T = TypeVar("_T")
25+
26+
version: Final[int]
27+
SIDL: Final = 1
28+
SRUN: Final = 2
29+
SSLEEP: Final = 3
30+
SSTOP: Final = 4
31+
SZOMB: Final = 5
32+
TCPS_CLOSED: Final = 0
33+
TCPS_CLOSING: Final = 7
34+
TCPS_CLOSE_WAIT: Final = 5
35+
TCPS_LISTEN: Final = 1
36+
TCPS_ESTABLISHED: Final = 4
37+
TCPS_SYN_SENT: Final = 2
38+
TCPS_SYN_RECEIVED: Final = 3
39+
TCPS_FIN_WAIT_1: Final = 6
40+
TCPS_FIN_WAIT_2: Final = 9
41+
TCPS_LAST_ACK: Final = 8
42+
TCPS_TIME_WAIT: Final = 10
43+
PSUTIL_CONN_NONE: Final = 128
44+
45+
def proc_cmdline(pid: int, /) -> list[str]: ...
46+
def proc_cwd(pid: int, /) -> str: ...
47+
def proc_environ(pid: int, /) -> str: ...
48+
def proc_exe(pid: int, /) -> str: ...
49+
def proc_is_zombie(pid: int, /) -> bool: ...
50+
def proc_kinfo_oneshot(pid: int, /) -> tuple[int, int, int, int, int, int, int, float, int, str]: ...
51+
def proc_memory_uss(pid: int, /) -> int: ...
52+
def proc_name(pid: int, /) -> str: ...
53+
def proc_net_connections(
54+
pid: int, af_filter: Sequence[AddressFamily | int | None], type_filter: Sequence[SocketKind | int | None], /
55+
) -> list[
56+
tuple[int, int, int, tuple[str | None, int], tuple[str | None, int] | tuple[()], int]
57+
| tuple[int, int, int, str, str, int]
58+
]: ...
59+
def proc_num_fds(pid: int, /) -> int: ...
60+
def proc_open_files(pid: int, /) -> list[tuple[str, int]]: ...
61+
def proc_pidtaskinfo_oneshot(pid: int, /) -> tuple[float, float, int, int, int, int, int, int]: ...
62+
def proc_threads(pid: int, /) -> list[tuple[int, float, float]]: ...
63+
def boot_time() -> float: ...
64+
def cpu_count_cores() -> int | None: ...
65+
def cpu_count_logical() -> int | None: ...
66+
def cpu_freq() -> tuple[int, int, int]: ...
67+
def cpu_stats() -> tuple[int, int, int, int, int]: ...
68+
def cpu_times() -> tuple[float, float, float, float]: ...
69+
def disk_io_counters() -> dict[str, tuple[int, int, int, int, int, int]]: ...
70+
def disk_partitions() -> list[tuple[str, str, str, str]]: ...
71+
def disk_usage_used(mount_point: StrOrBytesPath, default: _T, /) -> int | _T: ...
72+
def has_cpu_freq() -> bool: ...
73+
def net_io_counters() -> dict[str, tuple[int, int, int, int, int, int, int, int]]: ...
74+
def per_cpu_times() -> list[tuple[float, float, float, float]]: ...
75+
def pids() -> list[int]: ...
76+
def sensors_battery() -> tuple[int, int, int]: ...
77+
def swap_mem() -> tuple[int, int, int, int, int]: ...
78+
def virtual_mem() -> tuple[int, int, int, int, int, int]: ...
79+
def check_pid_range(pid: int, /) -> None: ...
80+
def set_debug(value: bool, /) -> None: ...

stubs/psutil/psutil/_pswindows.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if sys.platform == "win32":
3333

3434
from . import _common
3535

36-
__extra__all__: list[str]
36+
__extra__all__: Final[list[str]]
3737
CONN_DELETE_TCB: Final = "DELETE_TCB"
3838
ERROR_PARTIAL_COPY: Final = 299
3939
PYPY: Final[bool]

0 commit comments

Comments
 (0)