Skip to content

Commit

Permalink
remove maxfile and maxpath from disk_partitions()
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Apr 17, 2024
1 parent 7556e5d commit a7fec1b
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 56 deletions.
14 changes: 14 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

**Enhancements**

- 2109_: ``maxfile`` and ``maxpath`` fields were removed from the namedtuple
returned by `disk_partitions()`_. Reason: on network filesystems (NFS) this
can potentially take a very long time to complete.
- 2366_, [Windows]: log debug message when using slower process APIs.
- 2375_, [macOS]: provide arm64 wheels. (patch by Matthieu Darbois)
- 2396_: `process_iter()`_ no longer pre-emptively checks whether PIDs have
Expand All @@ -24,6 +27,17 @@
- 2362_, [macOS]: can't compile on macOS 10.11. (patch by Ryan Schmidt)
- 2365_, [macOS]: can't compile on macOS < 10.9. (patch by Ryan Schmidt)

**Porting notes**

Version 6.0.0 introduces some changes which affect backward compatibility:

- 2109_: the namedtuple returned by `disk_partitions()`_' no longer has
``maxfile`` and ``maxpath`` fields.
- 2396_: `process_iter()`_ no longer pre-emptively checks whether PIDs have
been reused. If you want to check for PID reusage you are supposed to use
`Process.is_running()`_ against the yielded `Process`_ instances. That will
also automatically remove reused PIDs from `process_iter()`_ internal cache.

