From 01c89608c9ea06facde4700f2a78009b4ac9c217 Mon Sep 17 00:00:00 2001 From: Theo Satabin Date: Tue, 1 Oct 2024 16:53:14 +0200 Subject: [PATCH] =?UTF-8?q?GDAL=20optionnel=20pour=20utiliser=20la=20parti?= =?UTF-8?q?e=20de=20la=20librairie=20storage=20non=20concern=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ src/rok4/storage.py | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29c38f0..2ce1ef7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.2.1 + +### [Changed] + +* Module `storage` : il est possible de l'utiliser sans avoir la librairie GDAL : seule la fonction `get_osgeo_path` pour du S3 ne sera pas disponible + ## 2.2.0 ### [Added] diff --git a/src/rok4/storage.py b/src/rok4/storage.py index 66bd295..85e83a4 100644 --- a/src/rok4/storage.py +++ b/src/rok4/storage.py @@ -52,9 +52,23 @@ import boto3 import botocore.exceptions import requests + from osgeo import gdal # conditional import + +try: + from osgeo import gdal + + # Enable GDAL/OGR exceptions + gdal.UseExceptions() + + GDAL_AVAILABLE: bool = True +except ImportError: + GDAL_AVAILABLE: bool = False + gdal = None + + try: import rados @@ -69,8 +83,6 @@ # -- GLOBALS -- -# Enable GDAL/OGR exceptions -gdal.UseExceptions() __CEPH_CLIENT = None __CEPH_IOCTXS = {} @@ -1071,7 +1083,7 @@ def get_osgeo_path(path: str) -> str: storage_type, unprefixed_path, tray_name, base_name = get_infos_from_path(path) - if storage_type == StorageType.S3: + if storage_type == StorageType.S3 and GDAL_AVAILABLE: s3_client, bucket_name = __get_s3_client(tray_name) gdal.SetConfigOption("AWS_SECRET_ACCESS_KEY", s3_client["secret_key"])