Skip to content

Commit 29a0887

Browse files
cmaloneymiss-islington
authored andcommitted
gh-101100: Document os.uname_result and os.statvfs_result with related constants (GH-151301)
(cherry picked from commit 9688d25) Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
1 parent 2e873f7 commit 29a0887

4 files changed

Lines changed: 204 additions & 54 deletions

File tree

Doc/library/os.rst

Lines changed: 201 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -791,36 +791,61 @@ process and user.
791791
single: gethostbyaddr() (in module socket)
792792

793793
Returns information identifying the current operating system.
794-
The return value is an object with five attributes:
795-
796-
* :attr:`sysname` - operating system name
797-
* :attr:`nodename` - name of machine on network (implementation-defined)
798-
* :attr:`release` - operating system release
799-
* :attr:`version` - operating system version
800-
* :attr:`machine` - hardware identifier
801-
802-
For backwards compatibility, this object is also iterable, behaving
803-
like a five-tuple containing :attr:`sysname`, :attr:`nodename`,
804-
:attr:`release`, :attr:`version`, and :attr:`machine`
805-
in that order.
806-
807-
Some systems truncate :attr:`nodename` to 8 characters or to the
808-
leading component; a better way to get the hostname is
809-
:func:`socket.gethostname` or even
810-
``socket.gethostbyaddr(socket.gethostname())``.
794+
The return value is a :class:`uname_result`.
811795

812796
On macOS, iOS and Android, this returns the *kernel* name and version (i.e.,
813797
``'Darwin'`` on macOS and iOS; ``'Linux'`` on Android). :func:`platform.uname`
814798
can be used to get the user-facing operating system name and version on iOS and
815799
Android.
816800

801+
.. seealso::
802+
:data:`sys.platform` which has finer granularity.
803+
804+
The :mod:`platform` module provides detailed checks for the
805+
system's identity.
806+
817807
.. availability:: Unix.
818808

819809
.. versionchanged:: 3.3
820810
Return type changed from a tuple to a tuple-like object
821811
with named attributes.
822812

823813

814+
.. class:: uname_result
815+
816+
Name and information about the system returned by :func:`os.uname`.
817+
These attributes correspond to the members described in :manpage:`uname(2)`.
818+
819+
For backwards compatibility, this object is also iterable, behaving
820+
like a five-tuple containing :attr:`~uname_result.sysname`,
821+
:attr:`~uname_result.nodename`, :attr:`~uname_result.release`,
822+
:attr:`~uname_result.version`, and :attr:`~uname_result.machine`
823+
in that order.
824+
825+
.. attribute:: sysname
826+
827+
Operating system name.
828+
829+
.. attribute:: nodename
830+
831+
Name of machine on network. Some systems truncate
832+
:attr:`~uname_result.nodename` to 8 characters or to the leading
833+
component; a better way to get the hostname is :func:`socket.gethostname`
834+
or even ``socket.gethostbyaddr(socket.gethostname())``.
835+
836+
.. attribute:: release
837+
838+
Operating system release.
839+
840+
.. attribute:: version
841+
842+
Operating system version.
843+
844+
.. attribute:: machine
845+
846+
Hardware identifier.
847+
848+
824849
.. function:: unsetenv(key, /)
825850

826851
.. index:: single: environment variables; deleting
@@ -1103,8 +1128,8 @@ as internal buffering of data.
11031128
.. function:: fstatvfs(fd, /)
11041129

11051130
Return information about the filesystem containing the file associated with
1106-
file descriptor *fd*, like :func:`statvfs`. As of Python 3.3, this is
1107-
equivalent to ``os.statvfs(fd)``.
1131+
file descriptor *fd* in a :class:`statvfs_result`, like :func:`statvfs`.
1132+
As of Python 3.3, this is equivalent to ``os.statvfs(fd)``.
11081133

11091134
.. availability:: Unix.
11101135

@@ -3374,48 +3399,174 @@ features:
33743399

33753400
.. function:: statvfs(path)
33763401

