Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._vendor.distro.distro Namespace Reference

Data Structures

class  cached_property
 
class  InfoDict
 
class  LinuxDistribution
 
class  VersionDict
 

Functions

Tuple[str, str, str] linux_distribution (bool full_distribution_name=True)
 
str id ()
 
str name (bool pretty=False)
 
str version (bool pretty=False, bool best=False)
 
Tuple[str, str, str] version_parts (bool best=False)
 
str major_version (bool best=False)
 
str minor_version (bool best=False)
 
str build_number (bool best=False)
 
str like ()
 
str codename ()
 
InfoDict info (bool pretty=False, bool best=False)
 
Dict[str, str] os_release_info ()
 
Dict[str, str] lsb_release_info ()
 
Dict[str, str] distro_release_info ()
 
Dict[str, str] uname_info ()
 
str os_release_attr (str attribute)
 
str lsb_release_attr (str attribute)
 
str distro_release_attr (str attribute)
 
str uname_attr (str attribute)
 
None main ()
 

Variables

 TypedDict = dict
 
 _UNIXCONFDIR = os.environ.get("UNIXCONFDIR", "/etc")
 
 _UNIXUSRLIBDIR = os.environ.get("UNIXUSRLIBDIR", "/usr/lib")
 
str _OS_RELEASE_BASENAME = "os-release"
 
dict NORMALIZED_OS_ID
 
dict NORMALIZED_LSB_ID
 
dict NORMALIZED_DISTRO_ID
 
 _DISTRO_RELEASE_CONTENT_REVERSED_PATTERN
 
 _DISTRO_RELEASE_BASENAME_PATTERN = re.compile(r"(\w+)[-_](release|version)$")
 
list _DISTRO_RELEASE_BASENAMES
 
tuple _DISTRO_RELEASE_IGNORE_BASENAMES
 
 _distro = LinuxDistribution()
 

Detailed Description

The ``distro`` package (``distro`` stands for Linux Distribution) provides
information about the Linux distribution it runs on, such as a reliable
machine-readable distro ID, or version information.

It is the recommended replacement for Python's original
:py:func:`platform.linux_distribution` function, but it provides much more
functionality. An alternative implementation became necessary because Python
3.5 deprecated this function, and Python 3.8 removed it altogether. Its
predecessor function :py:func:`platform.dist` was already deprecated since
Python 2.6 and removed in Python 3.8. Still, there are many cases in which
access to OS distribution information is needed. See `Python issue 1322
<https://bugs.python.org/issue1322>`_ for more information.

Function Documentation

◆ build_number()

str build_number ( bool   best = False)
Return the build number of the current OS distribution, as a string,
if provided.
Otherwise, the empty string is returned. The build number is the third part
of the dot-separated version string.

For a description of the *best* parameter, see the :func:`distro.version`
method.

Definition at line 413 of file distro.py.

413def build_number(best: bool = False) -> str:
414 """
415 Return the build number of the current OS distribution, as a string,
416 if provided.
417 Otherwise, the empty string is returned. The build number is the third part
418 of the dot-separated version string.
419
420 For a description of the *best* parameter, see the :func:`distro.version`
421 method.
422 """
423 return _distro.build_number(best)
424
425
for i

References i.

◆ codename()

str codename ( )
Return the codename for the release of the current OS distribution,
as a string.

If the distribution does not have a codename, an empty string is returned.

Note that the returned codename is not always really a codename. For
example, openSUSE returns "x86_64". This function does not handle such
cases in any special way and just returns the string it finds, if any.

**Lookup hierarchy:**

* the codename within the "VERSION" attribute of the os-release file, if
  provided,

* the value of the "Codename" attribute returned by the lsb_release
  command,

* the value of the "<codename>" field of the distro release file.

Definition at line 443 of file distro.py.

443def codename() -> str:
444 """
445 Return the codename for the release of the current OS distribution,
446 as a string.
447
448 If the distribution does not have a codename, an empty string is returned.
449
450 Note that the returned codename is not always really a codename. For
451 example, openSUSE returns "x86_64". This function does not handle such
452 cases in any special way and just returns the string it finds, if any.
453
454 **Lookup hierarchy:**
455
456 * the codename within the "VERSION" attribute of the os-release file, if
457 provided,
458
459 * the value of the "Codename" attribute returned by the lsb_release
460 command,
461
462 * the value of the "<codename>" field of the distro release file.
463 """
464 return _distro.codename()
465
466

