Skip to content

Commit be6cbfb

Browse files
authored
bpo-35952: Sync test.pythoninfo from master (GH-13010)
1 parent f4edd39 commit be6cbfb

File tree

1 file changed

+65
-8
lines changed

1 file changed

+65
-8
lines changed

Lib/test/pythoninfo.py

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import re
77
import sys
88
import traceback
9+
import warnings
910

1011

1112
def normalize_text(text):
@@ -142,7 +143,11 @@ def collect_platform(info_add):
142143
info_add('platform.python_implementation',
143144
platform.python_implementation())
144145
info_add('platform.platform',
145-
platform.platform(aliased=True, terse=True))
146+
platform.platform(aliased=True))
147+
148+
libc_ver = ('%s %s' % platform.libc_ver()).strip()
149+
if libc_ver:
150+
info_add('platform.libc_ver', libc_ver)
146151

147152

148153
def collect_locale(info_add):
@@ -376,9 +381,17 @@ def collect_time(info_add):
376381
copy_attributes(info_add, time, 'time.%s', attributes)
377382

378383
if hasattr(time, 'get_clock_info'):
379-
for clock in ('time', 'perf_counter'):
380-
tinfo = time.get_clock_info(clock)
381-
info_add('time.get_clock_info(%s)' % clock, tinfo)
384+
for clock in ('clock', 'monotonic', 'perf_counter',
385+
'process_time', 'thread_time', 'time'):
386+
try:
387+
# prevent DeprecatingWarning on get_clock_info('clock')
388+
with warnings.catch_warnings(record=True):
389+
clock_info = time.get_clock_info(clock)
390+
except ValueError:
391+
# missing clock like time.thread_time()
392+
pass
393+
else:
394+
info_add('time.get_clock_info(%s)' % clock, clock_info)
382395

383396

384397
def collect_datetime(info_add):
@@ -407,7 +420,10 @@ def collect_sysconfig(info_add):
407420
'OPT',
408421
'PY_CFLAGS',
409422
'PY_CFLAGS_NODIST',
423+
'PY_CORE_LDFLAGS',
410424
'PY_LDFLAGS',
425+
'PY_LDFLAGS_NODIST',
426+
'PY_STDMODULE_CFLAGS',
411427
'Py_DEBUG',
412428
'Py_ENABLE_SHARED',
413429
'SHELL',
@@ -513,6 +529,8 @@ def collect_resource(info_add):
513529
value = resource.getrlimit(key)
514530
info_add('resource.%s' % name, value)
515531

532+
call_func(info_add, 'resource.pagesize', resource, 'getpagesize')
533+
516534

517535
def collect_test_socket(info_add):
518536
try:
@@ -553,10 +571,17 @@ def collect_cc(info_add):
553571
except ImportError:
554572
args = CC.split()
555573
args.append('--version')
556-
proc = subprocess.Popen(args,
557-
stdout=subprocess.PIPE,
558-
stderr=subprocess.STDOUT,
559-
universal_newlines=True)
574+
try:
575+
proc = subprocess.Popen(args,
576+
stdout=subprocess.PIPE,
577+
stderr=subprocess.STDOUT,
578+
universal_newlines=True)
579+
except OSError:
580+
# Cannot run the compiler, for example when Python has been
581+
# cross-compiled and installed on the target platform where the
582+
# compiler is missing.
583+
return
584+
560585
stdout = proc.communicate()[0]
561586
if proc.returncode:
562587
# CC --version failed: ignore error
@@ -567,6 +592,35 @@ def collect_cc(info_add):
567592
info_add('CC.version', text)
568593

569594

595+
def collect_gdbm(info_add):
596+
try:
597+
from _gdbm import _GDBM_VERSION
598+
except ImportError:
599+
return
600+
601+
info_add('gdbm.GDBM_VERSION', '.'.join(map(str, _GDBM_VERSION)))
602+
603+
604+
def collect_get_config(info_add):
605+
# Dump global configuration variables, _PyCoreConfig
606+
# and _PyMainInterpreterConfig
607+
try:
608+
from _testinternalcapi import get_configs
609+
except ImportError:
610+
return
611+
612+
all_configs = get_configs()
613+
for config_type in sorted(all_configs):
614+
config = all_configs[config_type]
615+
for key in sorted(config):
616+
info_add('%s[%s]' % (config_type, key), repr(config[key]))
617+
618+
619+
def collect_subprocess(info_add):
620+
import subprocess
621+
copy_attributes(info_add, subprocess, 'subprocess.%s', ('_USE_POSIX_SPAWN',))
622+
623+
570624
def collect_info(info):
571625
error = False
572626
info_add = info.add
@@ -594,6 +648,9 @@ def collect_info(info):
594648
collect_testcapi,
595649
collect_resource,
596650
collect_cc,
651+
collect_gdbm,
652+
collect_get_config,
653+
collect_subprocess,
597654

598655
# Collecting from tests should be last as they have side effects.
599656
collect_test_socket,

0 commit comments

Comments
 (0)