From fe5fd517a73a6cd69d0a1c04633bed73c9b67117 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Sat, 15 Jul 2023 23:33:32 +0100 Subject: [PATCH 1/5] gh-106789: avoid importing pprint from sysconfig --- Lib/opcode.py | 22 ++++------------------ Lib/sysconfig.py | 8 ++++++-- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Lib/opcode.py b/Lib/opcode.py index bc885051c6454e..db9b7dbee3b2c9 100644 --- a/Lib/opcode.py +++ b/Lib/opcode.py @@ -8,24 +8,10 @@ "haslocal", "hascompare", "hasfree", "hasexc", "opname", "opmap", "HAVE_ARGUMENT", "EXTENDED_ARG"] -# It's a chicken-and-egg I'm afraid: -# We're imported before _opcode's made. -# With exception unheeded -# (stack_effect is not needed) -# Both our chickens and eggs are allayed. -# --Larry Hastings, 2013/11/23 - -try: - from _opcode import stack_effect - __all__.append('stack_effect') -except ImportError: - pass - -# _opcode_metadata may not be ready during early stages of the build -try: - from _opcode_metadata import _specializations, _specialized_instructions -except ModuleNotFoundError: - pass +from _opcode import stack_effect +__all__.append('stack_effect') + +from _opcode_metadata import _specializations, _specialized_instructions cmp_op = ('<', '<=', '==', '!=', '>', '>=') diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py index 122d441bd19f5e..eba6535b78866d 100644 --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -465,10 +465,14 @@ def _get_sysconfigdata_name(): f'_sysconfigdata_{sys.abiflags}_{sys.platform}_{multiarch}', ) +def _print_config_dict(d, stream): + print (" {", file=stream) + for k, v in sorted(d.items()): + print(f" {k!r}: {v!r},", file=stream) + print ("}", file=stream) def _generate_posix_vars(): """Generate the Python module containing build-time variables.""" - import pprint vars = {} # load the installed Makefile: makefile = get_makefile_filename() @@ -523,7 +527,7 @@ def _generate_posix_vars(): f.write('# system configuration generated and used by' ' the sysconfig module\n') f.write('build_time_vars = ') - pprint.pprint(vars, stream=f) + _print_config_dict(vars, stream=f) # Create file used for sys.path fixup -- see Modules/getpath.c with open('pybuilddir.txt', 'w', encoding='utf8') as f: From df2c234773cb84c9ce42bd7eb27158794f52b050 Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Sun, 16 Jul 2023 11:38:52 +0100 Subject: [PATCH 2/5] whitespace Co-authored-by: Inada Naoki --- Lib/sysconfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py index eba6535b78866d..a8b5c5f7dfba5b 100644 --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -466,7 +466,7 @@ def _get_sysconfigdata_name(): ) def _print_config_dict(d, stream): - print (" {", file=stream) + print ("{", file=stream) for k, v in sorted(d.items()): print(f" {k!r}: {v!r},", file=stream) print ("}", file=stream) From d4cf8df4336481684d8707a37cc1aa80d64553b3 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 16 Jul 2023 10:40:38 +0000 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-07-16-10-40-34.gh-issue-106789.NvyE3C.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-07-16-10-40-34.gh-issue-106789.NvyE3C.rst diff --git a/Misc/NEWS.d/next/Library/2023-07-16-10-40-34.gh-issue-106789.NvyE3C.rst b/Misc/NEWS.d/next/Library/2023-07-16-10-40-34.gh-issue-106789.NvyE3C.rst new file mode 100644 index 00000000000000..532f8059740daf --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-07-16-10-40-34.gh-issue-106789.NvyE3C.rst @@ -0,0 +1 @@ +Remove import of :mod:``pprint`` from :mod:``sysconfig``. From 252a12bba623734d9e8486d96428524e43b3ca21 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Sun, 16 Jul 2023 11:50:43 +0100 Subject: [PATCH 4/5] tweak --- Lib/opcode.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Lib/opcode.py b/Lib/opcode.py index db9b7dbee3b2c9..a8c7acbda725e5 100644 --- a/Lib/opcode.py +++ b/Lib/opcode.py @@ -6,11 +6,9 @@ __all__ = ["cmp_op", "hasarg", "hasconst", "hasname", "hasjrel", "hasjabs", "haslocal", "hascompare", "hasfree", "hasexc", "opname", "opmap", - "HAVE_ARGUMENT", "EXTENDED_ARG"] + "stack_effect", "HAVE_ARGUMENT", "EXTENDED_ARG"] from _opcode import stack_effect -__all__.append('stack_effect') - from _opcode_metadata import _specializations, _specialized_instructions cmp_op = ('<', '<=', '==', '!=', '>', '>=') From d125f870c1c44953051ba7c1cb1707a84ada7f87 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Sun, 16 Jul 2023 13:50:40 +0100 Subject: [PATCH 5/5] fix build on pre-3.13 Pythons --- Lib/opcode.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/opcode.py b/Lib/opcode.py index a8c7acbda725e5..1b36300785aaea 100644 --- a/Lib/opcode.py +++ b/Lib/opcode.py @@ -9,7 +9,11 @@ "stack_effect", "HAVE_ARGUMENT", "EXTENDED_ARG"] from _opcode import stack_effect -from _opcode_metadata import _specializations, _specialized_instructions + +import sys +# The build uses older versions of Python which do not have _opcode_metadata +if sys.version_info[:2] >= (3, 13): + from _opcode_metadata import _specializations, _specialized_instructions cmp_op = ('<', '<=', '==', '!=', '>', '>=')