References i.

◆ distro_release_attr()

str distro_release_attr ( str  attribute)
Return a single named information item from the distro release file
data source of the current OS distribution.

Parameters:

* ``attribute`` (string): Key of the information item.

Returns:

* (string): Value of the information item, if the item exists.
  The empty string, if the item does not exist.

See `distro release file`_ for details about these information items.

Definition at line 589 of file distro.py.

589def distro_release_attr(attribute: str) -> str:
590 """
591 Return a single named information item from the distro release file
592 data source of the current OS distribution.
593
594 Parameters:
595
596 * ``attribute`` (string): Key of the information item.
597
598 Returns:
599
600 * (string): Value of the information item, if the item exists.
601 The empty string, if the item does not exist.
602
603 See `distro release file`_ for details about these information items.
604 """
605 return _distro.distro_release_attr(attribute)
606
607

References i.

◆ distro_release_info()

Dict[str, str] distro_release_info ( )
Return a dictionary containing key-value pairs for the information items
from the distro release file data source of the current OS distribution.

See `distro release file`_ for details about these information items.

Definition at line 532 of file distro.py.

532def distro_release_info() -> Dict[str, str]:
533 """
534 Return a dictionary containing key-value pairs for the information items
535 from the distro release file data source of the current OS distribution.
536
537 See `distro release file`_ for details about these information items.
538 """
540
541

References i.

◆ id()

str id ( )
Return the distro ID of the current distribution, as a
machine-readable string.

For a number of OS distributions, the returned distro ID value is
*reliable*, in the sense that it is documented and that it does not change
across releases of the distribution.

This package maintains the following reliable distro ID values:

==============  =========================================
Distro ID       Distribution
==============  =========================================
"ubuntu"        Ubuntu
"debian"        Debian
"rhel"          RedHat Enterprise Linux
"centos"        CentOS
"fedora"        Fedora
"sles"          SUSE Linux Enterprise Server
"opensuse"      openSUSE
"amzn"          Amazon Linux
"arch"          Arch Linux
"buildroot"     Buildroot
"cloudlinux"    CloudLinux OS
"exherbo"       Exherbo Linux
"gentoo"        GenToo Linux
"ibm_powerkvm"  IBM PowerKVM
"kvmibm"        KVM for IBM z Systems
"linuxmint"     Linux Mint
"mageia"        Mageia
"mandriva"      Mandriva Linux
"parallels"     Parallels
"pidora"        Pidora
"raspbian"      Raspbian
"oracle"        Oracle Linux (and Oracle Enterprise Linux)
"scientific"    Scientific Linux
"slackware"     Slackware
"xenserver"     XenServer
"openbsd"       OpenBSD
"netbsd"        NetBSD
"freebsd"       FreeBSD
"midnightbsd"   MidnightBSD
"rocky"         Rocky Linux
"aix"           AIX
"guix"          Guix System
==============  =========================================

If you have a need to get distros for reliable IDs added into this set,
or if you find that the :func:`distro.id` function returns a different
distro ID for one of the listed distros, please create an issue in the
`distro issue tracker`_.

**Lookup hierarchy and transformations:**

First, the ID is obtained from the following sources, in the specified
order. The first available and non-empty value is used:

* the value of the "ID" attribute of the os-release file,

* the value of the "Distributor ID" attribute returned by the lsb_release
  command,

* the first part of the file name of the distro release file,

The so determined ID value then passes the following transformations,
before it is returned by this method:

* it is translated to lower case,

* blanks (which should not be there anyway) are translated to underscores,

* a normalization of the ID is performed, based upon
  `normalization tables`_. The purpose of this normalization is to ensure
  that the ID is as reliable as possible, even across incompatible changes
  in the OS distributions. A common reason for an incompatible change is
  the addition of an os-release file, or the addition of the lsb_release
  command, with ID values that differ from what was previously determined
  from the distro release file name.

Definition at line 200 of file distro.py.

