Skip to content

Commit

Permalink
merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Dec 19, 2024
2 parents 0b7bfb8 + 1a63407 commit b438d68
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 54 deletions.
6 changes: 3 additions & 3 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
*Bug tracker at https://github.com/giampaolo/psutil/issues*

6.1.1 (IN DEVELOPMENT)
======================
6.1.1
=====

XXXX-XX-XX
2024-12-19

**Enhancements**

Expand Down
4 changes: 4 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,10 @@ PyPy3.
Timeline
========

- 2024-12-19:
`6.1.1 <https://pypi.org/project/psutil/6.1.1/#files>`__ -
`what's new <https://github.com/giampaolo/psutil/blob/master/HISTORY.rst#611>`__ -
`diff <https://github.com/giampaolo/psutil/compare/release-6.1.0...release-6.1.1#files_bucket>`__
- 2024-10-17:
`6.1.0 <https://pypi.org/project/psutil/6.1.0/#files>`__ -
`what's new <https://github.com/giampaolo/psutil/blob/master/HISTORY.rst#610>`__ -
Expand Down
2 changes: 1 addition & 1 deletion psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def __str__(self):
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)
Expand Down
4 changes: 2 additions & 2 deletions psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,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
Expand Down
2 changes: 1 addition & 1 deletion psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ def cpu_affinity_set(self, cpus):
# <<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(
Expand Down
6 changes: 3 additions & 3 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ def retrieve(self, kind, pid=None):
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
)
Expand Down Expand Up @@ -1290,7 +1290,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:
Expand Down Expand Up @@ -1521,7 +1521,7 @@ def multi_bcat(*paths):
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.
Expand Down
6 changes: 3 additions & 3 deletions psutil/_pssunos.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,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:
Expand Down Expand Up @@ -472,7 +472,7 @@ def nice_get(self):

@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,
Expand Down Expand Up @@ -673,7 +673,7 @@ def net_connections(self, kind='inet'):
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)
Expand Down
10 changes: 5 additions & 5 deletions psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,10 @@ def _wrap_exceptions(self):
% 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:
Expand Down Expand Up @@ -916,7 +916,7 @@ def wait(self, timeout=None):

@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 f"{domain}\\{user}"
Expand Down Expand Up @@ -974,7 +974,7 @@ def resume(self):
@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
Expand All @@ -983,7 +983,7 @@ def cwd(self):

@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:
Expand Down
18 changes: 9 additions & 9 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def macos_version():
UNICODE_SUFFIX = "-ƒőő"
# An invalid unicode string.
INVALID_UNICODE_SUFFIX = b"f\xc0\x80".decode('utf8', 'surrogateescape')
ASCII_FS = sys.getfilesystemencoding().lower() in ('ascii', 'us-ascii')
ASCII_FS = sys.getfilesystemencoding().lower() in {"ascii", "us-ascii"}

# --- paths

Expand Down Expand Up @@ -1682,11 +1682,11 @@ def get_free_port(host='127.0.0.1'):

def bind_socket(family=AF_INET, type=SOCK_STREAM, addr=None):
"""Binds a generic socket."""
if addr is None and family in (AF_INET, AF_INET6):
if addr is None and family in {AF_INET, AF_INET6}:
addr = ("", 0)
sock = socket.socket(family, type)
try:
if os.name not in ('nt', 'cygwin'):
if os.name not in {'nt', 'cygwin'}:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(addr)
if type == socket.SOCK_STREAM:
Expand Down Expand Up @@ -1810,7 +1810,7 @@ def check_connection_ntuple(conn):

def check_ntuple(conn):
has_pid = len(conn) == 7
assert len(conn) in (6, 7), len(conn)
assert len(conn) in {6, 7}, len(conn)
assert conn[0] == conn.fd, conn.fd
assert conn[1] == conn.family, conn.family
assert conn[2] == conn.type, conn.type
Expand All @@ -1821,7 +1821,7 @@ def check_ntuple(conn):
assert conn[6] == conn.pid, conn.pid

