diff --git a/stubs/psutil/psutil/_pslinux.pyi b/stubs/psutil/psutil/_pslinux.pyi index 295c6c61744b..a0ca74631346 100644 --- a/stubs/psutil/psutil/_pslinux.pyi +++ b/stubs/psutil/psutil/_pslinux.pyi @@ -1,237 +1,288 @@ -import enum -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, - isfile_strict as isfile_strict, - parse_environ_block as parse_environ_block, - path_exists_strict as path_exists_strict, - supports_ipv6 as supports_ipv6, - usage_percent as usage_percent, -) - -__extra__all__: Incomplete -POWER_SUPPLY_PATH: str -HAS_PROC_SMAPS: bool -HAS_PROC_SMAPS_ROLLUP: bool -HAS_PROC_IO_PRIORITY: Incomplete -HAS_CPU_AFFINITY: Incomplete -CLOCK_TICKS: Incomplete -PAGESIZE: Incomplete -LITTLE_ENDIAN: Incomplete -UNSET: object -DISK_SECTOR_SIZE: int -AF_LINK: Incomplete -AddressFamily: Incomplete -IOPRIO_CLASS_NONE: int -IOPRIO_CLASS_RT: int -IOPRIO_CLASS_BE: int -IOPRIO_CLASS_IDLE: int - -class IOPriority(enum.IntEnum): - IOPRIO_CLASS_NONE = 0 - IOPRIO_CLASS_RT = 1 - IOPRIO_CLASS_BE = 2 - IOPRIO_CLASS_IDLE = 3 - -PROC_STATUSES: Incomplete -TCP_STATUSES: Incomplete - -class svmem(NamedTuple): - total: int - available: int - percent: float - used: int - free: int - active: int - inactive: int - buffers: int - cached: int - shared: int - slab: int - -class sdiskio(NamedTuple): - read_count: Incomplete - write_count: Incomplete - read_bytes: Incomplete - write_bytes: Incomplete - read_time: Incomplete - write_time: Incomplete - read_merged_count: Incomplete - write_merged_count: Incomplete - busy_time: Incomplete - -class popenfile(NamedTuple): - path: Incomplete - fd: Incomplete - position: Incomplete - mode: Incomplete - flags: Incomplete - -class pmem(NamedTuple): - rss: Incomplete - vms: Incomplete - shared: Incomplete - text: Incomplete - lib: Incomplete - data: Incomplete - dirty: Incomplete - -class pfullmem(NamedTuple): - rss: Incomplete - vms: Incomplete - shared: Incomplete - text: Incomplete - lib: Incomplete - data: Incomplete - dirty: Incomplete - uss: Incomplete - pss: Incomplete - swap: Incomplete - -class pmmap_grouped(NamedTuple): - path: Incomplete - rss: Incomplete - size: Incomplete - pss: Incomplete - shared_clean: Incomplete - shared_dirty: Incomplete - private_clean: Incomplete - private_dirty: Incomplete - referenced: Incomplete - anonymous: Incomplete - swap: Incomplete - -pmmap_ext: Incomplete - -class pio(NamedTuple): - read_count: Incomplete - write_count: Incomplete - read_bytes: Incomplete - write_bytes: Incomplete - read_chars: Incomplete - write_chars: Incomplete - -class pcputimes(NamedTuple): - user: float - system: float - children_user: float - children_system: float - iowait: float - -def readlink(path): ... -def file_flags_to_mode(flags): ... -def is_storage_device(name): ... -def set_scputimes_ntuple(procfs_path) -> None: ... - -class scputimes(NamedTuple): - # Note: scputimes has different fields depending on exactly how Linux - # is setup, but we'll include the "complete" set of fields - user: float - nice: float - system: float - idle: float - iowait: float - irq: float - softirq: float - steal: float - guest: float - guest_nice: float - -def calculate_avail_vmem(mems): ... -def virtual_memory() -> svmem: ... -def swap_memory(): ... -def cpu_times(): ... -def per_cpu_times(): ... -def cpu_count_logical(): ... -def cpu_count_cores() -> int | None: ... -def cpu_stats(): ... -def cpu_freq(): ... - -net_if_addrs: Incomplete - -class _Ipv6UnsupportedError(Exception): ... - -class NetConnections: - tmap: Incomplete - def __init__(self) -> None: ... - def get_proc_inodes(self, pid): ... - def get_all_inodes(self): ... - @staticmethod - def decode_address(addr, family): ... - @staticmethod - def process_inet(file, family, type_, inodes, filter_pid: Incomplete | None = ...) -> None: ... - @staticmethod - def process_unix(file, family, inodes, filter_pid: Incomplete | None = ...) -> None: ... - def retrieve(self, kind, pid: Incomplete | None = ...): ... - -def net_connections(kind: str = ...): ... -def net_io_counters(): ... -def net_if_stats(): ... - -disk_usage: Incomplete - -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(): ... -def sensors_battery(): ... -def users(): ... -def boot_time(): ... -def pids(): ... -def pid_exists(pid): ... -def ppid_map(): ... -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 terminal(self): ... - def io_counters(self) -> pio: ... - def cpu_times(self): ... - def cpu_num(self): ... - def wait(self, timeout: Incomplete | None = ...): ... - def create_time(self, monotonic: bool = False) -> float: ... - def memory_info(self): ... - def memory_full_info(self): ... - def memory_maps(self): ... - def cwd(self): ... - def num_ctx_switches(self, _ctxsw_re=...): ... - def num_threads(self, _num_threads_re=...): ... - def threads(self): ... - def nice_get(self): ... - def nice_set(self, value): ... - def cpu_affinity_get(self): ... - def cpu_affinity_set(self, cpus) -> None: ... - def ionice_get(self): ... - def ionice_set(self, ioclass, value): ... - def rlimit(self, resource_, limits: Incomplete | None = ...): ... - def status(self): ... - def open_files(self): ... - def net_connections(self, kind: str = ...): ... - def num_fds(self): ... - def ppid(self): ... - def uids(self, _uids_re=...): ... - def gids(self, _gids_re=...): ... +import sys + +if sys.platform == "linux": + import enum + import re + from _typeshed import FileDescriptorOrPath, Incomplete + from collections import defaultdict + from collections.abc import Callable, Generator, Sequence + from typing import Final, NamedTuple, TypeVar, overload + from typing_extensions import ParamSpec + + from psutil._common import ( + ENCODING as ENCODING, + 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, + bcat as bcat, + cat as cat, + debug as debug, + decode as decode, + get_procfs_path as get_procfs_path, + isfile_strict as isfile_strict, + memoize as memoize, + memoize_when_activated as memoize_when_activated, + open_binary as open_binary, + open_text as open_text, + parse_environ_block as parse_environ_block, + path_exists_strict as path_exists_strict, + supports_ipv6 as supports_ipv6, + usage_percent as usage_percent, + ) + + from . import _common, _psposix, _psutil_linux + + _P = ParamSpec("_P") + _R = TypeVar("_R") + + __extra__all__: Final[list[str]] + POWER_SUPPLY_PATH: Final = "/sys/class/power_supply" + HAS_PROC_SMAPS: Final[bool] + HAS_PROC_SMAPS_ROLLUP: Final[bool] + HAS_PROC_IO_PRIORITY: Final[bool] + HAS_CPU_AFFINITY: Final[bool] + CLOCK_TICKS: Final[int] + PAGESIZE: Final[int] + LITTLE_ENDIAN: Final[bool] + UNSET: object + DISK_SECTOR_SIZE: Final = 512 + + class AddressFamily(enum.IntEnum): + AF_LINK = 17 # = socket.AF_PACKET + + AF_LINK: Final = AddressFamily.AF_LINK + + class IOPriority(enum.IntEnum): + IOPRIO_CLASS_NONE = 0 + IOPRIO_CLASS_RT = 1 + IOPRIO_CLASS_BE = 2 + IOPRIO_CLASS_IDLE = 3 + + IOPRIO_CLASS_NONE: Final = IOPriority.IOPRIO_CLASS_NONE + IOPRIO_CLASS_RT: Final = IOPriority.IOPRIO_CLASS_RT + IOPRIO_CLASS_BE: Final = IOPriority.IOPRIO_CLASS_BE + IOPRIO_CLASS_IDLE: Final = IOPriority.IOPRIO_CLASS_IDLE + + PROC_STATUSES: Final[dict[str, str]] + TCP_STATUSES: Final[dict[str, str]] + + class svmem(NamedTuple): + total: int + available: int + percent: float + used: int + free: int + active: int + inactive: int + buffers: int + cached: int + shared: int + slab: int + + class sdiskio(NamedTuple): + read_count: Incomplete + write_count: Incomplete + read_bytes: Incomplete + write_bytes: Incomplete + read_time: Incomplete + write_time: Incomplete + read_merged_count: Incomplete + write_merged_count: Incomplete + busy_time: Incomplete + + class popenfile(NamedTuple): + path: str + fd: int + position: int + mode: str + flags: int + + class pmem(NamedTuple): + rss: int + vms: int + shared: int + text: int + lib: int + data: int + dirty: int + + class pfullmem(NamedTuple): + rss: int + vms: int + shared: int + text: int + lib: int + data: int + dirty: int + uss: int + pss: int + swap: int + + class pmmap_grouped(NamedTuple): + path: Incomplete + rss: Incomplete + size: Incomplete + pss: Incomplete + shared_clean: Incomplete + shared_dirty: Incomplete + private_clean: Incomplete + private_dirty: Incomplete + referenced: Incomplete + anonymous: Incomplete + swap: Incomplete + + class pmmap_ext(NamedTuple): + addr: Incomplete + perms: Incomplete + path: Incomplete + rss: Incomplete + size: Incomplete + pss: Incomplete + shared_clean: Incomplete + shared_dirty: Incomplete + private_clean: Incomplete + private_dirty: Incomplete + referenced: Incomplete + anonymous: Incomplete + swap: Incomplete + + class pio(NamedTuple): + read_count: int + write_count: int + read_bytes: int + write_bytes: int + read_chars: int + write_chars: int + + class pcputimes(NamedTuple): + user: float + system: float + children_user: float + children_system: float + iowait: float + + def readlink(path: str) -> str: ... + def file_flags_to_mode(flags: int) -> str: ... + def is_storage_device(name: str) -> bool: ... + def set_scputimes_ntuple(procfs_path: str) -> None: ... + + class scputimes(NamedTuple): + # Note: scputimes has different fields depending on exactly how Linux + # is setup, but we'll include the "complete" set of fields + user: float + nice: float + system: float + idle: float + iowait: float + irq: float + softirq: float + steal: float + guest: float + guest_nice: float + + def calculate_avail_vmem(mems: dict[bytes, int]) -> int: ... + def virtual_memory() -> svmem: ... + def swap_memory() -> _common.sswap: ... + def cpu_times() -> scputimes: ... + def per_cpu_times() -> list[scputimes]: ... + def cpu_count_logical() -> int | None: ... + def cpu_count_cores() -> int | None: ... + def cpu_stats() -> _common.scpustats: ... + def cpu_freq() -> list[_common.scpufreq]: ... + + net_if_addrs = _psutil_linux.net_if_addrs + + class _Ipv6UnsupportedError(Exception): ... + + class NetConnections: + tmap: dict[str, tuple[tuple[str, int, int | None], ...]] + def __init__(self) -> None: ... + def get_proc_inodes(self, pid: int) -> defaultdict[str, list[tuple[int, int]]]: ... + def get_all_inodes(self) -> dict[str, list[tuple[int, int]]]: ... + @staticmethod + def decode_address(addr: str, family: int) -> _common.addr | tuple[()]: ... + @staticmethod + def process_inet( + file: str, family: int, type_: int, inodes: dict[str, list[tuple[int, int]]], filter_pid: int | None = None + ) -> Generator[tuple[int, int, int, _common.addr | tuple[()], _common.addr | tuple[()], str, int | None]]: ... + @staticmethod + def process_unix( + file: FileDescriptorOrPath, family: int, inodes: dict[str, list[tuple[int, int]]], filter_pid: int | None = None + ) -> Generator[tuple[int, int, int, str, str, str, int | None]]: ... + @overload + def retrieve(self, kind: str, pid: int) -> list[_common.pconn]: ... + @overload + def retrieve(self, kind: str, pid: None = None) -> list[_common.sconn]: ... + + def net_connections(kind: str = "inet") -> list[_common.sconn]: ... + def net_io_counters() -> dict[str, tuple[int, int, int, int, int, int, int, int]]: ... + def net_if_stats() -> dict[str, _common.snicstats]: ... + + disk_usage = _psposix.disk_usage + + def disk_io_counters(perdisk: bool = False) -> dict[str, tuple[int, int, int, int, int, int, int, int]]: ... + + class RootFsDeviceFinder: + __slots__ = ["major", "minor"] + major: int + minor: int + def __init__(self) -> None: ... + def ask_proc_partitions(self) -> str | None: ... + def ask_sys_dev_block(self) -> str | None: ... + def ask_sys_class_block(self) -> str | None: ... + def find(self) -> str | None: ... + + def disk_partitions(all: bool = False) -> list[_common.sdiskpart]: ... + def sensors_temperatures() -> dict[str, list[tuple[str, float, float | None, float | None]]]: ... + def sensors_fans() -> dict[str, list[_common.sfan]]: ... + def sensors_battery() -> _common.sbattery | None: ... + def users() -> list[_common.suser]: ... + def boot_time() -> float: ... + def pids() -> list[int]: ... + def pid_exists(pid: int) -> bool: ... + def ppid_map() -> dict[int, int]: ... + def wrap_exceptions(fun: Callable[_P, _R]) -> Callable[_P, _R]: ... + + class Process: + __slots__ = ["_cache", "_ctime", "_name", "_ppid", "_procfs_path", "pid"] + pid: int + def __init__(self, pid: int) -> None: ... + def oneshot_enter(self) -> None: ... + def oneshot_exit(self) -> None: ... + def name(self) -> str: ... + def exe(self) -> str: ... + def cmdline(self) -> list[str]: ... + def environ(self) -> dict[str, str]: ... + def terminal(self) -> str | None: ... + def io_counters(self) -> pio: ... + def cpu_times(self) -> pcputimes: ... + def cpu_num(self) -> int: ... + def wait(self, timeout: float | None = None): ... + def create_time(self, monotonic: bool = False) -> float: ... + def memory_info(self) -> pmem: ... + def memory_full_info(self) -> pfullmem: ... + def memory_maps(self) -> list[tuple[str, str, str, int, int, int, int, int, int, int, int, int, int]]: ... + def cwd(self) -> str: ... + def num_ctx_switches(self, _ctxsw_re: re.Pattern[bytes] = ...) -> _common.pctxsw: ... + def num_threads(self, _num_threads_re: re.Pattern[bytes] = ...) -> int: ... + def threads(self) -> list[_common.pthread]: ... + def nice_get(self) -> int: ... + def nice_set(self, value: int) -> None: ... + def cpu_affinity_get(self) -> list[int]: ... + def cpu_affinity_set(self, cpus: Sequence[int]) -> None: ... + def ionice_get(self) -> _common.pionice: ... + def ionice_set(self, ioclass: int, value: int | None) -> None: ... + @overload + def rlimit(self, resource_: int, limits: tuple[int, int]) -> None: ... + @overload + def rlimit(self, resource_: int, limits: None = None) -> tuple[int, int]: ... + def status(self) -> str: ... + def open_files(self) -> list[popenfile]: ... + def net_connections(self, kind: str = "inet") -> list[_common.pconn]: ... + def num_fds(self) -> int: ... + def ppid(self) -> int: ... + def uids(self, _uids_re: re.Pattern[bytes] = ...) -> _common.puids: ... + def gids(self, _gids_re: re.Pattern[bytes] = ...) -> _common.pgids: ... diff --git a/stubs/psutil/psutil/_psutil_linux.pyi b/stubs/psutil/psutil/_psutil_linux.pyi index 2c44a4cd5ded..9fb15b422834 100644 --- a/stubs/psutil/psutil/_psutil_linux.pyi +++ b/stubs/psutil/psutil/_psutil_linux.pyi @@ -1,45 +1,48 @@ -from _typeshed import Incomplete -from typing import Final +import sys -# TODO: Add POSIX constants and check their aviability (see psutil_posix_add_constants) -RLIM_INFINITY: Final[int] -RLIMIT_AS: Final[int] -RLIMIT_CORE: Final[int] -RLIMIT_CPU: Final[int] -RLIMIT_DATA: Final[int] -RLIMIT_FSIZE: Final[int] -RLIMIT_LOCKS: Final[int] -RLIMIT_MEMLOCK: Final[int] -RLIMIT_MSGQUEUE: Final[int] -RLIMIT_NICE: Final[int] -RLIMIT_NOFILE: Final[int] -RLIMIT_NPROC: Final[int] -RLIMIT_RSS: Final[int] -RLIMIT_RTPRIO: Final[int] -RLIMIT_RTTIME: Final[int] -RLIMIT_SIGPENDING: Final[int] -RLIMIT_STACK: Final[int] +if sys.platform == "linux": + from _typeshed import Incomplete + from collections.abc import Sequence + from typing import Final -def getpagesize() -> int: ... -def net_if_addrs(): ... -def net_if_flags(nic_name: str, /) -> list[str]: ... -def net_if_is_running(nic_name: str, /) -> bool: ... -def net_if_mtu(nic_name: str, /) -> int: ... -def proc_priority_get(pid: int, /) -> int: ... -def proc_priority_set(pid: int, priority: int, /) -> None: ... -def users() -> list[tuple[Incomplete, ...]]: ... + RLIMIT_AS: Final[int] + RLIMIT_CORE: Final[int] + RLIMIT_CPU: Final[int] + RLIMIT_DATA: Final[int] + RLIMIT_FSIZE: Final[int] + RLIMIT_MEMLOCK: Final[int] + RLIMIT_NOFILE: Final[int] + RLIMIT_NPROC: Final[int] + RLIMIT_RSS: Final[int] + RLIMIT_STACK: Final[int] + RLIMIT_LOCKS: Final[int] + RLIMIT_MSGQUEUE: Final[int] + RLIMIT_NICE: Final[int] + RLIMIT_RTPRIO: Final[int] + RLIMIT_RTTIME: Final[int] + RLIMIT_SIGPENDING: Final[int] + RLIM_INFINITY: Final[int] -version: int -DUPLEX_FULL: int -DUPLEX_HALF: int -DUPLEX_UNKNOWN: int + def getpagesize() -> int: ... + def net_if_addrs(): ... + def net_if_flags(nic_name: str, /) -> list[str]: ... + def net_if_is_running(nic_name: str, /) -> bool: ... + def net_if_mtu(nic_name: str, /) -> int: ... + def proc_priority_get(pid: int, /) -> int: ... + def proc_priority_set(pid: int, priority: int, /) -> None: ... + def users() -> list[tuple[Incomplete, ...]]: ... -def proc_ioprio_get(pid: int, /): ... -def proc_ioprio_set(*args, **kwargs): ... -def proc_cpu_affinity_get(pid: int, /): ... -def proc_cpu_affinity_set(*args, **kwargs): ... -def disk_partitions(mtab_path: str, /): ... -def net_if_duplex_speed(nic_name: str, /): ... -def linux_sysinfo() -> tuple[int, int, int, int, int, int, int]: ... -def check_pid_range(pid: int, /) -> None: ... -def set_debug(value: bool, /) -> None: ... + version: Final[int] + DUPLEX_FULL: Final[int] + DUPLEX_HALF: Final[int] + DUPLEX_UNKNOWN: Final[int] + + def proc_ioprio_get(pid: int, /) -> tuple[int, int]: ... + def proc_ioprio_set(pid: int, ioclass: int, iodata: int, /) -> None: ... + def proc_cpu_affinity_get(pid: int, /) -> list[int]: ... + def proc_cpu_affinity_set(pid: int, cpu_set: Sequence[int], /) -> None: ... + def disk_partitions(mtab_path: str, /) -> list[tuple[str, str, str, str]]: ... + def net_if_duplex_speed(nic_name: str, /) -> tuple[int, int]: ... # It's actually list of 2 elements + def linux_sysinfo() -> tuple[int, int, int, int, int, int, int]: ... + def check_pid_range(pid: int, /) -> None: ... + def set_debug(value: bool, /) -> None: ...