Return a string that identifies the current platform. This is used mainly to distinguish platform-specific build directories and platform-specific built distributions. Typically includes the OS name and version and the architecture (as supplied by 'os.uname()'), although the exact
()
| 636 | |
| 637 | |
| 638 | def get_platform(): |
| 639 | """Return a string that identifies the current platform. |
| 640 | |
| 641 | This is used mainly to distinguish platform-specific build directories and |
| 642 | platform-specific built distributions. Typically includes the OS name and |
| 643 | version and the architecture (as supplied by 'os.uname()'), although the |
| 644 | exact information included depends on the OS; on Linux, the kernel version |
| 645 | isn't particularly important. |
| 646 | |
| 647 | Examples of returned values: |
| 648 | linux-x86_64 |
| 649 | linux-aarch64 |
| 650 | solaris-2.6-sun4u |
| 651 | |
| 652 | |
| 653 | Windows: |
| 654 | |
| 655 | - win-amd64 (64-bit Windows on AMD64, aka x86_64, Intel64, and EM64T) |
| 656 | - win-arm64 (64-bit Windows on ARM64, aka AArch64) |
| 657 | - win32 (all others - specifically, sys.platform is returned) |
| 658 | |
| 659 | POSIX based OS: |
| 660 | |
| 661 | - linux-x86_64 |
| 662 | - macosx-15.5-arm64 |
| 663 | - macosx-26.0-universal2 (macOS on Apple Silicon or Intel) |
| 664 | - android-24-arm64_v8a |
| 665 | |
| 666 | For other non-POSIX platforms, currently just returns :data:`sys.platform`.""" |
| 667 | if os.name == 'nt': |
| 668 | import _sysconfig |
| 669 | platform = _sysconfig.get_platform() |
| 670 | if platform: |
| 671 | return platform |
| 672 | return sys.platform |
| 673 | |
| 674 | if os.name != "posix" or not hasattr(os, 'uname'): |
| 675 | # XXX what about the architecture? NT is Intel or Alpha |
| 676 | return sys.platform |
| 677 | |
| 678 | # Set for cross builds explicitly |
| 679 | if "_PYTHON_HOST_PLATFORM" in os.environ: |
| 680 | osname, _, machine = os.environ["_PYTHON_HOST_PLATFORM"].partition('-') |
| 681 | release = None |
| 682 | else: |
| 683 | # Try to distinguish various flavours of Unix |
| 684 | osname, host, release, version, machine = os.uname() |
| 685 | |
| 686 | # Convert the OS name to lowercase, remove '/' characters, and translate |
| 687 | # spaces (for "Power Macintosh") |
| 688 | osname = osname.lower().replace('/', '') |
| 689 | machine = machine.replace(' ', '_') |
| 690 | machine = machine.replace('/', '-') |
| 691 | |
| 692 | if osname == "android" or sys.platform == "android": |
| 693 | osname = "android" |
| 694 | release = get_config_var("ANDROID_API_LEVEL") |
| 695 |
searching dependent graphs…