From 297fdd2348137ff46bd519d902b906b4550ded79 Mon Sep 17 00:00:00 2001
From: Klaus Zimmermann <klaus.zimmermann@smhi.se>
Date: Mon, 14 Nov 2022 19:47:41 +0100
Subject: [PATCH] Improve numpy fixing

---
 swig/python/setup.py.in | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/swig/python/setup.py.in b/swig/python/setup.py.in
index fba13d0e61..c22d19f113 100644
--- a/swig/python/setup.py.in
+++ b/swig/python/setup.py.in
@@ -60,7 +60,14 @@ libraries = ['@GDAL_LIB_OUTPUT_NAME@']
 # Function to find numpy's include directory
 def get_numpy_include():
     # Fix numpy installation using setuptools
-    __builtins__.__NUMPY_SETUP__ = False
+    # __builtins__ can be either a dict or a module
+    def _set_builtin(name, value):
+        if isinstance(__builtins__, dict):
+            __builtins__[name] = value
+        else:
+            setattr(__builtins__, name, value)
+
+    _set_builtin("__NUMPY_SETUP__", False)
 
     import numpy
     return numpy.get_include()
-- 
2.35.1