5.9.8
=====

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ Disks
.. code-block:: python
>>> psutil.disk_partitions()
[sdiskpart(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid', maxfile=255, maxpath=4096),
sdiskpart(device='/dev/sda2', mountpoint='/home', fstype='ext', opts='rw', maxfile=255, maxpath=4096)]
[sdiskpart(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid'),
sdiskpart(device='/dev/sda2', mountpoint='/home', fstype='ext', opts='rw')]
>>>
>>> psutil.disk_usage('/')
sdiskusage(total=21378641920, used=4809781248, free=15482871808, percent=22.5)
Expand Down
9 changes: 4 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,16 @@ Disks
on Windows).
* **opts**: a comma-separated string indicating different mount options for
the drive/partition. Platform-dependent.
* **maxfile**: the maximum length a file name can have.
* **maxpath**: the maximum length a path name (directory name + base file
name) can have.

>>> import psutil
>>> psutil.disk_partitions()
[sdiskpart(device='/dev/sda3', mountpoint='/', fstype='ext4', opts='rw,errors=remount-ro', maxfile=255, maxpath=4096),
sdiskpart(device='/dev/sda7', mountpoint='/home', fstype='ext4', opts='rw', maxfile=255, maxpath=4096)]
[sdiskpart(device='/dev/sda3', mountpoint='/', fstype='ext4', opts='rw,errors=remount-ro'),
sdiskpart(device='/dev/sda7', mountpoint='/home', fstype='ext4', opts='rw')]

.. versionchanged:: 5.7.4 added *maxfile* and *maxpath* fields

.. versionchanged:: 6.0.0 removed *maxfile* and *maxpath* fields

.. function:: disk_usage(path)

Return disk usage statistics about the partition which contains the given
Expand Down
20 changes: 1 addition & 19 deletions psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2040,25 +2040,7 @@ def disk_partitions(all=False):
If *all* parameter is False return physical devices only and ignore
all others.
"""

def pathconf(path, name):
try:
return os.pathconf(path, name)
except (OSError, AttributeError):
pass

ret = _psplatform.disk_partitions(all)
if POSIX:
new = []
for item in ret:
nt = item._replace(
maxfile=pathconf(item.mountpoint, 'PC_NAME_MAX'),
maxpath=pathconf(item.mountpoint, 'PC_PATH_MAX'),
)
new.append(nt)
return new
else:
return ret
return _psplatform.disk_partitions(all)


def disk_io_counters(perdisk=False, nowrap=True):
Expand Down
3 changes: 1 addition & 2 deletions psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ class BatteryTime(enum.IntEnum):
'read_bytes', 'write_bytes',
'read_time', 'write_time'])
# psutil.disk_partitions()
sdiskpart = namedtuple('sdiskpart', ['device', 'mountpoint', 'fstype', 'opts',
'maxfile', 'maxpath'])
sdiskpart = namedtuple('sdiskpart', ['device', 'mountpoint', 'fstype', 'opts'])
# psutil.net_io_counters()
snetio = namedtuple('snetio', ['bytes_sent', 'bytes_recv',
'packets_sent', 'packets_recv',
Expand Down
5 changes: 1 addition & 4 deletions psutil/_psaix.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,7 @@ def disk_partitions(all=False):
# filter by filesystem having a total size > 0.
if not disk_usage(mountpoint).total:
continue
maxfile = maxpath = None # set later
ntuple = _common.sdiskpart(
device, mountpoint, fstype, opts, maxfile, maxpath
)
ntuple = _common.sdiskpart(device, mountpoint, fstype, opts)
retlist.append(ntuple)
return retlist

Expand Down
5 changes: 1 addition & 4 deletions psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,7 @@ def disk_partitions(all=False):
partitions = cext.disk_partitions()
for partition in partitions:
device, mountpoint, fstype, opts = partition
maxfile = maxpath = None # set later
ntuple = _common.sdiskpart(
device, mountpoint, fstype, opts, maxfile, maxpath
)
ntuple = _common.sdiskpart(device, mountpoint, fstype, opts)
retlist.append(ntuple)
return retlist

Expand Down
5 changes: 1 addition & 4 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,10 +1363,7 @@ def disk_partitions(all=False):
if not all:
if not device or fstype not in fstypes:
continue
maxfile = maxpath = None # set later
ntuple = _common.sdiskpart(
device, mountpoint, fstype, opts, maxfile, maxpath
)
ntuple = _common.sdiskpart(device, mountpoint, fstype, opts)
retlist.append(ntuple)

return retlist
Expand Down
5 changes: 1 addition & 4 deletions psutil/_psosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,7 @@ def disk_partitions(all=False):
if not all:
if not os.path.isabs(device) or not os.path.exists(device):
continue
maxfile = maxpath = None # set later
ntuple = _common.sdiskpart(
device, mountpoint, fstype, opts, maxfile, maxpath
)
ntuple = _common.sdiskpart(device, mountpoint, fstype, opts)
retlist.append(ntuple)
return retlist

Expand Down
5 changes: 1 addition & 4 deletions psutil/_pssunos.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,7 @@ def disk_partitions(all=False):
# https://github.com/giampaolo/psutil/issues/1674
debug("skipping %r: %s" % (mountpoint, err))
continue
maxfile = maxpath = None # set later
ntuple = _common.sdiskpart(
device, mountpoint, fstype, opts, maxfile, maxpath
)
ntuple = _common.sdiskpart(device, mountpoint, fstype, opts)
retlist.append(ntuple)
return retlist

Expand Down
2 changes: 0 additions & 2 deletions psutil/tests/test_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ def test_disk_partitions(self):
self.assertIsInstance(disk.mountpoint, str)
self.assertIsInstance(disk.fstype, str)
self.assertIsInstance(disk.opts, str)
self.assertIsInstance(disk.maxfile, (int, type(None)))
self.assertIsInstance(disk.maxpath, (int, type(None)))

@unittest.skipIf(SKIP_SYSCONS, "requires root")
def test_net_connections(self):
Expand Down
6 changes: 0 additions & 6 deletions psutil/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,12 +667,6 @@ def check_ntuple(nt):
self.assertIsInstance(nt.mountpoint, str)
self.assertIsInstance(nt.fstype, str)
self.assertIsInstance(nt.opts, str)
self.assertIsInstance(nt.maxfile, (int, type(None)))
self.assertIsInstance(nt.maxpath, (int, type(None)))
if nt.maxfile is not None and not GITHUB_ACTIONS:
self.assertGreater(nt.maxfile, 0)
if nt.maxpath is not None:
self.assertGreater(nt.maxpath, 0)

# all = False
ls = psutil.disk_partitions(all=False)
Expand Down

0 comments on commit a7fec1b

Please sign in to comment.