Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not import ecmwf-api-client for standalone MARS access #489

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/release_notes/version_0.10_updates.rst
Original file line number Diff line number Diff line change
@@ -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
===============

Expand Down
16 changes: 11 additions & 5 deletions src/earthkit/data/sources/mars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -49,13 +44,24 @@ 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):
if SETTINGS.get("use-standalone-mars-client-when-available"):
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()
Expand Down
6 changes: 5 additions & 1 deletion src/earthkit/data/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down
Loading