Repository: rasterio/rasterio (language: python)

Issue:
Find GDAL data by looking for gdalvrt.xsd
header.dxf is no longer included in wheels. This must be done before 1.4b2.


Discussion / hints:

Fix patch:
diff --git a/CHANGES.txt b/CHANGES.txt
index b74f9f140..3feb2b92a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -6,6 +6,7 @@ Next (TBD)
 
 Bug fixes:
 
+- Find installed GDAL data directory by searching for gdalvrt.xsd (#3157).
 - Allow rasterio.open() to receive instances of MemoryFile (#3145).
 - Leaks of CSL string lists in get/set_proj_data_search_path() have been fixed
   (#3140).
diff --git a/rasterio/_env.pyx b/rasterio/_env.pyx
index cf6bec21a..da124f099 100644
--- a/rasterio/_env.pyx
+++ b/rasterio/_env.pyx
@@ -238,7 +238,7 @@ class GDALDataFinder:
         Parameters
         ----------
         basename : str
-            Basename of a data file such as "header.dxf"
+            Basename of a data file such as "gdalvrt.xsd"
 
         Returns
         -------
@@ -276,18 +276,18 @@ class GDALDataFinder:
         if prefix is None:
             prefix = __file__
         datadir = os.path.abspath(os.path.join(os.path.dirname(prefix), "gdal_data"))
-        return datadir if os.path.exists(os.path.join(datadir, 'header.dxf')) else None
+        return datadir if os.path.exists(os.path.join(datadir, 'gdalvrt.xsd')) else None
 
     def search_prefix(self, prefix=sys.prefix):
         """Check sys.prefix location"""
         datadir = os.path.join(prefix, 'share', 'gdal')
-        return datadir if os.path.exists(os.path.join(datadir, 'header.dxf')) else None
+        return datadir if os.path.exists(os.path.join(datadir, 'gdalvrt.xsd')) else None
 
     def search_debian(self, prefix=sys.prefix):
         """Check Debian locations"""
         gdal_release_name = gdal_version()
         datadir = os.path.join(prefix, 'share', 'gdal', '{}.{}'.format(*gdal_release_name.split('.')[:2]))
-        return datadir if os.path.exists(os.path.join(datadir, 'header.dxf')) else None
+        return datadir if os.path.exists(os.path.join(datadir, 'gdalvrt.xsd')) else None
 
 
 @contextmanager
@@ -390,7 +390,7 @@ cdef class GDALEnv(ConfigEnv):
                             self.update_config_options(GDAL_DATA=path)
 
                         # See https://github.com/rasterio/rasterio/issues/1631.
-                        elif GDALDataFinder().find_file("header.dxf"):
+                        elif GDALDataFinder().find_file("gdalvrt.xsd"):
                             log.debug("GDAL data files are available at built-in paths.")
 
                         else:
diff --git a/rasterio/env.py b/rasterio/env.py
index 62797dbf9..bdfca01ba 100644
--- a/rasterio/env.py
+++ b/rasterio/env.py
@@ -661,7 +661,7 @@ def wrapper(*args, **kwds):
         set_gdal_config("GDAL_DATA", path)
 
     # See https://github.com/rasterio/rasterio/issues/1631.
-    elif GDALDataFinder().find_file("header.dxf"):
+    elif GDALDataFinder().find_file("gdalvrt.xsd"):
         log.debug("GDAL data files are available at built-in paths.")
 
     else:


Test patch:
diff --git a/tests/test__env.py b/tests/test__env.py
index 5a781fc07..5191cc3ae 100644
--- a/tests/test__env.py
+++ b/tests/test__env.py
@@ -18,7 +18,7 @@ def mock_wheel(tmpdir):
     moduledir = tmpdir.mkdir("rasterio")
     moduledir.ensure("__init__.py")
     moduledir.ensure("_env.py")
-    moduledir.ensure("gdal_data/header.dxf")
+    moduledir.ensure("gdal_data/gdalvrt.xsd")
     moduledir.ensure("proj_data/epsg")
     return moduledir
 
@@ -26,7 +26,7 @@ def mock_wheel(tmpdir):
 @pytest.fixture
 def mock_fhs(tmpdir):
     """A fake FHS system"""
-    tmpdir.ensure("share/gdal/header.dxf")
+    tmpdir.ensure("share/gdal/gdalvrt.xsd")
     tmpdir.ensure("share/proj/epsg")
     return tmpdir
 
@@ -34,11 +34,11 @@ def mock_fhs(tmpdir):
 @pytest.fixture
 def mock_debian(tmpdir):
     """A fake Debian multi-install system"""
-    tmpdir.ensure("share/gdal/3.3/header.dxf")
-    tmpdir.ensure("share/gdal/3.4/header.dxf")
-    tmpdir.ensure("share/gdal/3.5/header.dxf")
-    tmpdir.ensure("share/gdal/3.6/header.dxf")
-    tmpdir.ensure(f"share/gdal/{gdal_version.major}.{gdal_version.minor}/header.dxf")
+    tmpdir.ensure("share/gdal/3.3/gdalvrt.xsd")
+    tmpdir.ensure("share/gdal/3.4/gdalvrt.xsd")
+    tmpdir.ensure("share/gdal/3.5/gdalvrt.xsd")
+    tmpdir.ensure("share/gdal/3.6/gdalvrt.xsd")
+    tmpdir.ensure(f"share/gdal/{gdal_version.major}.{gdal_version.minor}/gdalvrt.xsd")
     tmpdir.ensure("share/proj/epsg")
     return tmpdir
 
diff --git a/tests/test_data_paths.py b/tests/test_data_paths.py
index 1097fbf35..95d029fbc 100644
--- a/tests/test_data_paths.py
+++ b/tests/test_data_paths.py
@@ -4,7 +4,7 @@
 
 def test_gdal_data_find_file():
     """Find_file shouldn't raise any exceptions"""
-    GDALDataFinder().find_file("header.dxf")
+    GDALDataFinder().find_file("gdalvrt.xsd")
 
 
 def test_proj_data_has_data():
diff --git a/tests/test_env.py b/tests/test_env.py
index 7f681d4b5..474006d5b 100644
--- a/tests/test_env.py
+++ b/tests/test_env.py
@@ -129,7 +129,7 @@ def f():
 
     find_file.return_value = None
 
-    tmpdir.ensure("share/gdal/header.dxf")
+    tmpdir.ensure("share/gdal/gdalvrt.xsd")
     monkeypatch.delenv('GDAL_DATA', raising=False)
     monkeypatch.setattr(sys, 'prefix', str(tmpdir))
 
@@ -145,7 +145,7 @@ def f():
 
     find_file.return_value = None
 
-    tmpdir.ensure("gdal_data/header.dxf")
+    tmpdir.ensure("gdal_data/gdalvrt.xsd")
     monkeypatch.delenv('GDAL_DATA', raising=False)
     monkeypatch.setattr(_env, '__file__', str(tmpdir.join(os.path.basename(_env.__file__))))