Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #54 from giampaolo/master
Browse files Browse the repository at this point in the history
[pull] master from giampaolo:master
  • Loading branch information
ddelange authored Dec 1, 2023
2 parents e6e50c1 + 4407540 commit c3b3b41
Show file tree
Hide file tree
Showing 32 changed files with 686 additions and 565 deletions.
15 changes: 15 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
*Bug tracker at https://github.com/giampaolo/psutil/issues*

5.9.7 (IN DEVELOPMENT)
======================

XXXX-XX-XX

**Enhancements**

- 2324_: enforce Ruff rule `raw-string-in-exception`, which helps providing
clearer tracebacks when exceptions are raised by psutil.

**Bug fixes**

- 2325_, [PyPy]: psutil did not compile on PyPy due to missing
`PyErr_SetExcFromWindowsErrWithFilenameObject` cPython API.

5.9.6
=====

Expand Down
10 changes: 10 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ include psutil/arch/freebsd/sensors.c
include psutil/arch/freebsd/sensors.h
include psutil/arch/freebsd/sys_socks.c
include psutil/arch/freebsd/sys_socks.h
include psutil/arch/linux/disk.c
include psutil/arch/linux/disk.h
include psutil/arch/linux/mem.c
include psutil/arch/linux/mem.h
include psutil/arch/linux/net.c
include psutil/arch/linux/net.h
include psutil/arch/linux/proc.c
include psutil/arch/linux/proc.h
include psutil/arch/linux/users.c
include psutil/arch/linux/users.h
include psutil/arch/netbsd/cpu.c
include psutil/arch/netbsd/cpu.h
include psutil/arch/netbsd/disk.c
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ CPU
>>> import psutil
>>>
>>> psutil.cpu_times()
scputimes(user=3961.46, nice=169.729, system=2150.659, idle=16900.540, iowait=629.59, irq=0.0, softirq=19.42, steal=0.0, guest=0, nice=0.0)
scputimes(user=3961.46, nice=169.729, system=2150.659, idle=16900.540, iowait=629.59, irq=0.0, softirq=19.42, steal=0.0, guest=0, guest_nice=0.0)
>>>
>>> for x in range(3):
... psutil.cpu_percent(interval=1)
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def get_version():
assert num.isdigit(), ret
return ret
else:
raise ValueError("couldn't find version string")
msg = "couldn't find version string"
raise ValueError(msg)


VERSION = get_version()
Expand Down
31 changes: 16 additions & 15 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2630,21 +2630,22 @@ If you want to develop psutil take a look at the `DEVGUIDE.rst`_.
Platforms support history
=========================

* psutil 5.9.6 (XXXX-XX): drop Python 3.4 and 3.5 support
* psutil 5.9.1 (2022-05): drop Python 2.6 support
* psutil 5.9.0 (2021-12): **MidnightBSD**
* psutil 5.8.0 (2020-12): **PyPy 2** on Windows
* psutil 5.7.1 (2020-07): **Windows Nano**
* psutil 5.7.0 (2020-02): drop Windows XP & Server 2003 support
* psutil 5.7.0 (2020-02): **PyPy 3** on Windows
* psutil 5.4.0 (2017-11): **AIX**
* psutil 3.4.1 (2016-01): **NetBSD**
* psutil 3.3.0 (2015-11): **OpenBSD**
* psutil 1.0.0 (2013-07): **Solaris**
* psutil 0.1.1 (2009-03): **FreeBSD**
* psutil 0.1.0 (2009-01): **Linux, Windows, macOS**

Supported Python versions are 2.7, 3.6+ and PyPy3.
* psutil 5.9.6 (2023-10): drop Python 3.4 and 3.5
* psutil 5.9.1 (2022-05): drop Python 2.6
* psutil 5.9.0 (2021-12): add **MidnightBSD**
* psutil 5.8.0 (2020-12): add **PyPy 2** on Windows
* psutil 5.7.1 (2020-07): add **Windows Nano**
* psutil 5.7.0 (2020-02): drop Windows XP & Windows Server 2003
* psutil 5.7.0 (2020-02): add **PyPy 3** on Windows
* psutil 5.4.0 (2017-11): add **AIX**
* psutil 3.4.1 (2016-01): add **NetBSD**
* psutil 3.3.0 (2015-11): add **OpenBSD**
* psutil 1.0.0 (2013-07): add **Solaris**
* psutil 0.1.1 (2009-03): add **FreeBSD**
* psutil 0.1.0 (2009-01): add **Linux, Windows, macOS**

