@@ -711,6 +711,26 @@ def _syscmd_file(target, default=''):
711711 'dos' : ('' , 'MSDOS' ),
712712})
713713
714+
715+ _sysconfig_architecture = frozendict ({
716+ 'win32' : ('x86' , '32bit' , 'WindowsPE' ),
717+ 'win32-arm' : ('ARM' , '32bit' , 'WindowsPE' ),
718+ 'win64-amd64' : ('AMD64' , '32bit' , 'WindowsPE' ),
719+ 'win64-arm' : ('ARM64' , '32bit' , 'WindowsPE' ),
720+ })
721+
722+ def _sysconfig_platform ():
723+ try :
724+ import _sysconfig
725+ except ImportError :
726+ return ('' , '' , '' )
727+
728+ platform = _sysconfig .get_platform ()
729+ if platform in _sysconfig_architecture :
730+ return _sysconfig_architecture [platform ]
731+ return ('' , '' , '' )
732+
733+
714734def architecture (executable = sys .executable , bits = '' , linkage = '' ):
715735
716736 """ Queries the given executable (defaults to the Python interpreter
@@ -745,10 +765,15 @@ def architecture(executable=sys.executable, bits='', linkage=''):
745765 else :
746766 fileout = ''
747767
748- if not fileout and \
749- executable == sys .executable :
768+ if not fileout and executable == sys .executable :
750769 # "file" command did not return anything; we'll try to provide
751770 # some sensible defaults then...
771+ if os .name == "nt" :
772+ # Use _sysconfig.get_platform() if available
773+ _ , b , l = _sysconfig_platform ()
774+ if b :
775+ return (b , l )
776+
752777 if sys .platform in _default_architecture :
753778 b , l = _default_architecture [sys .platform ]
754779 if b :
@@ -790,10 +815,10 @@ def architecture(executable=sys.executable, bits='', linkage=''):
790815
791816
792817def _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
818+ # Use _sysconfig.get_platform() if available
819+ arch , bits , linkage = _sysconfig_platform ()
820+ if arch :
821+ return arch
797822
798823 # WOW64 processes mask the native architecture
799824 try :
@@ -811,6 +836,11 @@ def _get_machine_win32():
811836 else :
812837 if arch :
813838 return arch
839+
840+ # Try to use the PROCESSOR_* environment variables
841+ # available on Win XP and later; see
842+ # http://support.microsoft.com/kb/888731 and
843+ # http://www.geocities.com/rick_lively/MANUALS/ENV/MSWIN/PROCESSI.HTM
814844 return (
815845 os .environ .get ('PROCESSOR_ARCHITEW6432' , '' ) or
816846 os .environ .get ('PROCESSOR_ARCHITECTURE' , '' )
0 commit comments