@@ -711,6 +711,27 @@ def _syscmd_file(target, default=''):
711711 'dos' : ('' , 'MSDOS' ),
712712})
713713
714+
715+ _sysconfig_architecture = frozendict ({
716+ # platform: (arch, bits, linkage)
717+ 'win32' : ('x86' , '32bit' , 'WindowsPE' ),
718+ 'win-amd64' : ('AMD64' , '32bit' , 'WindowsPE' ),
719+ 'win-arm32' : ('ARM' , '32bit' , 'WindowsPE' ),
720+ 'win-arm64' : ('ARM64' , '64bit' , 'WindowsPE' ),
721+ })
722+
723+ def _sysconfig_platform ():
724+ try :
725+ import _sysconfig
726+ except ImportError :
727+ return ('' , '' , '' )
728+
729+ platform = _sysconfig .get_platform ()
730+ if platform in _sysconfig_architecture :
731+ return _sysconfig_architecture [platform ]
732+ return ('' , '' , '' )
733+
734+
714735def architecture (executable = sys .executable , bits = '' , linkage = '' ):
715736
716737 """ Queries the given executable (defaults to the Python interpreter
@@ -745,10 +766,15 @@ def architecture(executable=sys.executable, bits='', linkage=''):
745766 else :
746767 fileout = ''
747768
748- if not fileout and \
749- executable == sys .executable :
769+ if not fileout and executable == sys .executable :
750770 # "file" command did not return anything; we'll try to provide
751771 # some sensible defaults then...
772+ if os .name == "nt" :
773+ # Use _sysconfig.get_platform() if available
774+ _ , b , l = _sysconfig_platform ()
775+ if b :
776+ return (b , l )
777+
752778 if sys .platform in _default_architecture :
753779 b , l = _default_architecture [sys .platform ]
754780 if b :
@@ -790,10 +816,10 @@ def architecture(executable=sys.executable, bits='', linkage=''):
790816
791817
792818def _get_machine_win32 ():
793- # Try to use the PROCESSOR_* environment variables
794- # available on Win XP and later; see
795- # http://support.microsoft.com/kb/888731 and
796- # http://www.geocities.com/rick_lively/MANUALS/ENV/MSWIN/PROCESSI.HTM
819+ # Use _sysconfig.get_platform() if available
820+ arch , bits , linkage = _sysconfig_platform ()
821+ if arch :
822+ return arch
797823
798824 # WOW64 processes mask the native architecture
799825 try :
@@ -811,6 +837,11 @@ def _get_machine_win32():
811837 else :
812838 if arch :
813839 return arch
840+
841+ # Try to use the PROCESSOR_* environment variables
842+ # available on Win XP and later; see
843+ # http://support.microsoft.com/kb/888731 and
844+ # http://www.geocities.com/rick_lively/MANUALS/ENV/MSWIN/PROCESSI.HTM
814845 return (
815846 os .environ .get ('PROCESSOR_ARCHITEW6432' , '' ) or
816847 os .environ .get ('PROCESSOR_ARCHITECTURE' , '' )
0 commit comments