200def id() -> str:
201 """
202 Return the distro ID of the current distribution, as a
203 machine-readable string.
204
205 For a number of OS distributions, the returned distro ID value is
206 *reliable*, in the sense that it is documented and that it does not change
207 across releases of the distribution.
208
209 This package maintains the following reliable distro ID values:
210
211 ============== =========================================
212 Distro ID Distribution
213 ============== =========================================
214 "ubuntu" Ubuntu
215 "debian" Debian
216 "rhel" RedHat Enterprise Linux
217 "centos" CentOS
218 "fedora" Fedora
219 "sles" SUSE Linux Enterprise Server
220 "opensuse" openSUSE
221 "amzn" Amazon Linux
222 "arch" Arch Linux
223 "buildroot" Buildroot
224 "cloudlinux" CloudLinux OS
225 "exherbo" Exherbo Linux
226 "gentoo" GenToo Linux
227 "ibm_powerkvm" IBM PowerKVM
228 "kvmibm" KVM for IBM z Systems
229 "linuxmint" Linux Mint
230 "mageia" Mageia
231 "mandriva" Mandriva Linux
232 "parallels" Parallels
233 "pidora" Pidora
234 "raspbian" Raspbian
235 "oracle" Oracle Linux (and Oracle Enterprise Linux)
236 "scientific" Scientific Linux
237 "slackware" Slackware
238 "xenserver" XenServer
239 "openbsd" OpenBSD
240 "netbsd" NetBSD
241 "freebsd" FreeBSD
242 "midnightbsd" MidnightBSD
243 "rocky" Rocky Linux
244 "aix" AIX
245 "guix" Guix System
246 ============== =========================================
247
248 If you have a need to get distros for reliable IDs added into this set,
249 or if you find that the :func:`distro.id` function returns a different
250 distro ID for one of the listed distros, please create an issue in the
251 `distro issue tracker`_.
252
253 **Lookup hierarchy and transformations:**
254
255 First, the ID is obtained from the following sources, in the specified
256 order. The first available and non-empty value is used:
257
258 * the value of the "ID" attribute of the os-release file,
259
260 * the value of the "Distributor ID" attribute returned by the lsb_release
261 command,
262
263 * the first part of the file name of the distro release file,
264
265 The so determined ID value then passes the following transformations,
266 before it is returned by this method:
267
268 * it is translated to lower case,
269
270 * blanks (which should not be there anyway) are translated to underscores,
271
272 * a normalization of the ID is performed, based upon
273 `normalization tables`_. The purpose of this normalization is to ensure
274 that the ID is as reliable as possible, even across incompatible changes
275 in the OS distributions. A common reason for an incompatible change is
276 the addition of an os-release file, or the addition of the lsb_release
277 command, with ID values that differ from what was previously determined
278 from the distro release file name.
279 """
280 return _distro.id()
281
282

References i.

◆ info()

InfoDict info ( bool   pretty = False,
bool   best = False 
)
Return certain machine-readable information items about the current OS
distribution in a dictionary, as shown in the following example:

.. sourcecode:: python

    {
        'id': 'rhel',
        'version': '7.0',
        'version_parts': {
            'major': '7',
            'minor': '0',
            'build_number': ''
        },
        'like': 'fedora',
        'codename': 'Maipo'
    }

The dictionary structure and keys are always the same, regardless of which
information items are available in the underlying data sources. The values
for the various keys are as follows:

* ``id``:  The result of :func:`distro.id`.

* ``version``:  The result of :func:`distro.version`.

* ``version_parts -> major``:  The result of :func:`distro.major_version`.

* ``version_parts -> minor``:  The result of :func:`distro.minor_version`.

* ``version_parts -> build_number``:  The result of
  :func:`distro.build_number`.

* ``like``:  The result of :func:`distro.like`.

* ``codename``:  The result of :func:`distro.codename`.

For a description of the *pretty* and *best* parameters, see the
:func:`distro.version` method.

Definition at line 467 of file distro.py.

