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 e
()
| 716 | |
| 717 | |
| 718 | def get_platform(): |
| 719 | """Return a string that identifies the current platform. |
| 720 | |
| 721 | This is used mainly to distinguish platform-specific build directories and |
| 722 | platform-specific built distributions. Typically includes the OS name and |
| 723 | version and the architecture (as supplied by 'os.uname()'), although the |
| 724 | exact information included depends on the OS; on Linux, the kernel version |
| 725 | isn't particularly important. |
| 726 | |
| 727 | Examples of returned values: |
| 728 | linux-i586 |
| 729 | linux-alpha (?) |
| 730 | solaris-2.6-sun4u |
| 731 | |
| 732 | Windows will return one of: |
| 733 | win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc) |
| 734 | win32 (all others - specifically, sys.platform is returned) |
| 735 | |
| 736 | For other non-POSIX platforms, currently just returns 'sys.platform'. |
| 737 | |
| 738 | """ |
| 739 | if os.name == 'nt': |
| 740 | if 'amd64' in sys.version.lower(): |
| 741 | return 'win-amd64' |
| 742 | if '(arm)' in sys.version.lower(): |
| 743 | return 'win-arm32' |
| 744 | if '(arm64)' in sys.version.lower(): |
| 745 | return 'win-arm64' |
| 746 | return sys.platform |
| 747 | |
| 748 | if os.name != "posix" or not hasattr(os, 'uname'): |
| 749 | # XXX what about the architecture? NT is Intel or Alpha |
| 750 | return sys.platform |
| 751 | |
| 752 | # Set for cross builds explicitly |
| 753 | if "_PYTHON_HOST_PLATFORM" in os.environ: |
| 754 | return os.environ["_PYTHON_HOST_PLATFORM"] |
| 755 | |
| 756 | # Try to distinguish various flavours of Unix |
| 757 | osname, host, release, version, machine = os.uname() |
| 758 | |
| 759 | # Convert the OS name to lowercase, remove '/' characters, and translate |
| 760 | # spaces (for "Power Macintosh") |
| 761 | osname = osname.lower().replace('/', '') |
| 762 | machine = machine.replace(' ', '_') |
| 763 | machine = machine.replace('/', '-') |
| 764 | |
| 765 | if osname[:5] == "linux": |
| 766 | # At least on Linux/Intel, 'machine' is the processor -- |
| 767 | # i386, etc. |
| 768 | # XXX what about Alpha, SPARC, etc? |
| 769 | return f"{osname}-{machine}" |
| 770 | elif osname[:5] == "sunos": |
| 771 | if release[0] >= "5": # SunOS 5 == Solaris 2 |
| 772 | osname = "solaris" |
| 773 | release = f"{int(release[0]) - 3}.{release[2:]}" |
| 774 | # We can't use "platform.architecture()[0]" because a |
| 775 | # bootstrap problem. We use a dict to get an error |