diff --git a/docs/release_notes/version_0.10_updates.rst b/docs/release_notes/version_0.10_updates.rst index d085b94f..3ce52377 100644 --- a/docs/release_notes/version_0.10_updates.rst +++ b/docs/release_notes/version_0.10_updates.rst @@ -1,6 +1,16 @@ Version 0.10 Updates ///////////////////////// + +Version 0.10.8 +=============== + +Fixes +++++++ + +- Fixed issue when tried to import "ecmwf-api-client" unnecessarily when the standalone MARS client was invoked for retrieving data from MARS. + + Version 0.10.7 =============== diff --git a/src/earthkit/data/sources/mars.py b/src/earthkit/data/sources/mars.py index 5940aeab..5a57cf2f 100644 --- a/src/earthkit/data/sources/mars.py +++ b/src/earthkit/data/sources/mars.py @@ -11,11 +11,6 @@ import os import subprocess -try: - import ecmwfapi -except ImportError: - raise ImportError("MARS access requires 'ecmwf-api-client' to be installed") - from earthkit.data.core.settings import SETTINGS from earthkit.data.core.temporary import temp_file @@ -49,6 +44,12 @@ def execute(self, request, target): check=True, ) + @staticmethod + def enabled(): + if SETTINGS.get("use-standalone-mars-client-when-available"): + return os.path.exists(StandaloneMarsClient.EXE) + return False + class MarsRetriever(ECMWFApi): def service(self): @@ -56,6 +57,11 @@ def service(self): if os.path.exists(StandaloneMarsClient.EXE): return StandaloneMarsClient() + try: + import ecmwfapi + except ImportError: + raise ImportError("MARS access requires 'ecmwf-api-client' to be installed") + if self.prompt: prompt = MARSAPIKeyPrompt() prompt.check() diff --git a/src/earthkit/data/testing.py b/src/earthkit/data/testing.py index 4068b6d1..b6aaf999 100644 --- a/src/earthkit/data/testing.py +++ b/src/earthkit/data/testing.py @@ -18,6 +18,7 @@ from earthkit.data import from_source from earthkit.data.readers.text import TextReader from earthkit.data.sources.empty import EmptySource +from earthkit.data.sources.mars import StandaloneMarsClient LOG = logging.getLogger(__name__) @@ -90,7 +91,10 @@ def modules_installed(*modules): return True -NO_MARS = not os.path.exists(os.path.expanduser("~/.ecmwfapirc")) +NO_MARS_DIRECT = not StandaloneMarsClient.enabled() +NO_MARS_API = not os.path.exists(os.path.expanduser("~/.ecmwfapirc")) +NO_MARS = NO_MARS_API and NO_MARS_DIRECT + NO_CDS = not os.path.exists(os.path.expanduser("~/.cdsapirc")) NO_HDA = not os.path.exists(os.path.expanduser("~/.hdarc")) IN_GITHUB = os.environ.get("GITHUB_WORKFLOW") is not None