MCPcopy Index your code
hub / github.com/python/cpython / get_host_platform

Function get_host_platform

Tools/c-analyzer/distutils/util.py:13–91  ·  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 exact info

()

Source from the content-addressed store, hash-verified

11from distutils.errors import DistutilsPlatformError
12
13def get_host_platform():
14 """Return a string that identifies the current platform. This is used mainly to
15 distinguish platform-specific build directories and platform-specific built
16 distributions. Typically includes the OS name and version and the
17 architecture (as supplied by 'os.uname()'), although the exact information
18 included depends on the OS; eg. on Linux, the kernel version isn't
19 particularly important.
20
21 Examples of returned values:
22 linux-x86_64
23 linux-aarch64
24 solaris-2.6-sun4u
25
26 Windows will return one of:
27 win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
28 win32 (all others - specifically, sys.platform is returned)
29
30 For other non-POSIX platforms, currently just returns 'sys.platform'.
31
32 """
33 if os.name == 'nt':
34 if 'amd64' in sys.version.lower():
35 return 'win-amd64'
36 if '(arm)' in sys.version.lower():
37 return 'win-arm32'
38 if '(arm64)' in sys.version.lower():
39 return 'win-arm64'
40 return sys.platform
41
42 # Set for cross builds explicitly
43 if "_PYTHON_HOST_PLATFORM" in os.environ:
44 return os.environ["_PYTHON_HOST_PLATFORM"]
45
46 if os.name != "posix" or not hasattr(os, 'uname'):
47 # XXX what about the architecture? NT is Intel or Alpha,
48 # Mac OS is M68k or PPC, etc.
49 return sys.platform
50
51 # Try to distinguish various flavours of Unix
52
53 (osname, host, release, version, machine) = os.uname()
54
55 # Convert the OS name to lowercase, remove '/' characters, and translate
56 # spaces (for "Power Macintosh")
57 osname = osname.lower().replace('/', '')
58 machine = machine.replace(' ', '_')
59 machine = machine.replace('/', '-')
60
61 if osname[:5] == "linux":
62 # At least on Linux/Intel, 'machine' is the processor --
63 # i386, etc.
64 # XXX what about Alpha, SPARC, etc?
65 return "%s-%s" % (osname, machine)
66 elif osname[:5] == "sunos":
67 if release[0] >= "5": # SunOS 5 == Solaris 2
68 osname = "solaris"
69 release = "%d.%s" % (int(release[0]) - 3, release[2:])
70 # We can't use "platform.architecture()[0]" because a

Callers 1

get_platformFunction · 0.85

Calls 6

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…