MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / get_platform

Function get_platform

tools/python-3.11.9-amd64/Lib/sysconfig.py:718–796  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

716
717
718def 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

Callers 5

test_finalize_optionsMethod · 0.90
get_build_platformFunction · 0.90
get_build_platformFunction · 0.90
_generate_posix_varsFunction · 0.70
_mainFunction · 0.70

Calls 7

aix_platformFunction · 0.90
get_config_varsFunction · 0.70
lowerMethod · 0.45
replaceMethod · 0.45
compileMethod · 0.45
matchMethod · 0.45
groupMethod · 0.45

Tested by 1

test_finalize_optionsMethod · 0.72