109
109
def _get_implementation ():
110
110
return 'Python'
111
111
112
- def get_platform ():
113
- """Return a string that identifies the current platform.
114
-
115
- This is used mainly to distinguish platform-specific build directories and
116
- platform-specific built distributions. Typically includes the OS name and
117
- version and the architecture (as supplied by 'os.uname()'), although the
118
- exact information included depends on the OS; on Linux, the kernel version
119
- isn't particularly important.
120
-
121
- Examples of returned values:
122
- linux-i586
123
- linux-alpha (?)
124
- solaris-2.6-sun4u
125
-
126
- Windows will return one of:
127
- win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
128
- win32 (all others - specifically, sys.platform is returned)
129
-
130
- For other non-POSIX platforms, currently just returns 'sys.platform'.
131
-
132
- """
133
- if os .name == 'nt' :
134
- if 'amd64' in sys .version .lower ():
135
- return 'win-amd64'
136
- if '(arm)' in sys .version .lower ():
137
- return 'win-arm32'
138
- if '(arm64)' in sys .version .lower ():
139
- return 'win-arm64'
140
- return sys .platform
141
-
142
- if os .name != "posix" or not hasattr (os , 'uname' ):
143
- # XXX what about the architecture? NT is Intel or Alpha
144
- return sys .platform
145
-
146
- # Set for cross builds explicitly
147
- if "_PYTHON_HOST_PLATFORM" in os .environ :
148
- return os .environ ["_PYTHON_HOST_PLATFORM" ]
149
-
150
- # Try to distinguish various flavours of Unix
151
- osname , host , release , version , machine = os .uname ()
152
-
153
- # Convert the OS name to lowercase, remove '/' characters, and translate
154
- # spaces (for "Power Macintosh")
155
- osname = osname .lower ().replace ('/' , '' )
156
- machine = machine .replace (' ' , '_' )
157
- machine = machine .replace ('/' , '-' )
158
-
159
- if osname [:5 ] == "linux" :
160
- if sys .platform == "android" :
161
- osname = "android"
162
- release = get_config_var ("ANDROID_API_LEVEL" )
163
-
164
- # Wheel tags use the ABI names from Android's own tools.
165
- machine = {
166
- "x86_64" : "x86_64" ,
167
- "i686" : "x86" ,
168
- "aarch64" : "arm64_v8a" ,
169
- "armv7l" : "armeabi_v7a" ,
170
- }[machine ]
171
- else :
172
- # At least on Linux/Intel, 'machine' is the processor --
173
- # i386, etc.
174
- # XXX what about Alpha, SPARC, etc?
175
- return f"{ osname } -{ machine } "
176
- elif osname [:5 ] == "sunos" :
177
- if release [0 ] >= "5" : # SunOS 5 == Solaris 2
178
- osname = "solaris"
179
- release = f"{ int (release [0 ]) - 3 } .{ release [2 :]} "
180
- # We can't use "platform.architecture()[0]" because a
181
- # bootstrap problem. We use a dict to get an error
182
- # if some suspicious happens.
183
- bitness = {2147483647 :"32bit" , 9223372036854775807 :"64bit" }
184
- machine += f".{ bitness [sys .maxsize ]} "
185
- # fall through to standard osname-release-machine representation
186
- elif osname [:3 ] == "aix" :
187
- from _aix_support import aix_platform
188
- return aix_platform ()
189
- elif osname [:6 ] == "cygwin" :
190
- osname = "cygwin"
191
- import re
192
- rel_re = re .compile (r'[\d.]+' )
193
- m = rel_re .match (release )
194
- if m :
195
- release = m .group ()
196
- elif osname [:6 ] == "darwin" :
197
- if sys .platform == "ios" :
198
- release = get_config_vars ().get ("IPHONEOS_DEPLOYMENT_TARGET" , "13.0" )
199
- osname = sys .platform
200
- machine = sys .implementation ._multiarch
201
- else :
202
- import _osx_support
203
- osname , release , machine = _osx_support .get_platform_osx (
204
- get_config_vars (),
205
- osname , release , machine )
206
-
207
- return f"{ osname } -{ release } -{ machine } "
208
-
209
112
# NOTE: site.py has copy of this function.
210
113
# Sync it when modify this function.
211
114
def _getuserbase ():
@@ -214,8 +117,8 @@ def _getuserbase():
214
117
return env_base
215
118
216
119
# Emscripten, iOS, tvOS, VxWorks, WASI, and watchOS have no home directories.
217
- # Use sysconfig.get_platform() to get the correct platform when cross-compiling.
218
- system_name = get_platform ( ).split ('-' )[0 ]
120
+ # Use _PYTHON_HOST_PLATFORM to get the correct platform when cross-compiling.
121
+ system_name = os . environ . get ( '_PYTHON_HOST_PLATFORM' , sys . platform ).split ('-' )[0 ]
219
122
if system_name in {"emscripten" , "ios" , "tvos" , "vxworks" , "wasi" , "watchos" }:
220
123
return None
221
124
@@ -719,6 +622,104 @@ def get_config_var(name):
719
622
return get_config_vars ().get (name )
720
623
721
624
625
+ def get_platform ():
626
+ """Return a string that identifies the current platform.
627
+
628
+ This is used mainly to distinguish platform-specific build directories and
629
+ platform-specific built distributions. Typically includes the OS name and
630
+ version and the architecture (as supplied by 'os.uname()'), although the
631
+ exact information included depends on the OS; on Linux, the kernel version
632
+ isn't particularly important.
633
+
634
+ Examples of returned values:
635
+ linux-i586
636
+ linux-alpha (?)
637
+ solaris-2.6-sun4u
638
+
639
+ Windows will return one of:
640
+ win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
641
+ win32 (all others - specifically, sys.platform is returned)
642
+
643
+ For other non-POSIX platforms, currently just returns 'sys.platform'.
644
+
645
+ """
646
+ if os .name == 'nt' :
647
+ if 'amd64' in sys .version .lower ():
648
+ return 'win-amd64'
649
+ if '(arm)' in sys .version .lower ():
650
+ return 'win-arm32'
651
+ if '(arm64)' in sys .version .lower ():
652
+ return 'win-arm64'
653
+ return sys .platform
654
+
655
+ if os .name != "posix" or not hasattr (os , 'uname' ):
656
+ # XXX what about the architecture? NT is Intel or Alpha
657
+ return sys .platform
658
+
659
+ # Set for cross builds explicitly
660
+ if "_PYTHON_HOST_PLATFORM" in os .environ :
661
+ return os .environ ["_PYTHON_HOST_PLATFORM" ]
662
+
663
+ # Try to distinguish various flavours of Unix
664
+ osname , host , release , version , machine = os .uname ()
665
+
666
+ # Convert the OS name to lowercase, remove '/' characters, and translate
667
+ # spaces (for "Power Macintosh")
668
+ osname = osname .lower ().replace ('/' , '' )
669
+ machine = machine .replace (' ' , '_' )
670
+ machine = machine .replace ('/' , '-' )
671
+
672
+ if osname [:5 ] == "linux" :
673
+ if sys .platform == "android" :
674
+ osname = "android"
675
+ release = get_config_var ("ANDROID_API_LEVEL" )
676
+
677
+ # Wheel tags use the ABI names from Android's own tools.
678
+ machine = {
679
+ "x86_64" : "x86_64" ,
680
+ "i686" : "x86" ,
681
+ "aarch64" : "arm64_v8a" ,
682
+ "armv7l" : "armeabi_v7a" ,
683
+ }[machine ]
684
+ else :
685
+ # At least on Linux/Intel, 'machine' is the processor --
686
+ # i386, etc.
687
+ # XXX what about Alpha, SPARC, etc?
688
+ return f"{ osname } -{ machine } "
689
+ elif osname [:5 ] == "sunos" :
690
+ if release [0 ] >= "5" : # SunOS 5 == Solaris 2
691
+ osname = "solaris"
692
+ release = f"{ int (release [0 ]) - 3 } .{ release [2 :]} "
693
+ # We can't use "platform.architecture()[0]" because a
694
+ # bootstrap problem. We use a dict to get an error
695
+ # if some suspicious happens.
696
+ bitness = {2147483647 :"32bit" , 9223372036854775807 :"64bit" }
697
+ machine += f".{ bitness [sys .maxsize ]} "
698
+ # fall through to standard osname-release-machine representation
699
+ elif osname [:3 ] == "aix" :
700
+ from _aix_support import aix_platform
701
+ return aix_platform ()
702
+ elif osname [:6 ] == "cygwin" :
703
+ osname = "cygwin"
704
+ import re
705
+ rel_re = re .compile (r'[\d.]+' )
706
+ m = rel_re .match (release )
707
+ if m :
708
+ release = m .group ()
709
+ elif osname [:6 ] == "darwin" :
710
+ if sys .platform == "ios" :
711
+ release = get_config_vars ().get ("IPHONEOS_DEPLOYMENT_TARGET" , "13.0" )
712
+ osname = sys .platform
713
+ machine = sys .implementation ._multiarch
714
+ else :
715
+ import _osx_support
716
+ osname , release , machine = _osx_support .get_platform_osx (
717
+ get_config_vars (),
718
+ osname , release , machine )
719
+
720
+ return f"{ osname } -{ release } -{ machine } "
721
+
722
+
722
723
def get_python_version ():
723
724
return _PY_VERSION_SHORT
724
725
0 commit comments