467def info(pretty: bool = False, best: bool = False) -> InfoDict:
468 """
469 Return certain machine-readable information items about the current OS
470 distribution in a dictionary, as shown in the following example:
471
472 .. sourcecode:: python
473
474 {
475 'id': 'rhel',
476 'version': '7.0',
477 'version_parts': {
478 'major': '7',
479 'minor': '0',
480 'build_number': ''
481 },
482 'like': 'fedora',
483 'codename': 'Maipo'
484 }
485
486 The dictionary structure and keys are always the same, regardless of which
487 information items are available in the underlying data sources. The values
488 for the various keys are as follows:
489
490 * ``id``: The result of :func:`distro.id`.
491
492 * ``version``: The result of :func:`distro.version`.
493
494 * ``version_parts -> major``: The result of :func:`distro.major_version`.
495
496 * ``version_parts -> minor``: The result of :func:`distro.minor_version`.
497
498 * ``version_parts -> build_number``: The result of
499 :func:`distro.build_number`.
500
501 * ``like``: The result of :func:`distro.like`.
502
503 * ``codename``: The result of :func:`distro.codename`.
504
505 For a description of the *pretty* and *best* parameters, see the
506 :func:`distro.version` method.
507 """
508 return _distro.info(pretty, best)
509
510

References i.

◆ like()

str like ( )
Return a space-separated list of distro IDs of distributions that are
closely related to the current OS distribution in regards to packaging
and programming interfaces, for example distributions the current
distribution is a derivative from.

**Lookup hierarchy:**

This information item is only provided by the os-release file.
For details, see the description of the "ID_LIKE" attribute in the
`os-release man page
<http://www.freedesktop.org/software/systemd/man/os-release.html>`_.

Definition at line 426 of file distro.py.

426def like() -> str:
427 """
428 Return a space-separated list of distro IDs of distributions that are
429 closely related to the current OS distribution in regards to packaging
430 and programming interfaces, for example distributions the current
431 distribution is a derivative from.
432
433 **Lookup hierarchy:**
434
435 This information item is only provided by the os-release file.
436 For details, see the description of the "ID_LIKE" attribute in the
437 `os-release man page
438 <http://www.freedesktop.org/software/systemd/man/os-release.html>`_.
439 """
440 return _distro.like()
441
442

References i.

◆ linux_distribution()

Tuple[str, str, str] linux_distribution ( bool   full_distribution_name = True)
.. deprecated:: 1.6.0

    :func:`distro.linux_distribution()` is deprecated. It should only be
    used as a compatibility shim with Python's
    :py:func:`platform.linux_distribution()`. Please use :func:`distro.id`,
    :func:`distro.version` and :func:`distro.name` instead.

Return information about the current OS distribution as a tuple
``(id_name, version, codename)`` with items as follows:

* ``id_name``:  If *full_distribution_name* is false, the result of
  :func:`distro.id`. Otherwise, the result of :func:`distro.name`.

* ``version``:  The result of :func:`distro.version`.

* ``codename``:  The extra item (usually in parentheses) after the
  os-release version number, or the result of :func:`distro.codename`.

The interface of this function is compatible with the original
:py:func:`platform.linux_distribution` function, supporting a subset of
its parameters.

The data it returns may not exactly be the same, because it uses more data
sources than the original function, and that may lead to different data if
the OS distribution is not consistent across multiple data sources it
provides (there are indeed such distributions ...).

Another reason for differences is the fact that the :func:`distro.id`
method normalizes the distro ID string to a reliable machine-readable value
for a number of popular OS distributions.

Definition at line 157 of file distro.py.

157def linux_distribution(full_distribution_name: bool = True) -> Tuple[str, str, str]:
158 """
159 .. deprecated:: 1.6.0
160
161 :func:`distro.linux_distribution()` is deprecated. It should only be
162 used as a compatibility shim with Python's
163 :py:func:`platform.linux_distribution()`. Please use :func:`distro.id`,
164 :func:`distro.version` and :func:`distro.name` instead.
165
166 Return information about the current OS distribution as a tuple
167 ``(id_name, version, codename)`` with items as follows:
168
169 * ``id_name``: If *full_distribution_name* is false, the result of
170 :func:`distro.id`. Otherwise, the result of :func:`distro.name`.
171
172 * ``version``: The result of :func:`distro.version`.
173
174 * ``codename``: The extra item (usually in parentheses) after the
175 os-release version number, or the result of :func:`distro.codename`.
176
177 The interface of this function is compatible with the original
178 :py:func:`platform.linux_distribution` function, supporting a subset of
179 its parameters.
180
181 The data it returns may not exactly be the same, because it uses more data
182 sources than the original function, and that may lead to different data if
183 the OS distribution is not consistent across multiple data sources it
184 provides (there are indeed such distributions ...).
185
186 Another reason for differences is the fact that the :func:`distro.id`
187 method normalizes the distro ID string to a reliable machine-readable value
188 for a number of popular OS distributions.
189 """
191 "distro.linux_distribution() is deprecated. It should only be used as a "
192 "compatibility shim with Python's platform.linux_distribution(). Please use "
193 "distro.id(), distro.version() and distro.name() instead.",
194 DeprecationWarning,
195 stacklevel=2,
196 )
197 return _distro.linux_distribution(full_distribution_name)
198
199

