Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Restore platform.processor behavior to match prior expectation (relia…
…nt on uname -p in a subprocess).
  • Loading branch information
jaraco committed Mar 8, 2019
commit 9a628c4aeba7c174f3dbf829e7c84354880101f7
24 changes: 13 additions & 11 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,16 +718,12 @@ def _get_machine_win32():
class _Processor:
@classmethod
def get(cls):
func = getattr(cls, f'get_{sys.platform}', cls.from_cpu_info)
func = getattr(cls, f'get_{sys.platform}', cls.from_subprocess)
return func() or ''

def get_win32():
return os.environ.get('PROCESSOR_IDENTIFIER', _get_machine_win32())

def get_darwin():
cmd = 'sysctl -n machdep.cpu.brand_string'.split()
return subprocess.check_output(cmd, text=True).strip()

def get_OpenVMS():
try:
import vms_lib
Expand All @@ -737,12 +733,18 @@ def get_OpenVMS():
csid, cpu_number = vms_lib.getsyi('SYI$_CPU', 0)
return 'Alpha' if cpu_number >= 128 else 'VAX'

def from_cpu_info():
pattern = re.compile(r'model name\s+: (.*)')
with contextlib.suppress(Exception):
with open('/proc/cpuinfo') as lines:
matched = next(filter(pattern.match, lines))
return pattern.match(matched).group(1)
def from_subprocess():
"""
Fall back to `uname -p`
"""
try:
return subprocess.check_output(
['uname', '-p'],
stderr=subprocess.DEVNULL,
text=True,
).strip()
except (OSError, subprocess.CalledProcessError):
pass


### Portable uname() interface
Expand Down