Supported Python versions at the time of writing are cPython 2.7, 3.6+ and
PyPy3.

Timeline
========
Expand Down
16 changes: 10 additions & 6 deletions psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,8 @@ def username(self):
if POSIX:
if pwd is None:
# might happen if python was installed from sources
raise ImportError(
"requires pwd module shipped with standard python")
msg = "requires pwd module shipped with standard python"
raise ImportError(msg)
real_uid = self.uids().real
try:
return pwd.getpwuid(real_uid).pw_name
Expand Down Expand Up @@ -803,7 +803,8 @@ def ionice(self, ioclass=None, value=None):
"""
if ioclass is None:
if value is not None:
raise ValueError("'ioclass' argument must be specified")
msg = "'ioclass' argument must be specified"
raise ValueError(msg)
return self._proc.ionice_get()
else:
self._raise_if_pid_reused()
Expand Down Expand Up @@ -1198,10 +1199,12 @@ def _send_signal(self, sig):
self._raise_if_pid_reused()
if self.pid == 0:
# see "man 2 kill"
raise ValueError(
msg = (
"preventing sending signal to process with PID 0 as it "
"would affect every process in the process group of the "
"calling process (os.getpid()) instead of PID 0")
"calling process (os.getpid()) instead of PID 0"
)
raise ValueError(msg)
try:
os.kill(self.pid, sig)
except ProcessLookupError:
Expand Down Expand Up @@ -1288,7 +1291,8 @@ def wait(self, timeout=None):
To wait for multiple Process(es) use psutil.wait_procs().
"""
if timeout is not None and not timeout >= 0:
raise ValueError("timeout must be a positive integer")
msg = "timeout must be a positive integer"
raise ValueError(msg)
if self._exitcode is not _SENTINEL:
return self._exitcode
self._exitcode = self._proc.wait(timeout)
Expand Down
15 changes: 9 additions & 6 deletions psutil/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,17 @@ def super(type_=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
# Get the function's first positional argument.
type_or_obj = f.f_locals[f.f_code.co_varnames[0]]
except (IndexError, KeyError):
raise RuntimeError('super() used in a function with no args')
msg = 'super() used in a function with no args'
raise RuntimeError(msg)
try:
# Get the MRO so we can crawl it.
mro = type_or_obj.__mro__
except (AttributeError, RuntimeError):
try:
mro = type_or_obj.__class__.__mro__
except AttributeError:
raise RuntimeError('super() used in a non-newstyle class')
msg = 'super() used in a non-newstyle class'
raise RuntimeError(msg)
for type_ in mro:
# Find the class that owns the currently-executing method.
for meth in type_.__dict__.values():
Expand All @@ -118,7 +120,8 @@ def super(type_=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
continue
break # found
else:
raise RuntimeError('super() called outside a method')
msg = 'super() called outside a method'
raise RuntimeError(msg)

# Dispatch to builtin super().
if type_or_obj is not _SENTINEL:
Expand Down Expand Up @@ -199,9 +202,9 @@ def FileExistsError(inst):
except FileExistsError:
pass
except OSError:
raise RuntimeError(
"broken or incompatible Python implementation, see: "
"https://github.com/giampaolo/psutil/issues/1659")
msg = ("broken or incompatible Python implementation, see: "
"https://github.com/giampaolo/psutil/issues/1659")
raise RuntimeError(msg)


# --- stdlib additions
Expand Down
3 changes: 2 additions & 1 deletion psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def per_cpu_times():
if cpu_count_logical() == 1:
return [cpu_times()]
if per_cpu_times.__called__:
raise NotImplementedError("supported only starting from FreeBSD 8")
msg = "supported only starting from FreeBSD 8"
raise NotImplementedError(msg)
per_cpu_times.__called__ = True
return [cpu_times()]

Expand Down
19 changes: 7 additions & 12 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,8 @@ def cpu_freq():
# https://github.com/giampaolo/psutil/issues/1071
curr = bcat(pjoin(path, "cpuinfo_cur_freq"), fallback=None)
if curr is None:
raise NotImplementedError(
"can't find current frequency file")
msg = "can't find current frequency file"
raise NotImplementedError(msg)
curr = int(curr) / 1000
max_ = int(bcat(pjoin(path, "scaling_max_freq"))) / 1000
min_ = int(bcat(pjoin(path, "scaling_min_freq"))) / 1000
Expand Down Expand Up @@ -1549,14 +1549,7 @@ def users():
retlist = []
rawlist = cext.users()
for item in rawlist:
user, tty, hostname, tstamp, user_process, pid = item
# note: the underlying C function includes entries about
# system boot, run level and others. We might want
# to use them in the future.
if not user_process:
continue
if hostname in (':0.0', ':0'):
hostname = 'localhost'
user, tty, hostname, tstamp, pid = item
nt = _common.suser(user, tty or None, hostname, tstamp, pid)
retlist.append(nt)
return retlist
Expand Down Expand Up @@ -2164,7 +2157,8 @@ def ionice_set(self, ioclass, value):
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:
raise ValueError("value not in 0-7 range")
msg = "value not in 0-7 range"
raise ValueError(msg)
return cext.proc_ioprio_set(self.pid, ioclass, value)

if prlimit is not None:
Expand All @@ -2175,7 +2169,8 @@ def rlimit(self, resource_, limits=None):
# we don't want that. We should never get here though as
# PID 0 is not supported on Linux.
if self.pid == 0:
raise ValueError("can't use prlimit() against PID 0 process")
msg = "can't use prlimit() against PID 0 process"
raise ValueError(msg)
try:
if limits is None:
# get
Expand Down
4 changes: 3 additions & 1 deletion psutil/_psposix.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def wait_pid(pid, timeout=None, proc_name=None,
timeout=0 is also possible (either return immediately or raise).
"""
if pid <= 0:
raise ValueError("can't wait for PID 0") # see "man waitpid"
# see "man waitpid"
msg = "can't wait for PID 0"
raise ValueError(msg)
interval = 0.0001
flags = 0
if timeout is not None:
Expand Down
3 changes: 2 additions & 1 deletion psutil/_pssunos.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def swap_memory():

lines = stdout.strip().split('\n')[1:]
if not lines:
raise RuntimeError('no swap device(s) configured')
msg = 'no swap device(s) configured'
raise RuntimeError(msg)
total = free = 0
for line in lines:
line = line.split()
Expand Down
12 changes: 12 additions & 0 deletions psutil/_psutil_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ PyErr_SetFromWindowsErrWithFilename(int winerr, const char *filename) {
#endif // !defined(PyErr_SetFromWindowsErrWithFilename)


#if !defined(PyErr_SetExcFromWindowsErrWithFilenameObject)
PyObject *
PyErr_SetExcFromWindowsErrWithFilenameObject(PyObject *type,
int ierr,
PyObject *filename) {
// Original function is too complex. Just raise OSError without
// filename.
return PyErr_SetFromWindowsErrWithFilename(ierr, NULL);
}
#endif // !defined(PyErr_SetExcFromWindowsErrWithFilenameObject)


// PyPy 2.7
#if !defined(PyErr_SetFromWindowsErr)
PyObject *
Expand Down
14 changes: 9 additions & 5 deletions psutil/_psutil_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ static const int PSUTIL_CONN_NONE = 128;
#define PyUnicode_DecodeFSDefaultAndSize PyString_FromStringAndSize
#endif

#if defined(PSUTIL_WINDOWS) && \
defined(PYPY_VERSION) && \
!defined(PyErr_SetFromWindowsErrWithFilename)
PyObject *PyErr_SetFromWindowsErrWithFilename(int ierr,
const char *filename);
#if defined(PSUTIL_WINDOWS) && defined(PYPY_VERSION)
#if !defined(PyErr_SetFromWindowsErrWithFilename)
PyObject *PyErr_SetFromWindowsErrWithFilename(int ierr,
const char *filename);
#endif
#if !defined(PyErr_SetExcFromWindowsErrWithFilenameObject)
PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject(
PyObject *type, int ierr, PyObject *filename);
#endif
#endif

// --- _Py_PARSE_PID
Expand Down
Loading

0 comments on commit c3b3b41

Please sign in to comment.