References i.

◆ lsb_release_attr()

str lsb_release_attr ( str  attribute)
Return a single named information item from the lsb_release command output
data source of the current OS distribution.

Parameters:

* ``attribute`` (string): Key of the information item.

Returns:

* (string): Value of the information item, if the item exists.
  The empty string, if the item does not exist.

See `lsb_release command output`_ for details about these information
items.

Definition at line 569 of file distro.py.

569def lsb_release_attr(attribute: str) -> str:
570 """
571 Return a single named information item from the lsb_release command output
572 data source of the current OS distribution.
573
574 Parameters:
575
576 * ``attribute`` (string): Key of the information item.
577
578 Returns:
579
580 * (string): Value of the information item, if the item exists.
581 The empty string, if the item does not exist.
582
583 See `lsb_release command output`_ for details about these information
584 items.
585 """
586 return _distro.lsb_release_attr(attribute)
587
588

References i.

◆ lsb_release_info()

Dict[str, str] lsb_release_info ( )
Return a dictionary containing key-value pairs for the information items
from the lsb_release command data source of the current OS distribution.

See `lsb_release command output`_ for details about these information
items.

Definition at line 521 of file distro.py.

521def lsb_release_info() -> Dict[str, str]:
522 """
523 Return a dictionary containing key-value pairs for the information items
524 from the lsb_release command data source of the current OS distribution.
525
526 See `lsb_release command output`_ for details about these information
527 items.
528 """
530
531

References i.

◆ main()

None main ( )

Definition at line 1358 of file distro.py.

1358def main() -> None:
1359 logger = logging.getLogger(__name__)
1362
1363 parser = argparse.ArgumentParser(description="OS distro info tool")
1365 "--json", "-j", help="Output in machine readable format", action="store_true"
1366 )
1367
1369 "--root-dir",
1370 "-r",
1371 type=str,
1372 dest="root_dir",
1373 help="Path to the root filesystem directory (defaults to /)",
1374 )
1375
1376 args = parser.parse_args()
1377
1378 if args.root_dir:
1379 dist = LinuxDistribution(
1380 include_lsb=False,
1381 include_uname=False,
1382 include_oslevel=False,
1383 root_dir=args.root_dir,
1384 )
1385 else:
1386 dist = _distro
1387
1388 if args.json:
1389 logger.info(json.dumps(dist.info(), indent=4, sort_keys=True))
1390 else:
1391 logger.info("Name: %s", dist.name(pretty=True))
1392 distribution_version = dist.version(pretty=True)
1393 logger.info("Version: %s", distribution_version)
1394 distribution_codename = dist.codename()
1395 logger.info("Codename: %s", distribution_codename)
1396
1397

References i, and pip._vendor.distro.distro.main().

Referenced by pip._vendor.distro.distro.main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ major_version()

str major_version ( bool   best = False)
Return the major version of the current OS distribution, as a string,
if provided.
Otherwise, the empty string is returned. The major version is the first
part of the dot-separated version string.

For a description of the *best* parameter, see the :func:`distro.version`
method.

Definition at line 387 of file distro.py.

387def major_version(best: bool = False) -> str:
388 """
389 Return the major version of the current OS distribution, as a string,
390 if provided.
391 Otherwise, the empty string is returned. The major version is the first
392 part of the dot-separated version string.
393
394 For a description of the *best* parameter, see the :func:`distro.version`
395 method.
396 """
397 return _distro.major_version(best)
398
399

References i.

◆ minor_version()

str minor_version ( bool   best = False)
Return the minor version of the current OS distribution, as a string,
if provided.
Otherwise, the empty string is returned. The minor version is the second
part of the dot-separated version string.

For a description of the *best* parameter, see the :func:`distro.version`
method.

Definition at line 400 of file distro.py.

