@@ -711,6 +711,24 @@ def _syscmd_file(target, default=''):
711711 'dos' : ('' , 'MSDOS' ),
712712})
713713
714+ _sysconfig_architecture = frozendict ({
715+ 'win32' : ('x86' , '32bit' , 'WindowsPE' ),
716+ 'win32-arm' : ('ARM' , '32bit' , 'WindowsPE' ),
717+ 'win64-amd64' : ('AMD64' , '32bit' , 'WindowsPE' ),
718+ 'win64-arm' : ('ARM64' , '32bit' , 'WindowsPE' ),
719+ })
720+
721+ def _sysconfig_platform ():
722+ try :
723+ import _sysconfig
724+ except ImportError :
725+ return ('' , '' , '' )
726+
727+ platform = _sysconfig .get_platform ()
728+ if platform in _sysconfig_architecture :
729+ return _sysconfig_architecture [platform ]
730+ return ('' , '' , '' )
731+
714732def architecture (executable = sys .executable , bits = '' , linkage = '' ):
715733
716734 """ Queries the given executable (defaults to the Python interpreter
@@ -745,10 +763,15 @@ def architecture(executable=sys.executable, bits='', linkage=''):
745763 else :
746764 fileout = ''
747765
748- if not fileout and \
749- executable == sys .executable :
766+ if not fileout and executable == sys .executable :
750767 # "file" command did not return anything; we'll try to provide
751768 # some sensible defaults then...
769+ if os .name == "nt" :
770+ # Use _sysconfig.get_platform() if available
771+ _ , b , l = _sysconfig_platform ()
772+ if b :
773+ return (b , l )
774+
752775 if sys .platform in _default_architecture :
753776 b , l = _default_architecture [sys .platform ]
754777 if b :
@@ -790,10 +813,10 @@ def architecture(executable=sys.executable, bits='', linkage=''):
790813
791814
792815def _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
816+ # Use _sysconfig.get_platform() if available
817+ arch , bits , linkage = _sysconfig_platform ()
818+ if arch :
819+ return arch
797820
798821 # WOW64 processes mask the native architecture
799822 try :
@@ -811,6 +834,11 @@ def _get_machine_win32():
811834 else :
812835 if arch :
813836 return arch
837+
838+ # Try to use the PROCESSOR_* environment variables
839+ # available on Win XP and later; see
840+ # http://support.microsoft.com/kb/888731 and
841+ # http://www.geocities.com/rick_lively/MANUALS/ENV/MSWIN/PROCESSI.HTM
814842 return (
815843 os .environ .get ('PROCESSOR_ARCHITEW6432' , '' ) or
816844 os .environ .get ('PROCESSOR_ARCHITECTURE' , '' )
0 commit comments