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