From e604f5d0709a3fda991d7619b6efc634b1442344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:23:30 +0100 Subject: [PATCH 1/3] Fix a `NameError` in `sysconfig.expand_makefile_vars`. --- Lib/sysconfig/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/sysconfig/__init__.py b/Lib/sysconfig/__init__.py index 7a4a8f65a5eb3e..7a3483b00d4281 100644 --- a/Lib/sysconfig/__init__.py +++ b/Lib/sysconfig/__init__.py @@ -718,6 +718,9 @@ def expand_makefile_vars(s, vars): """ import re + find_var1_re = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)") + find_var2_re = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}") + # This algorithm does multiple expansion, so if vars['foo'] contains # "${bar}", it will expand ${foo} to ${bar}, and then expand # ${bar}... and so forth. This is fine as long as 'vars' comes from @@ -725,7 +728,7 @@ def expand_makefile_vars(s, vars): # according to make's variable expansion semantics. while True: - m = re.search(_findvar1_rx, s) or re.search(_findvar2_rx, s) + m = find_var1_re.search(s) or find_var2_re.search(s) if m: (beg, end) = m.span() s = s[0:beg] + vars.get(m.group(1)) + s[end:] From c6554fe2c36b3c122a8ee8ada6a8e225dc7e19d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sat, 18 Jan 2025 11:04:49 +0100 Subject: [PATCH 2/3] blurb --- .../next/Library/2025-01-18-11-04-44.gh-issue-128978.hwg7-w.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-01-18-11-04-44.gh-issue-128978.hwg7-w.rst diff --git a/Misc/NEWS.d/next/Library/2025-01-18-11-04-44.gh-issue-128978.hwg7-w.rst b/Misc/NEWS.d/next/Library/2025-01-18-11-04-44.gh-issue-128978.hwg7-w.rst new file mode 100644 index 00000000000000..521496d6a2f8c2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-01-18-11-04-44.gh-issue-128978.hwg7-w.rst @@ -0,0 +1,2 @@ +Fix a :exc:`NameError` in :func:`!sysconfig.expand_makefile_vars`. Patch by +Bénédikt Tran. From cbd3b51d79b38bfba0aba7f740ba3b0e71538824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Mon, 20 Jan 2025 14:02:28 +0100 Subject: [PATCH 3/3] use `sysconfig.__main__` code instead --- Lib/sysconfig/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/sysconfig/__init__.py b/Lib/sysconfig/__init__.py index 7a3483b00d4281..ec9bb705925cdb 100644 --- a/Lib/sysconfig/__init__.py +++ b/Lib/sysconfig/__init__.py @@ -718,8 +718,8 @@ def expand_makefile_vars(s, vars): """ import re - find_var1_re = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)") - find_var2_re = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}") + _findvar1_rx = r"\$\(([A-Za-z][A-Za-z0-9_]*)\)" + _findvar2_rx = r"\${([A-Za-z][A-Za-z0-9_]*)}" # This algorithm does multiple expansion, so if vars['foo'] contains # "${bar}", it will expand ${foo} to ${bar}, and then expand @@ -728,7 +728,7 @@ def expand_makefile_vars(s, vars): # according to make's variable expansion semantics. while True: - m = find_var1_re.search(s) or find_var2_re.search(s) + m = re.search(_findvar1_rx, s) or re.search(_findvar2_rx, s) if m: (beg, end) = m.span() s = s[0:beg] + vars.get(m.group(1)) + s[end:]