400def minor_version(best: bool = False) -> str:
401 """
402 Return the minor version of the current OS distribution, as a string,
403 if provided.
404 Otherwise, the empty string is returned. The minor version is the second
405 part of the dot-separated version string.
406
407 For a description of the *best* parameter, see the :func:`distro.version`
408 method.
409 """
410 return _distro.minor_version(best)
411
412

References i.

◆ name()

str name ( bool   pretty = False)
Return the name of the current OS distribution, as a human-readable
string.

If *pretty* is false, the name is returned without version or codename.
(e.g. "CentOS Linux")

If *pretty* is true, the version and codename are appended.
(e.g. "CentOS Linux 7.1.1503 (Core)")

**Lookup hierarchy:**

The name is obtained from the following sources, in the specified order.
The first available and non-empty value is used:

* If *pretty* is false:

  - the value of the "NAME" attribute of the os-release file,

  - the value of the "Distributor ID" attribute returned by the lsb_release
    command,

  - the value of the "<name>" field of the distro release file.

* If *pretty* is true:

  - the value of the "PRETTY_NAME" attribute of the os-release file,

  - the value of the "Description" attribute returned by the lsb_release
    command,

  - the value of the "<name>" field of the distro release file, appended
    with the value of the pretty version ("<version_id>" and "<codename>"
    fields) of the distro release file, if available.

Definition at line 283 of file distro.py.

283def name(pretty: bool = False) -> str:
284 """
285 Return the name of the current OS distribution, as a human-readable
286 string.
287
288 If *pretty* is false, the name is returned without version or codename.
289 (e.g. "CentOS Linux")
290
291 If *pretty* is true, the version and codename are appended.
292 (e.g. "CentOS Linux 7.1.1503 (Core)")
293
294 **Lookup hierarchy:**
295
296 The name is obtained from the following sources, in the specified order.
297 The first available and non-empty value is used:
298
299 * If *pretty* is false:
300
301 - the value of the "NAME" attribute of the os-release file,
302
303 - the value of the "Distributor ID" attribute returned by the lsb_release
304 command,
305
306 - the value of the "<name>" field of the distro release file.
307
308 * If *pretty* is true:
309
310 - the value of the "PRETTY_NAME" attribute of the os-release file,
311
312 - the value of the "Description" attribute returned by the lsb_release
313 command,
314
315 - the value of the "<name>" field of the distro release file, appended
316 with the value of the pretty version ("<version_id>" and "<codename>"
317 fields) of the distro release file, if available.
318 """
319 return _distro.name(pretty)
320
321

References i.

◆ os_release_attr()

str os_release_attr ( str  attribute)
Return a single named information item from the os-release file data source
of the current OS distribution.

Parameters:

* ``attribute`` (string): Key of the information item.

Returns:

* (string): Value of the information item, if the item exists.
  The empty string, if the item does not exist.

See `os-release file`_ for details about these information items.

Definition at line 550 of file distro.py.

550def os_release_attr(attribute: str) -> str:
551 """
552 Return a single named information item from the os-release file data source
553 of the current OS distribution.
554
555 Parameters:
556
557 * ``attribute`` (string): Key of the information item.
558
559 Returns:
560
561 * (string): Value of the information item, if the item exists.
562 The empty string, if the item does not exist.
563
564 See `os-release file`_ for details about these information items.
565 """
566 return _distro.os_release_attr(attribute)
567
568

References i.

◆ os_release_info()

Dict[str, str] os_release_info ( )
Return a dictionary containing key-value pairs for the information items
from the os-release file data source of the current OS distribution.

See `os-release file`_ for details about these information items.

Definition at line 511 of file distro.py.

511def os_release_info() -> Dict[str, str]:
512 """
513 Return a dictionary containing key-value pairs for the information items
514 from the os-release file data source of the current OS distribution.
515
516 See `os-release file`_ for details about these information items.
517 """
519
520

References i.

◆ uname_attr()

str uname_attr ( str  attribute)
Return a single named information item from the distro release file
data source of the current OS distribution.

Parameters:

* ``attribute`` (string): Key of the information item.

Returns:

* (string): Value of the information item, if the item exists.
            The empty string, if the item does not exist.

Definition at line 608 of file distro.py.

