From: Stefano Rivera <stefano@rivera.za.net>
Date: Fri, 30 Aug 2024 15:32:33 +0200
Subject: Prefer static sysconfigdata if it exists

We generate a static _sysconfigdata_ in our package, but we never use
it.

In Debian we append some extra config into the static _sysconfigdata
rather than patching it into _sysconfigdata. But that's no use unless
the module is actually used.

Forwarded: https://github.com/pypy/pypy/pull/5015
---
 lib-python/3/sysconfig.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib-python/3/sysconfig.py b/lib-python/3/sysconfig.py
index 4a25f50..ca7acf6 100644
--- a/lib-python/3/sysconfig.py
+++ b/lib-python/3/sysconfig.py
@@ -530,9 +530,15 @@ def _init_posix(vars):
     #       while _sysconfigdata_* is a static version of the same values
     #       generated by calling _generate_posix_vars as part of packaging.py.
     #       To prevent chicken-and-egg problems of needing the values before
-    #       generating them, use the dynamic version here.
-    name = os.environ.get('_PYTHON_SYSCONFIGDATA_NAME', '_sysconfigdata')
-    _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
+    #       generating them, fall back to the dynamic version here.
+    name = _get_sysconfigdata_name()
+    try:
+        _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
+    except ImportError:
+        if '_PYTHON_SYSCONFIGDATA_NAME' in os.environ:
+            raise
+        _temp = __import__("_sysconfigdata", globals(), locals(), ['build_time_vars'], 0)
+
     build_time_vars = _temp.build_time_vars
     vars.update(build_time_vars)
 