def check_family(conn):
assert conn.family in (AF_INET, AF_INET6, AF_UNIX), conn.family
assert conn.family in {AF_INET, AF_INET6, AF_UNIX}, conn.family
assert isinstance(conn.family, enum.IntEnum), conn
if conn.family == AF_INET:
# actually try to bind the local socket; ignore IPv6
Expand All @@ -1840,19 +1840,19 @@ def check_family(conn):
def check_type(conn):
# SOCK_SEQPACKET may happen in case of AF_UNIX socks
SOCK_SEQPACKET = getattr(socket, "SOCK_SEQPACKET", object())
assert conn.type in (
assert conn.type in {
socket.SOCK_STREAM,
socket.SOCK_DGRAM,
SOCK_SEQPACKET,
), conn.type
}, conn.type
assert isinstance(conn.type, enum.IntEnum), conn
if conn.type == socket.SOCK_DGRAM:
assert conn.status == psutil.CONN_NONE, conn.status

def check_addrs(conn):
# check IP address and port sanity
for addr in (conn.laddr, conn.raddr):
if conn.family in (AF_INET, AF_INET6):
if conn.family in {AF_INET, AF_INET6}:
assert isinstance(addr, tuple), type(addr)
if not addr:
continue
Expand All @@ -1868,7 +1868,7 @@ def check_status(conn):
getattr(psutil, x) for x in dir(psutil) if x.startswith('CONN_')
]
assert conn.status in valids, conn.status
if conn.family in (AF_INET, AF_INET6) and conn.type == SOCK_STREAM:
if conn.family in {AF_INET, AF_INET6} and conn.type == SOCK_STREAM:
assert conn.status != psutil.CONN_NONE, conn.status
else:
assert conn.status == psutil.CONN_NONE, conn.status
Expand Down
14 changes: 7 additions & 7 deletions psutil/tests/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

def this_proc_net_connections(kind):
cons = psutil.Process().net_connections(kind=kind)
if kind in ("all", "unix"):
if kind in {"all", "unix"}:
return filter_proc_net_connections(cons)
return cons

Expand Down Expand Up @@ -429,7 +429,7 @@ def test_count(self):
cons = this_proc_net_connections(kind='tcp')
assert len(cons) == (2 if supports_ipv6() else 1)
for conn in cons:
assert conn.family in (AF_INET, AF_INET6)
assert conn.family in {AF_INET, AF_INET6}
assert conn.type == SOCK_STREAM
# tcp4
cons = this_proc_net_connections(kind='tcp4')
Expand All @@ -446,7 +446,7 @@ def test_count(self):
cons = this_proc_net_connections(kind='udp')
assert len(cons) == (2 if supports_ipv6() else 1)
for conn in cons:
assert conn.family in (AF_INET, AF_INET6)
assert conn.family in {AF_INET, AF_INET6}
assert conn.type == SOCK_DGRAM
# udp4
cons = this_proc_net_connections(kind='udp4')
Expand All @@ -463,23 +463,23 @@ def test_count(self):
cons = this_proc_net_connections(kind='inet')
assert len(cons) == (4 if supports_ipv6() else 2)
for conn in cons:
assert conn.family in (AF_INET, AF_INET6)
assert conn.type in (SOCK_STREAM, SOCK_DGRAM)
assert conn.family in {AF_INET, AF_INET6}
assert conn.type in {SOCK_STREAM, SOCK_DGRAM}
# inet6
if supports_ipv6():
cons = this_proc_net_connections(kind='inet6')
assert len(cons) == 2
for conn in cons:
assert conn.family == AF_INET6
assert conn.type in (SOCK_STREAM, SOCK_DGRAM)
assert conn.type in {SOCK_STREAM, SOCK_DGRAM}
# Skipped on BSD becayse by default the Python process
# creates a UNIX socket to '/var/run/log'.
if HAS_NET_CONNECTIONS_UNIX and not (FREEBSD or NETBSD):
cons = this_proc_net_connections(kind='unix')
assert len(cons) == 3
for conn in cons:
assert conn.family == AF_UNIX
assert conn.type in (SOCK_STREAM, SOCK_DGRAM)
assert conn.type in {SOCK_STREAM, SOCK_DGRAM}