608def uname_attr(attribute: str) -> str:
609 """
610 Return a single named information item from the distro release file
611 data source of the current OS distribution.
612
613 Parameters:
614
615 * ``attribute`` (string): Key of the information item.
616
617 Returns:
618
619 * (string): Value of the information item, if the item exists.
620 The empty string, if the item does not exist.
621 """
622 return _distro.uname_attr(attribute)
623
624

References i.

◆ uname_info()

Dict[str, str] uname_info ( )
Return a dictionary containing key-value pairs for the information items
from the distro release file data source of the current OS distribution.

Definition at line 542 of file distro.py.

542def uname_info() -> Dict[str, str]:
543 """
544 Return a dictionary containing key-value pairs for the information items
545 from the distro release file data source of the current OS distribution.
546 """
547 return _distro.uname_info()
548
549

References i.

◆ version()

str version ( bool   pretty = False,
bool   best = False 
)
Return the version of the current OS distribution, as a human-readable
string.

If *pretty* is false, the version is returned without codename (e.g.
"7.0").

If *pretty* is true, the codename in parenthesis is appended, if the
codename is non-empty (e.g. "7.0 (Maipo)").

Some distributions provide version numbers with different precisions in
the different sources of distribution information. Examining the different
sources in a fixed priority order does not always yield the most precise
version (e.g. for Debian 8.2, or CentOS 7.1).

Some other distributions may not provide this kind of information. In these
cases, an empty string would be returned. This behavior can be observed
with rolling releases distributions (e.g. Arch Linux).

The *best* parameter can be used to control the approach for the returned
version:

If *best* is false, the first non-empty version number in priority order of
the examined sources is returned.

If *best* is true, the most precise version number out of all examined
sources is returned.

**Lookup hierarchy:**

In all cases, the version number is obtained from the following sources.
If *best* is false, this order represents the priority order:

* the value of the "VERSION_ID" attribute of the os-release file,
* the value of the "Release" attribute returned by the lsb_release
  command,
* the version number parsed from the "<version_id>" field of the first line
  of the distro release file,
* the version number parsed from the "PRETTY_NAME" attribute of the
  os-release file, if it follows the format of the distro release files.
* the version number parsed from the "Description" attribute returned by
  the lsb_release command, if it follows the format of the distro release
  files.

Definition at line 322 of file distro.py.

322def version(pretty: bool = False, best: bool = False) -> str:
323 """
324 Return the version of the current OS distribution, as a human-readable
325 string.
326
327 If *pretty* is false, the version is returned without codename (e.g.
328 "7.0").
329
330 If *pretty* is true, the codename in parenthesis is appended, if the
331 codename is non-empty (e.g. "7.0 (Maipo)").
332
333 Some distributions provide version numbers with different precisions in
334 the different sources of distribution information. Examining the different
335 sources in a fixed priority order does not always yield the most precise
336 version (e.g. for Debian 8.2, or CentOS 7.1).
337
338 Some other distributions may not provide this kind of information. In these
339 cases, an empty string would be returned. This behavior can be observed
340 with rolling releases distributions (e.g. Arch Linux).
341
342 The *best* parameter can be used to control the approach for the returned
343 version:
344
345 If *best* is false, the first non-empty version number in priority order of
346 the examined sources is returned.
347
348 If *best* is true, the most precise version number out of all examined
349 sources is returned.
350
351 **Lookup hierarchy:**
352
353 In all cases, the version number is obtained from the following sources.
354 If *best* is false, this order represents the priority order:
355
356 * the value of the "VERSION_ID" attribute of the os-release file,
357 * the value of the "Release" attribute returned by the lsb_release
358 command,
359 * the version number parsed from the "<version_id>" field of the first line
360 of the distro release file,
361 * the version number parsed from the "PRETTY_NAME" attribute of the
362 os-release file, if it follows the format of the distro release files.
363 * the version number parsed from the "Description" attribute returned by
364 the lsb_release command, if it follows the format of the distro release
365 files.
366 """
367 return _distro.version(pretty, best)
368
369

References i.

◆ version_parts()

Tuple[str, str, str] version_parts ( bool   best = False)
Return the version of the current OS distribution as a tuple
``(major, minor, build_number)`` with items as follows:

* ``major``:  The result of :func:`distro.major_version`.

* ``minor``:  The result of :func:`distro.minor_version`.