3377-
Perform a :c:func:`!statvfs` system call on the given path. The return value is
3378-
an object whose attributes describe the filesystem on the given path, and
3379-
correspond to the members of the :c:struct:`statvfs` structure, namely:
3380-
:attr:`f_bsize`, :attr:`f_frsize`, :attr:`f_blocks`, :attr:`f_bfree`,
3381-
:attr:`f_bavail`, :attr:`f_files`, :attr:`f_ffree`, :attr:`f_favail`,
3382-
:attr:`f_flag`, :attr:`f_namemax`, :attr:`f_fsid`.
3383-
3384-
Two module-level constants are defined for the :attr:`f_flag` attribute's
3385-
bit-flags: if :const:`ST_RDONLY` is set, the filesystem is mounted
3386-
read-only, and if :const:`ST_NOSUID` is set, the semantics of
3387-
setuid/setgid bits are disabled or not supported.
3388-
3389-
Additional module-level constants are defined for GNU/glibc based systems.
3390-
These are :const:`ST_NODEV` (disallow access to device special files),
3391-
:const:`ST_NOEXEC` (disallow program execution), :const:`ST_SYNCHRONOUS`
3392-
(writes are synced at once), :const:`ST_MANDLOCK` (allow mandatory locks on an FS),
3393-
:const:`ST_WRITE` (write on file/directory/symlink), :const:`ST_APPEND`
3394-
(append-only file), :const:`ST_IMMUTABLE` (immutable file), :const:`ST_NOATIME`
3395-
(do not update access times), :const:`ST_NODIRATIME` (do not update directory access
3396-
times), :const:`ST_RELATIME` (update atime relative to mtime/ctime).
3402+
Perform a :manpage:`statvfs(3)` system call on the given path. The return value
3403+
is a :class:`statvfs_result` whose attributes describe the filesystem
3404+
on the given path and correspond to the members of the :c:struct:`statvfs`
3405+
structure.
33973406

33983407
This function can support :ref:`specifying a file descriptor <path_fd>`.
33993408

34003409
.. availability:: Unix.
34013410

3402-
.. versionchanged:: 3.2
3403-
The :const:`ST_RDONLY` and :const:`ST_NOSUID` constants were added.
3404-
34053411
.. versionchanged:: 3.3
34063412
Added support for specifying *path* as an open file descriptor.
34073413

3408-
.. versionchanged:: 3.4
3409-
The :const:`ST_NODEV`, :const:`ST_NOEXEC`, :const:`ST_SYNCHRONOUS`,
3410-
:const:`ST_MANDLOCK`, :const:`ST_WRITE`, :const:`ST_APPEND`,
3411-
:const:`ST_IMMUTABLE`, :const:`ST_NOATIME`, :const:`ST_NODIRATIME`,
3412-
and :const:`ST_RELATIME` constants were added.
3413-
34143414
.. versionchanged:: 3.6
34153415
Accepts a :term:`path-like object`.
34163416

