From 3b4bad9e2ef1802c719ebc8098eb95422c48e15e Mon Sep 17 00:00:00 2001 From: Sandor Kertesz Date: Wed, 16 Oct 2024 09:31:21 +0100 Subject: [PATCH 1/3] Do not import ecmwf-api-client for standalone MARS access --- docs/release_notes/version_0.10_updates.rst | 10 ++++++++++ src/earthkit/data/sources/mars.py | 10 +++++----- 2 files changed, 15 insertions(+), 5 deletions(-) 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..a84e7529 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 @@ -56,6 +51,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() From d85058612d35b6899f79e230b966f1f597c446ac Mon Sep 17 00:00:00 2001 From: Sandor Kertesz Date: Wed, 16 Oct 2024 09:54:46 +0100 Subject: [PATCH 2/3] Do not import ecmwf-api-client for standalone MARS access --- src/earthkit/data/sources/mars.py | 6 ++++++ src/earthkit/data/testing.py | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/earthkit/data/sources/mars.py b/src/earthkit/data/sources/mars.py index a84e7529..5a57cf2f 100644 --- a/src/earthkit/data/sources/mars.py +++ b/src/earthkit/data/sources/mars.py @@ -44,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): diff --git a/src/earthkit/data/testing.py b/src/earthkit/data/testing.py index 4068b6d1..f0ced514 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 (NO_MARS_DIRECT and 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 From eda06eb2d8136546409c03c17374c9b5fff4fcbd Mon Sep 17 00:00:00 2001 From: Sandor Kertesz Date: Wed, 16 Oct 2024 10:02:22 +0100 Subject: [PATCH 3/3] Do not import ecmwf-api-client for standalone MARS access --- src/earthkit/data/testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/earthkit/data/testing.py b/src/earthkit/data/testing.py index f0ced514..b6aaf999 100644 --- a/src/earthkit/data/testing.py +++ b/src/earthkit/data/testing.py @@ -92,7 +92,7 @@ def modules_installed(*modules): NO_MARS_DIRECT = not StandaloneMarsClient.enabled() -NO_MARS_API = not (NO_MARS_DIRECT and os.path.exists(os.path.expanduser("~/.ecmwfapirc"))) +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"))