* ``build_number``:  The result of :func:`distro.build_number`.

For a description of the *best* parameter, see the :func:`distro.version`
method.

Definition at line 370 of file distro.py.

370def version_parts(best: bool = False) -> Tuple[str, str, str]:
371 """
372 Return the version of the current OS distribution as a tuple
373 ``(major, minor, build_number)`` with items as follows:
374
375 * ``major``: The result of :func:`distro.major_version`.
376
377 * ``minor``: The result of :func:`distro.minor_version`.
378
379 * ``build_number``: The result of :func:`distro.build_number`.
380
381 For a description of the *best* parameter, see the :func:`distro.version`
382 method.
383 """
384 return _distro.version_parts(best)
385
386

References i.

Variable Documentation

◆ _distro

_distro = LinuxDistribution()
protected

Definition at line 1355 of file distro.py.

◆ _DISTRO_RELEASE_BASENAME_PATTERN

_DISTRO_RELEASE_BASENAME_PATTERN = re.compile(r"(\w+)[-_](release|version)$")
protected

Definition at line 123 of file distro.py.

◆ _DISTRO_RELEASE_BASENAMES

list _DISTRO_RELEASE_BASENAMES
protected
Initial value:
1= [
2 "SuSE-release",
3 "arch-release",
4 "base-release",
5 "centos-release",
6 "fedora-release",
7 "gentoo-release",
8 "mageia-release",
9 "mandrake-release",
10 "mandriva-release",
11 "mandrivalinux-release",
12 "manjaro-release",
13 "oracle-release",
14 "redhat-release",
15 "rocky-release",
16 "sl-release",
17 "slackware-version",
18]

Definition at line 126 of file distro.py.

◆ _DISTRO_RELEASE_CONTENT_REVERSED_PATTERN

_DISTRO_RELEASE_CONTENT_REVERSED_PATTERN
protected
Initial value:
2 r"(?:[^)]*\‍)(.*)\‍()? *(?:STL )?([\d.+\-a-z]*\d) *(?:esaeler *)?(.+)"
3)

Definition at line 118 of file distro.py.

◆ _DISTRO_RELEASE_IGNORE_BASENAMES

tuple _DISTRO_RELEASE_IGNORE_BASENAMES
protected
Initial value:
1= (
2 "debian_version",
3 "lsb-release",
4 "oem-release",
5 _OS_RELEASE_BASENAME,
6 "system-release",
7 "plesk-release",
8 "iredmail-release",
9)

Definition at line 146 of file distro.py.

◆ _OS_RELEASE_BASENAME

str _OS_RELEASE_BASENAME = "os-release"
protected

Definition at line 77 of file distro.py.

◆ _UNIXCONFDIR

_UNIXCONFDIR = os.environ.get("UNIXCONFDIR", "/etc")
protected

Definition at line 75 of file distro.py.

◆ _UNIXUSRLIBDIR

_UNIXUSRLIBDIR = os.environ.get("UNIXUSRLIBDIR", "/usr/lib")
protected

Definition at line 76 of file distro.py.

◆ NORMALIZED_DISTRO_ID

dict NORMALIZED_DISTRO_ID
Initial value:
1= {
2 "redhat": "rhel", # RHEL 6.x, 7.x
3}

Definition at line 113 of file distro.py.

◆ NORMALIZED_LSB_ID

dict NORMALIZED_LSB_ID
Initial value:
1= {
2 "enterpriseenterpriseas": "oracle", # Oracle Enterprise Linux 4
3 "enterpriseenterpriseserver": "oracle", # Oracle Linux 5
4 "redhatenterpriseworkstation": "rhel", # RHEL 6, 7 Workstation
5 "redhatenterpriseserver": "rhel", # RHEL 6, 7 Server
6 "redhatenterprisecomputenode": "rhel", # RHEL 6 ComputeNode
7}

Definition at line 98 of file distro.py.

◆ NORMALIZED_OS_ID

dict NORMALIZED_OS_ID
Initial value:
1= {
2 "ol": "oracle", # Oracle Linux
3 "opensuse-leap": "opensuse", # Newer versions of OpenSuSE report as opensuse-leap
4}

Definition at line 86 of file distro.py.

◆ TypedDict

TypedDict = dict

Definition at line 56 of file distro.py.