3417-
.. versionchanged:: 3.7
3418-
Added the :attr:`f_fsid` attribute.
3417+
3418+
.. class:: statvfs_result
3419+
3420+
Filesystem statistics returned by :func:`os.statvfs` and :func:`os.fstatvfs`.
3421+
See :manpage:`statvfs(3)` for more details.
3422+
3423+
.. attribute:: f_bsize
3424+
3425+
Block size.
3426+
3427+
.. attribute:: f_frsize
3428+
3429+
Fragment size.
3430+
3431+
.. attribute:: f_blocks
3432+
3433+
Number of :attr:`~statvfs_result.f_frsize` sized blocks the filesystem
3434+
can contain.
3435+
3436+
.. attribute:: f_bfree
3437+
3438+
Number of free blocks.
3439+
3440+
.. attribute:: f_bavail
3441+
3442+
Number of free blocks for unprivileged users.
3443+
3444+
.. attribute:: f_files
3445+
3446+
Number of file entries, inodes, the filesystem can contain.
3447+
3448+
.. attribute:: f_ffree
3449+
3450+
Number of free files entries.
3451+
3452+
.. attribute:: f_favail
3453+
3454+
Number of free file entries for unprivileged users.
3455+
3456+
.. attribute:: f_flag
3457+
3458+
Bit-mask of mount flags. The following flags are defined:
3459+
:data:`ST_RDONLY`, :data:`ST_NOSUID`, :data:`ST_NODEV`,
3460+
:data:`ST_NOEXEC`, :data:`ST_SYNCHRONOUS`, :data:`ST_MANDLOCK`,
3461+
:data:`ST_WRITE`, :data:`ST_APPEND`, :data:`ST_IMMUTABLE`,
3462+
:data:`ST_NOATIME`, :data:`ST_NODIRATIME`, and :data:`ST_RELATIME`.
3463+
3464+
.. attribute:: f_namemax
3465+
3466+
Filesystem max filename length. OS specific limitations such as
3467+
:ref:`Windows MAX_PATH <max-path>` and those described in Linux
3468+
:manpage:`pathname(7)` may exist.
3469+
3470+
.. attribute:: f_fsid
3471+
3472+
Filesystem ID.
3473+
3474+
.. versionadded:: 3.7
3475+
3476+
3477+
The following flags are used in :attr:`statvfs_result.f_flag`.
3478+
3479+
.. data:: ST_RDONLY
3480+
3481+
Read-only filesystem.
3482+
3483+
.. versionadded:: 3.2
3484+
3485+
.. data:: ST_NOSUID
3486+
3487+
Setuid/setgid bits are disabled or not supported.
3488+
3489+
.. versionadded:: 3.2
3490+
3491+
.. data:: ST_NODEV
3492+
3493+
Disallow access to device special files.
3494+
3495+
.. availability:: Linux.
3496+
3497+
.. versionadded:: 3.4
3498+
3499+
.. data:: ST_NOEXEC
3500+
3501+
Disallow program execution.
3502+
3503+
.. availability:: Linux.
3504+
3505+
.. versionadded:: 3.4
3506+
3507+
.. data:: ST_SYNCHRONOUS
3508+
3509+
Writes are synced at once.
3510+
3511+
.. availability:: Linux.
3512+
3513+
.. versionadded:: 3.4
3514+
3515+
.. data:: ST_MANDLOCK
3516+
3517+
Allow mandatory locks on an FS.
3518+
3519+
.. availability:: Linux.
3520+
3521+
.. versionadded:: 3.4
3522+
3523+
.. data:: ST_WRITE
3524+
3525+
Write on file/directory/symlink.
3526+
3527+
.. availability:: Linux.
3528+
3529+
.. versionadded:: 3.4
3530+
3531+
.. data:: ST_APPEND
3532+
3533+
Append-only file.
3534+
3535+
.. availability:: Linux.
3536+
3537+
.. versionadded:: 3.4
3538+
3539+
.. data:: ST_IMMUTABLE
3540+
3541+
Immutable file.
3542+
3543+
.. availability:: Linux.
3544+
3545+
.. versionadded:: 3.4
3546+
3547+
.. data:: ST_NOATIME
3548+
3549+
Do not update access times.
3550+
3551+
.. availability:: Linux.
3552+
3553+
.. versionadded:: 3.4
3554+
3555+
.. data:: ST_NODIRATIME
3556+
3557+
Do not update directory access times.
3558+
3559+
.. availability:: Linux.
3560+
3561+
.. versionadded:: 3.4
3562+
3563+
.. data:: ST_RELATIME
3564+
3565+
Update atime relative to mtime/ctime.
3566+
3567+
.. availability:: Linux.
3568+
3569+
.. versionadded:: 3.4
34193570

34203571

34213572
.. data:: supports_dir_fd

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Doc/library/lzma.rst
2121
Doc/library/mmap.rst
2222
Doc/library/multiprocessing.rst
2323
Doc/library/optparse.rst
24-
Doc/library/os.rst
2524
Doc/library/pickletools.rst
2625
Doc/library/profile.rst
2726
Doc/library/pyexpat.rst

Misc/NEWS.d/3.10.0a4.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ Harmonized :func:`random.randrange` argument handling to match :func:`range`.
622622
.. nonce: O4VcCY
623623
.. section: Library
624624
625-
Restore compatibility for ``uname_result`` around deepcopy and _replace.
625+
Restore compatibility for :class:`os.uname_result` around deepcopy and _replace.
626626

627627
..
628628

Misc/NEWS.d/3.12.0a3.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ event loop but the current event loop was set.
454454
.. nonce: humlhz
455455
.. section: Library
456456
457-
On ``uname_result``, restored expectation that ``_fields`` and ``_asdict``
458-
would include all six properties including ``processor``.
457+
On :class:`os.uname_result`, restored expectation that ``_fields`` and
458+
``_asdict`` would include all six properties including ``processor``.
459459

460460
..
461461

0 commit comments

Comments
 (0)