git: d619cbab6a60 - main - x11-toolkits/ntk: Unbreak by adding imp.py shim on PYTHONPATH for bundled waf on Python 3.12

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Sat, 11 Jul 2026 01:00:17 UTC
The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=d619cbab6a60fea3511c3a08de880d854212566a

commit d619cbab6a60fea3511c3a08de880d854212566a
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2026-07-11 00:55:18 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2026-07-11 01:00:13 +0000

    x11-toolkits/ntk: Unbreak by adding imp.py shim on PYTHONPATH for bundled waf on Python 3.12
    
    Reported by:    fallout
---
 x11-toolkits/ntk/Makefile     |  6 ++++++
 x11-toolkits/ntk/files/imp.py | 48 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/x11-toolkits/ntk/Makefile b/x11-toolkits/ntk/Makefile
index bb5f7a89ac20..24f1159e465c 100644
--- a/x11-toolkits/ntk/Makefile
+++ b/x11-toolkits/ntk/Makefile
@@ -26,6 +26,12 @@ WRKSRC=		${WRKDIR}/${PORTNAME}
 
 PLIST_SUB=	SHLIB_VER=${PORTVERSION:R}
 
+# The bundled waf's waflib still imports the 'imp' module removed in
+# Python 3.12.  Provide a minimal shim on PYTHONPATH so waflib can be
+# imported on 3.12 while still working on earlier versions.
+CONFIGURE_ENV+=	PYTHONPATH=${FILESDIR}${PYTHONPATH:S/^/:/}
+MAKE_ENV+=		PYTHONPATH=${FILESDIR}${PYTHONPATH:S/^/:/}
+
 post-patch:
 	@${REINPLACE_CMD} -e " \
 		s|conf\.env\['LIB_DL'\] = \['dl'\]|conf.env['LIB_DL'] = []|; \
diff --git a/x11-toolkits/ntk/files/imp.py b/x11-toolkits/ntk/files/imp.py
new file mode 100644
index 000000000000..f4a62aa67164
--- /dev/null
+++ b/x11-toolkits/ntk/files/imp.py
@@ -0,0 +1,48 @@
+"""Compatibility shim for the 'imp' module removed in Python 3.12.
+
+The bundled waf waflib still imports imp; on Python 3.12 we provide the
+few attributes that waflib uses (new_module, get_tag, load_source).
+On older versions we re-export the real built-in imp module.
+"""
+
+import importlib.util
+import sys
+import types
+
+
+def _provide_shim():
+    def new_module(name):
+        return types.ModuleType(name)
+
+    def get_tag():
+        return sys.implementation.cache_tag
+
+    def load_source(name, pathname):
+        spec = importlib.util.spec_from_file_location(name, pathname)
+        if spec is None or spec.loader is None:
+            raise ImportError("cannot load %r from %r" % (name, pathname))
+        mod = importlib.util.module_from_spec(spec)
+        spec.loader.exec_module(mod)
+        return mod
+
+    globals().update({
+        'new_module': new_module,
+        'get_tag': get_tag,
+        'load_source': load_source,
+    })
+
+
+if sys.version_info < (3, 12):
+    # Re-export the real built-in imp module instead of shadowing it.
+    _shim = sys.modules['imp']
+    del sys.modules['imp']
+    try:
+        import imp as _real_imp
+    except Exception:
+        _provide_shim()
+        sys.modules['imp'] = sys.modules.get('imp', _shim)
+    else:
+        globals().update(_real_imp.__dict__)
+        sys.modules['imp'] = _real_imp
+else:
+    _provide_shim()