From ad21f6d640febd2179feb4f7f0bc7c483b9c5ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85dne=20Jacobsen?= <88316787+adnejacobsen@users.noreply.github.com> Date: Thu, 31 Aug 2023 13:35:06 +0200 Subject: [PATCH] Handle missing OpenVDS, add warnings (#200) --- README.md | 2 ++ docs/explorer.rst | 4 ++++ src/fmu/sumo/explorer/objects/cube.py | 19 +++++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 26a4e880..5aba5588 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ This package is intended for interaction with Sumo within the FMU (Fast Model Up ## Explorer +> :warning: OpenVDS does not publish builds for MacOS. You can still use the Explorer without OpenVDS, but some Cube methods will not work. + Explore and retrieve data from Sumo. ```python diff --git a/docs/explorer.rst b/docs/explorer.rst index b981a268..301a5005 100644 --- a/docs/explorer.rst +++ b/docs/explorer.rst @@ -9,6 +9,10 @@ Api Reference - `API reference `_ +.. warning:: + OpenVDS does not publish builds for MacOS. You can still use the Explorer without OpenVDS, + but some Cube methods will not work. + Usage and examples ------------------ diff --git a/src/fmu/sumo/explorer/objects/cube.py b/src/fmu/sumo/explorer/objects/cube.py index fd473d06..77d1a7c7 100644 --- a/src/fmu/sumo/explorer/objects/cube.py +++ b/src/fmu/sumo/explorer/objects/cube.py @@ -1,9 +1,18 @@ """Module containing class for cube object""" import json -import openvds from typing import Dict from sumo.wrapper import SumoClient from fmu.sumo.explorer.objects._child import Child +import sys +import warnings + +if sys.platform == "darwin": + try: + import openvds + except ImportError: + warnings.warn("OpenVDS is missing. Some Cube methods will not work.") +else: + import openvds class Cube(Child): @@ -29,7 +38,9 @@ def _populate_url(self): self._url = res.decode("UTF-8") async def _populate_url_async(self): - res = await self._sumo.get_async(f"/objects('{self.uuid}')/blob/authuri") + res = await self._sumo.get_async( + f"/objects('{self.uuid}')/blob/authuri" + ) try: res = json.loads(res.decode("UTF-8")) self._url = res.get("baseuri") + self.uuid @@ -74,7 +85,7 @@ async def sas_async(self) -> str: return self._sas @property - def openvds_handle(self) -> openvds.core.VDS: + def openvds_handle(self): if self._url is None: self._populate_url() @@ -86,7 +97,7 @@ def openvds_handle(self) -> openvds.core.VDS: return openvds.open(url, sas) @property - async def openvds_handle_async(self) -> openvds.core.VDS: + async def openvds_handle_async(self): if self._url is None: await self._populate_url_async()