Skip to content

Commit f4d7102

Browse files
committed
gh-101100: Fix os.statvfs and os.uname references
Restructure descriptive paragraphs to class definitions copying across descriptions. Add constants from statvfs to os as data directives. Expand the `os.uname` section slightly with a see also which matches the one at the beginning of os.rst added in gh-56535 (commit a83cdaa). --- The statvfs_result members had no definition before and I opted not to add ones ere. The C code in `posixmodule.c` just forwards them directly so I don't think a description would be more precise than what is in the man page.
1 parent 871047d commit f4d7102

2 files changed

Lines changed: 164 additions & 44 deletions

File tree

Doc/library/os.rst

Lines changed: 164 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -800,20 +800,16 @@ process and user.
800800
single: gethostbyaddr() (in module socket)
801801

802802
Returns information identifying the current operating system.
803-
The return value is an object with five attributes:
804-
805-
* :attr:`sysname` - operating system name
806-
* :attr:`nodename` - name of machine on network (implementation-defined)
807-
* :attr:`release` - operating system release
808-
* :attr:`version` - operating system version
809-
* :attr:`machine` - hardware identifier
803+
The return value is a :class:`uname_result` object whose attributes
804+
correspond to the members described in :manpage:`uname(2)`.
810805

811806
For backwards compatibility, this object is also iterable, behaving
812-
like a five-tuple containing :attr:`sysname`, :attr:`nodename`,
813-
:attr:`release`, :attr:`version`, and :attr:`machine`
807+
like a five-tuple containing :attr:`~uname_result.sysname`,
808+
:attr:`~uname_result.nodename`, :attr:`~uname_result.release`,
809+
:attr:`~uname_result.version`, and :attr:`~uname_result.machine`
814810
in that order.
815811

816-
Some systems truncate :attr:`nodename` to 8 characters or to the
812+
Some systems truncate :attr:`~uname_result.nodename` to 8 characters or to the
817813
leading component; a better way to get the hostname is
818814
:func:`socket.gethostname` or even
819815
``socket.gethostbyaddr(socket.gethostname())``.
@@ -823,13 +819,44 @@ process and user.
823819
can be used to get the user-facing operating system name and version on iOS and
824820
Android.
825821

822+
.. seealso::
823+
:data:`sys.platform` has a finer granularity.
824+
825+
The :mod:`platform` module provides detailed checks for the
826+
system's identity.
827+
826828
.. availability:: Unix.
827829

828830
.. versionchanged:: 3.3
829831
Return type changed from a tuple to a tuple-like object
830832
with named attributes.
831833

832834

835+
.. class:: uname_result
836+
837+
Name and information about the system returned by :func:`os.uname`.
838+
839+
.. attribute:: sysname
840+
841+
Operating system name.
842+
843+
.. attribute:: nodename
844+
845+
Name of machine on network (implementation-defined).
846+
847+
.. attribute:: release
848+
849+
Operating system release.
850+
851+
.. attribute:: version
852+
853+
Operating system version.
854+
855+
.. attribute:: machine
856+
857+
Hardware identifier.
858+
859+
833860
.. function:: unsetenv(key, /)
834861

835862
.. index:: single: environment variables; deleting
@@ -1112,8 +1139,8 @@ as internal buffering of data.
11121139
.. function:: fstatvfs(fd, /)
11131140

11141141
Return information about the filesystem containing the file associated with
1115-
file descriptor *fd*, like :func:`statvfs`. As of Python 3.3, this is
1116-
equivalent to ``os.statvfs(fd)``.
1142+
file descriptor *fd* in a :class:`statvfs_result` like :func:`statvfs`.
1143+
As of Python 3.3, this is equivalent to ``os.statvfs(fd)``.
11171144

11181145
.. availability:: Unix.
11191146

@@ -3784,48 +3811,142 @@ features:
37843811

37853812
.. function:: statvfs(path)
37863813

3787-
Perform a :c:func:`!statvfs` system call on the given path. The return value is
3788-
an object whose attributes describe the filesystem on the given path, and
3789-
correspond to the members of the :c:struct:`statvfs` structure, namely:
3790-
:attr:`f_bsize`, :attr:`f_frsize`, :attr:`f_blocks`, :attr:`f_bfree`,
3791-
:attr:`f_bavail`, :attr:`f_files`, :attr:`f_ffree`, :attr:`f_favail`,
3792-
:attr:`f_flag`, :attr:`f_namemax`, :attr:`f_fsid`.
3793-
3794-
Two module-level constants are defined for the :attr:`f_flag` attribute's
3795-
bit-flags: if :const:`ST_RDONLY` is set, the filesystem is mounted
3796-
read-only, and if :const:`ST_NOSUID` is set, the semantics of
3797-
setuid/setgid bits are disabled or not supported.
3798-
3799-
Additional module-level constants are defined for GNU/glibc based systems.
3800-
These are :const:`ST_NODEV` (disallow access to device special files),
3801-
:const:`ST_NOEXEC` (disallow program execution), :const:`ST_SYNCHRONOUS`
3802-
(writes are synced at once), :const:`ST_MANDLOCK` (allow mandatory locks on an FS),
3803-
:const:`ST_WRITE` (write on file/directory/symlink), :const:`ST_APPEND`
3804-
(append-only file), :const:`ST_IMMUTABLE` (immutable file), :const:`ST_NOATIME`
3805-
(do not update access times), :const:`ST_NODIRATIME` (do not update directory access
3806-
times), :const:`ST_RELATIME` (update atime relative to mtime/ctime).
3814+
Perform a :manpage:`statvfs(3)` system call on the given path. The return value
3815+
is a :class:`statvfs_result` whose attributes describe the filesystem
3816+
on the given path and correspond to the members of the :c:struct:`statvfs`
3817+
structure.
38073818

