From 294b128449aa8c20d80be42d35f18788e2f488f3 Mon Sep 17 00:00:00 2001
From: Antonio Valentino <antonio.valentino@tiscali.it>
Date: Thu, 29 Dec 2022 17:01:15 +0100
Subject: [PATCH 1/3] Allow to use system blosc2 for building

---
 setup.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/setup.py b/setup.py
index 966be0286..3034cac3f 100755
--- a/setup.py
+++ b/setup.py
@@ -262,11 +262,9 @@ def run(self):
 
     debug = "--debug" in sys.argv
 
-    blosc2_inc, blosc2_lib = get_blosc2_directories()
-
     # Global variables
-    lib_dirs = [blosc2_lib]
-    inc_dirs = [Path("hdf5-blosc/src"), Path("hdf5-blosc2/src"), blosc2_inc]
+    lib_dirs = []
+    inc_dirs = [Path("hdf5-blosc/src"), Path("hdf5-blosc2/src")]
     optional_libs = []
     copy_libs = []
 
@@ -274,6 +272,15 @@ def run(self):
     default_library_dirs = None
     default_runtime_dirs = None
 
+    blosc2_inc = blosc2_lib = None
+    if os.environ.get("PYTABLES_NO_BLOASC2_WHEEL", None) is None:
+        try:
+            blosc2_inc, blosc2_lib = get_blosc2_directories()
+            lib_dirs.append(blosc2_lib)
+            inc_dirs.append(blosc2_inc)
+        except EnvironmentError:
+            pass
+
     if os.name == "posix":
         prefixes = ("/usr/local", "/sw", "/opt", "/opt/local", "/usr", "/")
         prefix_paths = [Path(x) for x in prefixes]
@@ -691,7 +698,7 @@ def find_runtime_path(self, locations=default_runtime_dirs):
     # Try to locate the compulsory and optional libraries.
     lzo2_enabled = False
     compiler = new_compiler()
-    if not BLOSC2_DIR:
+    if not BLOSC2_DIR and blosc2_inc is not None:
         # Inject the blosc2 directory as detected
         BLOSC2_DIR = os.path.dirname(blosc2_inc)
     for (package, location) in [
