1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
.. _COMMON/Platform:
Platform
########
The :class:`~pyTooling.Platform.Platform` class gives detailed platform information about the environment the
Python program or script is running in.
.. #contents:: Table of Contents
:local:
:depth: 1
.. admonition:: Background Information
Python has several ways in finding out what platform is running underneath of Python. Some information are provided
via function calls, others are variables in a module. The :class:`~pyTooling.Platform.Platform` class
unifies all these APIs into a single class instance providing access to the platform and runtime information.
Moreover, some (older) APIs do not reflect modern platforms like Python running in a MSYS2 MinGW64 environment on a
Windows x86-64. By combining multiple APIs, it's possible to identify also such platforms.
The internally used APIs are:
* :func:`platform.machine`
* :data:`sys.platform`
* :func:`sysconfig.get_platform`
These APIs are currently unused/not needed, because their information is already provided by the ones mentioned above:
* :data:`os.name`
* :func:`platform.system`
* :func:`platform.architecture`
.. _COMMON/CurrentPlatform:
Current Platform
****************
The module variable :data:`pyTooling.Common.CurrentPlatform` contains a singleton instance of
:class:`~pyTooling.Platform.Platform`, which abstracts and unifies multiple platform APIs of Python into a
single class instance.
.. rubric:: Supported platforms
* Native
* Linux (x86-64)
* macOS (x86-64)
* Windows (x86-64)
* MSYS2 (on Windows)
* MSYS
* Clang64
* MinGW32
* MinGW64
* UCRT64
* Cygwin
.. seealso::
:class:`~pyTooling.Platform.Platform`
|rarr| ``Is...`` properties describing a platform (and environment) the current Python program is running on.
.. _COMMON/CurrentPlatform/Usecases:
Usecase: Platform Specific Code
===============================
.. rubric:: Example:
.. admonition:: example.py
.. code-block:: python
from pyTooling.Common import CurrentPlatform
# Check for a native Linux platform
if CurrentPlatform.IsNativeLinux:
pass
Usecase: Platform Specific Tests
================================
.. admonition:: unittest.py
.. code-block:: python
from unittest import TestCase
from pytest import mark
from pyTooling.Common import CurrentPlatform
class MyTestCase(TestCase):
@mark.skipif(not CurrentPlatform.IsMinGW64OnWindows, reason="Skipped when platform isn't MinGW64.")
def test_OnMinGW64(self) -> None:
pass
.. _COMMON/Platform/Architectures:
Architectures
*************
The architectures describes the native bit-width of addresses in a system. Thus, the maximum addressable memory space of
a CPU. E.g. a 32-bit architecture can address 4 GiB of main memory without memory segmentation.
.. rubric:: Supported Architectures
* x86_32
* x86_64
.. code-block:: python
from pyTooling.Common import CurrentPlatform
#
CurrentPlatform.Architecture
.. _COMMON/Platform/NativePlatforms:
Native Platforms
****************
The native platform describes the hosting operating system.
.. rubric:: Supported Native Platforms
* Linux
* macOS
* Windows
.. code-block:: python
from pyTooling.Common import CurrentPlatform
# Check if the platform is a native platform
CurrentPlatform.IsNativePlatform
# Check for native Windows
CurrentPlatform.IsNativeWindows
# Check for native Linux
CurrentPlatform.IsNativeLinux
# Check for native macOS
CurrentPlatform.IsNativeMacOS
.. _COMMON/Platform/Environments:
Environments
************
An environment is an additional layer installed on an operating system that provides a runtime environment to execute
Python. E.g. the ``MSYS2`` environment provides ``MinGW64`` to run Python in a Linux like POSIX environment, but on top
of Windows.
.. rubric:: Supported Environments
* MSYS2
* Cygwin
.. code-block:: python
from pyTooling.Common import CurrentPlatform
# Check if the environment is MSYS2
CurrentPlatform.IsMSYS2Environment
.. _COMMON/Platform/Runtimes:
Runtimes
********
Some environments like ``MSYS2`` provide multiple runtimes.
.. rubric:: Supported (MSYS2) Runtimes
* MSYS
* MinGW32
* MinGW64
* UCRT64
* (CLang32)
* CLang64
.. code-block:: python
from pyTooling.Common import CurrentPlatform
# Check if the runtime is MSYS2 MinGW64 on a Windows machine
CurrentPlatform.IsMinGW64OnWindows
|