Browse Source

Intermediate changes
commit_hash:7397103fe9ab37aa08b57da5e3a0f5797270d528

robot-piglet 2 months ago
parent
commit
ef8c4a245b

+ 3 - 1
contrib/python/psutil/py3/.dist-info/METADATA

@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Name: psutil
-Version: 6.1.0
+Version: 6.1.1
 Summary: Cross-platform lib for process and system monitoring in Python.
 Home-page: https://github.com/giampaolo/psutil
 Author: Giampaolo Rodola
@@ -56,6 +56,7 @@ Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*
 Description-Content-Type: text/x-rst
 License-File: LICENSE
 Provides-Extra: dev
+Requires-Dist: abi3audit ; extra == 'dev'
 Requires-Dist: black ; extra == 'dev'
 Requires-Dist: check-manifest ; extra == 'dev'
 Requires-Dist: coverage ; extra == 'dev'
@@ -72,6 +73,7 @@ Requires-Dist: sphinx-rtd-theme ; extra == 'dev'
 Requires-Dist: toml-sort ; extra == 'dev'
 Requires-Dist: twine ; extra == 'dev'
 Requires-Dist: virtualenv ; extra == 'dev'
+Requires-Dist: vulture ; extra == 'dev'
 Requires-Dist: wheel ; extra == 'dev'
 Provides-Extra: test
 Requires-Dist: pytest ; extra == 'test'

+ 2 - 2
contrib/python/psutil/py3/psutil/__init__.py

@@ -214,7 +214,7 @@ if hasattr(_psplatform.Process, "rlimit"):
 AF_LINK = _psplatform.AF_LINK
 
 __author__ = "Giampaolo Rodola'"
-__version__ = "6.1.0"
+__version__ = "6.1.1"
 version_info = tuple([int(num) for num in __version__.split('.')])
 
 _timer = getattr(time, 'monotonic', time.time)
@@ -414,7 +414,7 @@ class Process(object):  # noqa: UP004
                 except AccessDenied:
                     pass
 
-            if self._exitcode not in (_SENTINEL, None):
+            if self._exitcode not in {_SENTINEL, None}:
                 info["exitcode"] = self._exitcode
             if self._create_time is not None:
                 info['started'] = _pprint_secs(self._create_time)

+ 4 - 4
contrib/python/psutil/py3/psutil/_common.py

@@ -547,7 +547,7 @@ def isfile_strict(path):
     try:
         st = os.stat(path)
     except OSError as err:
-        if err.errno in (errno.EPERM, errno.EACCES):
+        if err.errno in {errno.EPERM, errno.EACCES}:
             raise
         return False
     else:
@@ -562,7 +562,7 @@ def path_exists_strict(path):
     try:
         os.stat(path)
     except OSError as err:
-        if err.errno in (errno.EPERM, errno.EACCES):
+        if err.errno in {errno.EPERM, errno.EACCES}:
             raise
         return False
     else:
@@ -639,12 +639,12 @@ def socktype_to_enum(num):
 
 def conn_to_ntuple(fd, fam, type_, laddr, raddr, status, status_map, pid=None):
     """Convert a raw connection tuple to a proper ntuple."""
-    if fam in (socket.AF_INET, AF_INET6):
+    if fam in {socket.AF_INET, AF_INET6}:
         if laddr:
             laddr = addr(*laddr)
         if raddr:
             raddr = addr(*raddr)
-    if type_ == socket.SOCK_STREAM and fam in (AF_INET, AF_INET6):
+    if type_ == socket.SOCK_STREAM and fam in {AF_INET, AF_INET6}:
         status = status_map.get(status, CONN_NONE)
     else:
         status = CONN_NONE  # ignore whatever C returned to us

+ 2 - 2
contrib/python/psutil/py3/psutil/_compat.py

@@ -180,7 +180,7 @@ else:
 
     @_instance_checking_exception(EnvironmentError)
     def PermissionError(inst):
-        return getattr(inst, 'errno', _SENTINEL) in (errno.EACCES, errno.EPERM)
+        return getattr(inst, 'errno', _SENTINEL) in {errno.EACCES, errno.EPERM}
 
     @_instance_checking_exception(EnvironmentError)
     def InterruptedError(inst):
@@ -225,7 +225,7 @@ except ImportError:
         "CacheInfo", ["hits", "misses", "maxsize", "currsize"]
     )
 
-    class _HashedSeq(list):
+    class _HashedSeq(list):  # noqa: FURB189
         __slots__ = ('hashvalue',)
 
         def __init__(self, tup, hash=hash):

+ 1 - 1
contrib/python/psutil/py3/psutil/_psbsd.py

