Platform

The Platform class gives detailed platform information about the environment the Python program or script is running in.

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 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:

These APIs are currently unused/not needed, because their information is already provided by the ones mentioned above:

Current Platform

The module variable pyTooling.Common.CurrentPlatform contains a singleton instance of Platform, which abstracts and unifies multiple platform APIs of Python into a single class instance.

Supported platforms

  • Native

    • Linux (x86-64)

    • macOS (x86-64)

    • Windows (x86-64)

  • MSYS2 (on Windows)

    • MSYS

    • Clang64

    • MinGW32

    • MinGW64

    • UCRT64

  • Cygwin

See also

Platform

Is... properties describing a platform (and environment) the current Python program is running on.

Usecase: Platform Specific Code

Example:

example.py

from pyTooling.Common import CurrentPlatform

# Check for a native Linux platform
if CurrentPlatform.IsNativeLinux:
  pass

Usecase: Platform Specific Tests

unittest.py

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

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.

Supported Architectures

  • x86_32

  • x86_64

from pyTooling.Common import CurrentPlatform

#
CurrentPlatform.Architecture

Native Platforms

The native platform describes the hosting operating system.

Supported Native Platforms

  • Linux

  • macOS

  • Windows

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

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.

Supported Environments

  • MSYS2

  • Cygwin

from pyTooling.Common import CurrentPlatform

# Check if the environment is MSYS2
CurrentPlatform.IsMSYS2Environment

Runtimes

Some environments like MSYS2 provide multiple runtimes.

Supported (MSYS2) Runtimes

  • MSYS

  • MinGW32

  • MinGW64

  • UCRT64

  • (CLang32)

  • CLang64

from pyTooling.Common import CurrentPlatform

# Check if the runtime is MSYS2 MinGW64 on a Windows machine
CurrentPlatform.IsMinGW64OnWindows