@pytest.mark.skipif(SKIP_SYSCONS, reason="requires root")
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ def test_users(self):
# Make sure the C extension converts ':0' and ':0.0' to
# 'localhost'.
for user in psutil.users():
assert user.host not in (":0", ":0.0")
assert user.host not in {":0", ":0.0"}

def test_procfs_path(self):
tdir = self.get_testfn()
Expand Down
4 changes: 2 additions & 2 deletions psutil/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ class TestMisc(PsutilTestCase):
def test__all__(self):
dir_psutil = dir(psutil)
for name in dir_psutil:
if name in (
if name in {
'debug',
'tests',
'test',
'PermissionError',
'ProcessLookupError',
):
}:
continue
if not name.startswith('_'):
try:
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def test_create_time(self):
round_time_psutil_tstamp = datetime.datetime.fromtimestamp(
round_time_psutil
).strftime("%H:%M:%S")
assert time_ps in [time_psutil_tstamp, round_time_psutil_tstamp]
assert time_ps in {time_psutil_tstamp, round_time_psutil_tstamp}

def test_exe(self):
ps_pathname = ps_name(self.pid)
Expand Down
12 changes: 6 additions & 6 deletions psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def test_memory_maps(self):
value = getattr(nt, fname)
if fname == 'path':
continue
if fname in ('addr', 'perms'):
if fname in {'addr', 'perms'}:
assert value, value
else:
assert isinstance(value, int)
Expand Down Expand Up @@ -907,11 +907,11 @@ def cleanup(init):
# even if the function succeeds. For higher
# priorities, we match either the expected
# value or the highest so far.
if prio in (
if prio in {
psutil.ABOVE_NORMAL_PRIORITY_CLASS,
psutil.HIGH_PRIORITY_CLASS,
psutil.REALTIME_PRIORITY_CLASS,
):
}:
if new_prio == prio or highest_prio is None:
highest_prio = prio
assert new_prio == highest_prio
Expand Down Expand Up @@ -1370,12 +1370,12 @@ def assert_raises_nsp(fun, fun_name):
except psutil.NoSuchProcess:
pass
except psutil.AccessDenied:
if OPENBSD and fun_name in ('threads', 'num_threads'):
if OPENBSD and fun_name in {'threads', 'num_threads'}:
return
raise
else:
# NtQuerySystemInformation succeeds even if process is gone.
if WINDOWS and fun_name in ('exe', 'name'):
if WINDOWS and fun_name in {'exe', 'name'}:
return
raise self.fail(
"%r didn't raise NSP and returned %r instead" % (fun, ret)
Expand Down Expand Up @@ -1495,7 +1495,7 @@ def test_pid_0(self):
except psutil.AccessDenied:
pass
else:
if name in ("uids", "gids"):
if name in {"uids", "gids"}:
assert ret.real == 0
elif name == "username":
user = 'NT AUTHORITY\\SYSTEM' if WINDOWS else 'root'
Expand Down
4 changes: 2 additions & 2 deletions psutil/tests/test_process_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def memory_full_info(self, ret, info):
value = getattr(ret, name)
assert isinstance(value, int)
assert value >= 0
if LINUX or (OSX and name in ('vms', 'data')):
if LINUX or (OSX and name in {'vms', 'data'}):
# On Linux there are processes (e.g. 'goa-daemon') whose
# VMS is incredibly high for some reason.
continue
Expand All @@ -339,7 +339,7 @@ def open_files(self, ret, info):
assert isinstance(f.mode, str)
assert isinstance(f.flags, int)
assert f.position >= 0
assert f.mode in ('r', 'w', 'a', 'r+', 'a+')
assert f.mode in {'r', 'w', 'a', 'r+', 'a+'}
assert f.flags > 0
elif BSD and not f.path:
# XXX see: https://github.com/giampaolo/psutil/issues/595
Expand Down
Loading

0 comments on commit b438d68

Please sign in to comment.