38083819
This function can support :ref:`specifying a file descriptor <path_fd>`.
38093820

38103821
.. availability:: Unix.
38113822

3812-
.. versionchanged:: 3.2
3813-
The :const:`ST_RDONLY` and :const:`ST_NOSUID` constants were added.
3814-
38153823
.. versionchanged:: 3.3
38163824
Added support for specifying *path* as an open file descriptor.
38173825

3818-
.. versionchanged:: 3.4
3819-
The :const:`ST_NODEV`, :const:`ST_NOEXEC`, :const:`ST_SYNCHRONOUS`,
3820-
:const:`ST_MANDLOCK`, :const:`ST_WRITE`, :const:`ST_APPEND`,
3821-
:const:`ST_IMMUTABLE`, :const:`ST_NOATIME`, :const:`ST_NODIRATIME`,
3822-
and :const:`ST_RELATIME` constants were added.
3823-
38243826
.. versionchanged:: 3.6
38253827
Accepts a :term:`path-like object`.
38263828

3827-
.. versionchanged:: 3.7
3828-
Added the :attr:`f_fsid` attribute.
3829+
3830+
.. class:: statvfs_result
3831+
3832+
Filesystem statistics returned by :func:`os.statvfs` and :func:`os.fstatvfs`.
3833+
See :manpage:`statvfs(3)` for the meaning of each member.
3834+
3835+
.. attribute:: f_bsize
3836+
.. attribute:: f_frsize
3837+
.. attribute:: f_blocks
3838+
.. attribute:: f_bfree
3839+
.. attribute:: f_bavail
3840+
.. attribute:: f_files
3841+
.. attribute:: f_ffree
3842+
.. attribute:: f_favail
3843+
3844+
.. attribute:: f_flag
3845+
3846+
Bit-mask of mount flags. The following flags are defined:
3847+
:data:`ST_RDONLY`, :data:`ST_NOSUID`, :data:`ST_NODEV`,
3848+
:data:`ST_NOEXEC`, :data:`ST_SYNCHRONOUS`, :data:`ST_MANDLOCK`,
3849+
:data:`ST_WRITE`, :data:`ST_APPEND`, :data:`ST_IMMUTABLE`,
3850+
:data:`ST_NOATIME`, :data:`ST_NODIRATIME`, and :data:`ST_RELATIME`.
3851+
3852+
.. attribute:: f_namemax
3853+
3854+
.. attribute:: f_fsid
3855+
3856+
.. versionadded:: 3.7
3857+
3858+
3859+
.. data:: ST_RDONLY
3860+
3861+
Read-only filesystem.
3862+
3863+
.. versionadded:: 3.2
3864+
3865+
.. data:: ST_NOSUID
3866+
3867+
Setuid/setgid bits are disabled or not supported.
3868+
3869+
.. versionadded:: 3.2
3870+
3871+
.. data:: ST_NODEV
3872+
3873+
Disallow access to device special files.
3874+
3875+
.. availability:: Linux.
3876+
3877+
.. versionadded:: 3.4
3878+
3879+
.. data:: ST_NOEXEC
3880+
3881+
Disallow program execution.
3882+
3883+
.. availability:: Linux.
3884+
3885+
.. versionadded:: 3.4
3886+
3887+
.. data:: ST_SYNCHRONOUS
3888+
3889+
Writes are synced at once.
3890+
3891+
.. availability:: Linux.
3892+
3893+
.. versionadded:: 3.4
3894+
3895+
.. data:: ST_MANDLOCK
3896+
3897+
Allow mandatory locks on an FS.
3898+
3899+
.. availability:: Linux.
3900+
3901+
.. versionadded:: 3.4
3902+
3903+
.. data:: ST_WRITE
3904+
3905+
Write on file/directory/symlink.
3906+
3907+
.. availability:: Linux.
3908+
3909+
.. versionadded:: 3.4
3910+
3911+
.. data:: ST_APPEND
3912+
3913+
Append-only file.
3914+
3915+
.. availability:: Linux.
3916+
3917+
.. versionadded:: 3.4
3918+
3919+
.. data:: ST_IMMUTABLE
3920+
3921+
Immutable file.
3922+
3923+
.. availability:: Linux.
3924+
3925+
.. versionadded:: 3.4
3926+
3927+
.. data:: ST_NOATIME
3928+
3929+
Do not update access times.
3930+
3931+
.. availability:: Linux.
3932+
3933+
.. versionadded:: 3.4
3934+
3935+
.. data:: ST_NODIRATIME
3936+
3937+
Do not update directory access times.
3938+
3939+
.. availability:: Linux.
3940+
3941+
.. versionadded:: 3.4
3942+
3943+
.. data:: ST_RELATIME
3944+
3945+
Update atime relative to mtime/ctime.
3946+
3947+
.. availability:: Linux.
3948+
3949+
.. versionadded:: 3.4
38293950

38303951

38313952
.. data:: supports_dir_fd

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Doc/library/lzma.rst
1818
Doc/library/mmap.rst
1919
Doc/library/multiprocessing.rst
2020
Doc/library/optparse.rst
21-
Doc/library/os.rst
2221
Doc/library/pickletools.rst
2322
Doc/library/pyexpat.rst
2423
Doc/library/select.rst

0 commit comments

Comments
 (0)