@@ -958,7 +958,7 @@ class Process:
                 # <<the call would leave a thread without a valid CPU to run
                 # on because the set does not overlap with the thread's
                 # anonymous mask>>
-                if err.errno in (errno.EINVAL, errno.EDEADLK):
+                if err.errno in {errno.EINVAL, errno.EDEADLK}:
                     for cpu in cpus:
                         if cpu not in allcpus:
                             raise ValueError(

+ 13 - 9
contrib/python/psutil/py3/psutil/_pslinux.py

@@ -709,11 +709,10 @@ def cpu_count_cores():
                 except KeyError:
                     pass
                 current_info = {}
-            else:
+            elif line.startswith((b'physical id', b'cpu cores')):
                 # ongoing section
-                if line.startswith((b'physical id', b'cpu cores')):
-                    key, value = line.split(b'\t:', 1)
-                    current_info[key] = int(value)
+                key, value = line.split(b'\t:', 1)
+                current_info[key] = int(value)
 
     result = sum(mapping.values())
     return result or None  # mimic os.cpu_count()
@@ -1043,7 +1042,7 @@ class NetConnections:
         ret = set()
         for proto_name, family, type_ in self.tmap[kind]:
             path = "%s/net/%s" % (self._procfs_path, proto_name)
-            if family in (socket.AF_INET, socket.AF_INET6):
+            if family in {socket.AF_INET, socket.AF_INET6}:
                 ls = self.process_inet(
                     path, family, type_, inodes, filter_pid=pid
                 )
@@ -1361,7 +1360,7 @@ def disk_partitions(all=False):
         device, mountpoint, fstype, opts = partition
         if device == 'none':
             device = ''
-        if device in ("/dev/root", "rootfs"):
+        if device in {"/dev/root", "rootfs"}:
             device = RootFsDeviceFinder().find() or device
         if not all:
             if not device or fstype not in fstypes:
@@ -1592,7 +1591,7 @@ def sensors_battery():
         status = cat(root + "/status", fallback="").strip().lower()
         if status == "discharging":
             power_plugged = False
-        elif status in ("charging", "full"):
+        elif status in {"charging", "full"}:
             power_plugged = True
 
     # Seconds left.
@@ -1725,7 +1724,12 @@ def wrap_exceptions(fun):
             raise NoSuchProcess(self.pid, self._name)
         except FileNotFoundError:
             self._raise_if_zombie()
-            if not os.path.exists("%s/%s" % (self._procfs_path, self.pid)):
+            # /proc/PID directory may still exist, but the files within
+            # it may not, indicating the process is gone, see:
+            # https://github.com/giampaolo/psutil/issues/2418
+            if not os.path.exists(
+                "%s/%s/stat" % (self._procfs_path, self.pid)
+            ):
                 raise NoSuchProcess(self.pid, self._name)
             raise
 
@@ -2254,7 +2258,7 @@ class Process:
         def ionice_set(self, ioclass, value):
             if value is None:
                 value = 0
-            if value and ioclass in (IOPRIO_CLASS_IDLE, IOPRIO_CLASS_NONE):
+            if value and ioclass in {IOPRIO_CLASS_IDLE, IOPRIO_CLASS_NONE}:
                 raise ValueError("%r ioclass accepts no value" % ioclass)
             if value < 0 or value > 7:
                 msg = "value not in 0-7 range"

+ 3 - 3
contrib/python/psutil/py3/psutil/_pssunos.py

@@ -283,7 +283,7 @@ def net_connections(kind, _pid=-1):
         if type_ not in types:
             continue
         # TODO: refactor and use _common.conn_to_ntuple.
-        if fam in (AF_INET, AF_INET6):
+        if fam in {AF_INET, AF_INET6}:
             if laddr:
                 laddr = _common.addr(*laddr)
             if raddr:
@@ -476,7 +476,7 @@ class Process:
 
     @wrap_exceptions
     def nice_set(self, value):
-        if self.pid in (2, 3):
+        if self.pid in {2, 3}:
             # Special case PIDs: internally setpriority(3) return ESRCH
             # (no such process), no matter what.
             # The process actually exists though, as it has a name,
@@ -678,7 +678,7 @@ class Process:
             os.stat('%s/%s' % (self._procfs_path, self.pid))
 
         # UNIX sockets
-        if kind in ('all', 'unix'):
+        if kind in {'all', 'unix'}:
             ret.extend([
                 _common.pconn(*conn)
                 for conn in self._get_unix_sockets(self.pid)

+ 15 - 16
contrib/python/psutil/py3/psutil/_pswindows.py

@@ -218,11 +218,10 @@ def py2_strencode(s):
     """
     if PY3:
         return s
+    if isinstance(s, str):
+        return s
     else:
-        if isinstance(s, str):
-            return s
-        else:
-            return s.encode(ENCODING, ENCODING_ERRS)
+        return s.encode(ENCODING, ENCODING_ERRS)
 
 
 @memoize
@@ -575,10 +574,10 @@ class WindowsService:  # noqa: PLW1641
                     % self._name
                 )
                 raise AccessDenied(pid=None, name=self._name, msg=msg)
-            elif err.winerror in (
+            elif err.winerror in {
                 cext.ERROR_INVALID_NAME,
                 cext.ERROR_SERVICE_DOES_NOT_EXIST,
-            ):
+            }:
                 msg = "service %r does not exist" % self._name
                 raise NoSuchProcess(pid=None, name=self._name, msg=msg)
             else:
@@ -697,15 +696,15 @@ ppid_map = cext.ppid_map  # used internally by Process.children()
 def is_permission_err(exc):
     """Return True if this is a permission error."""
     assert isinstance(exc, OSError), exc
-    if exc.errno in (errno.EPERM, errno.EACCES):
+    if exc.errno in {errno.EPERM, errno.EACCES}:
         return True
     # On Python 2 OSError doesn't always have 'winerror'. Sometimes
     # it does, in which case the original exception was WindowsError
     # (which is a subclass of OSError).
-    return getattr(exc, "winerror", -1) in (
+    return getattr(exc, "winerror", -1) in {
         cext.ERROR_ACCESS_DENIED,
         cext.ERROR_PRIVILEGE_NOT_HELD,
-    )
+    }
 
 
 def convert_oserror(exc, pid=None, name=None):
@@ -919,10 +918,10 @@ class Process:
         if sig == signal.SIGTERM:
             cext.proc_kill(self.pid)
         # py >= 2.7
-        elif sig in (
+        elif sig in {
             getattr(signal, "CTRL_C_EVENT", object()),
             getattr(signal, "CTRL_BREAK_EVENT", object()),
-        ):
+        }:
             os.kill(self.pid, sig)
         else:
             msg = (
@@ -976,7 +975,7 @@ class Process:
 
     @wrap_exceptions
     def username(self):
-        if self.pid in (0, 4):
+        if self.pid in {0, 4}:
             return 'NT AUTHORITY\\SYSTEM'
         domain, user = cext.proc_username(self.pid)
         return py2_strencode(domain) + '\\' + py2_strencode(user)
@@ -1034,7 +1033,7 @@ class Process:
     @wrap_exceptions
     @retry_error_partial_copy
     def cwd(self):
-        if self.pid in (0, 4):
+        if self.pid in {0, 4}:
             raise AccessDenied(self.pid, self._name)
         # return a normalized pathname since the native C function appends
         # "\\" at the and of the path
@@ -1043,7 +1042,7 @@ class Process:
 
     @wrap_exceptions
     def open_files(self):
-        if self.pid in (0, 4):
+        if self.pid in {0, 4}:
             return []
         ret = set()
         # Filenames come in in native format like:
@@ -1087,12 +1086,12 @@ class Process:
         if value:
             msg = "value argument not accepted on Windows"
             raise TypeError(msg)
-        if ioclass not in (
+        if ioclass not in {
             IOPRIO_VERYLOW,
             IOPRIO_LOW,
             IOPRIO_NORMAL,
             IOPRIO_HIGH,
-        ):
+        }:
             raise ValueError("%s is not a valid priority" % ioclass)
         cext.proc_io_priority_set(self.pid, ioclass)
 

+ 1 - 1
contrib/python/psutil/py3/psutil/arch/linux/users.c

@@ -33,7 +33,7 @@ psutil_users(PyObject *self, PyObject *args) {
         py_tty = PyUnicode_DecodeFSDefault(ut->ut_line);
         if (! py_tty)
             goto error;
-        if (strcmp(ut->ut_host, ":0") || strcmp(ut->ut_host, ":0.0"))
+        if (strcmp(ut->ut_host, ":0") == 0 || strcmp(ut->ut_host, ":0.0") == 0)
             py_hostname = PyUnicode_DecodeFSDefault("localhost");
         else
             py_hostname = PyUnicode_DecodeFSDefault(ut->ut_host);

+ 2 - 2
contrib/python/psutil/py3/ya.make

@@ -2,7 +2,7 @@
 
 PY3_LIBRARY()
 
-VERSION(6.1.0)
+VERSION(6.1.1)
 
 LICENSE(BSD-3-Clause)
 
@@ -27,7 +27,7 @@ NO_CHECK_IMPORTS(
 NO_UTIL()
 
 CFLAGS(
-    -DPSUTIL_VERSION=610
+    -DPSUTIL_VERSION=611
 )
 
 SRCS(