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

Function architecture

Lib/platform.py:714–789  ·  view source on GitHub ↗

Queries the given executable (defaults to the Python interpreter binary) for various architecture information. Returns a tuple (bits, linkage) which contains information about the bit architecture and the linkage format used for the executable. Both values are retur

(executable=sys.executable, bits='', linkage='')

Source from the content-addressed store, hash-verified

712})
713
714def architecture(executable=sys.executable, bits='', linkage=''):
715
716 """ Queries the given executable (defaults to the Python interpreter
717 binary) for various architecture information.
718
719 Returns a tuple (bits, linkage) which contains information about
720 the bit architecture and the linkage format used for the
721 executable. Both values are returned as strings.
722
723 Values that cannot be determined are returned as given by the
724 parameter presets. If bits is given as '', the sizeof(pointer)
725 (or sizeof(long) on Python version < 1.5.2) is used as
726 indicator for the supported pointer size.
727
728 The function relies on the system&#x27;s "file" command to do the
729 actual work. This is available on most if not all Unix
730 platforms. On some non-Unix platforms where the "file" command
731 does not exist and the executable is set to the Python interpreter
732 binary defaults from _default_architecture are used.
733
734 """
735 # Use the sizeof(pointer) as default number of bits if nothing
736 # else is given as default.
737 if not bits:
738 import struct
739 size = struct.calcsize('P')
740 bits = str(size * 8) + 'bit'
741
742 # Get data from the 'file' system command
743 if executable:
744 fileout = _syscmd_file(executable, '')
745 else:
746 fileout = ''
747
748 if not fileout and \
749 executable == sys.executable:
750 # "file" command did not return anything; we'll try to provide
751 # some sensible defaults then...
752 if sys.platform in _default_architecture:
753 b, l = _default_architecture[sys.platform]
754 if b:
755 bits = b
756 if l:
757 linkage = l
758 return bits, linkage
759
760 if 'executable' not in fileout and 'shared object' not in fileout:
761 # Format not supported
762 return bits, linkage
763
764 # Bits
765 if '32-bit' in fileout:
766 bits = '32bit'
767 elif '64-bit' in fileout:
768 bits = '64bit'
769
770 # Linkage
771 if 'ELF' in fileout:

Callers 2

help_about.pyFile · 0.90
platformFunction · 0.85

Calls 2

strFunction · 0.85
_syscmd_fileFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…