From 9ad92eeaaf7b6ff46860c0d716f636eea39f2f41 Mon Sep 17 00:00:00 2001 From: Sandor Kertesz Date: Wed, 18 Dec 2024 21:22:10 +0000 Subject: [PATCH] Simplify startup when using remote inventory --- src/earthkit/regrid/db.py | 23 +++++++++++++---------- tests/test_remote_index.py | 5 +++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/earthkit/regrid/db.py b/src/earthkit/regrid/db.py index 3aa4444..9d7a84d 100644 --- a/src/earthkit/regrid/db.py +++ b/src/earthkit/regrid/db.py @@ -462,15 +462,18 @@ def find( def find_entry(self, gridspec_in, gridspec_out, method): method = self._method_alias(method) entry = self.index.find(gridspec_in, gridspec_out, method) - if entry is None: - if not self._accessor.is_local() and not self._accessor.checked_remote(): - LOG.info( - f"Matrix not found in DB for {gridspec_in=} {gridspec_out=} {method=}" - ) - LOG.info("Try to fetch remote index file to check for updates") - self._accessor.reload() - self._load_index() - entry = self.index.find(gridspec_in, gridspec_out, method) + if ( + entry is None + and not self._accessor.is_local() + and not self._accessor.checked_remote() + ): + LOG.info( + f"Matrix not found in DB for {gridspec_in=} {gridspec_out=} {method=}" + ) + LOG.info("Try to fetch remote index file to check for updates") + self._accessor.reload() + self._load_index() + entry = self.index.find(gridspec_in, gridspec_out, method) return entry @@ -548,7 +551,7 @@ def find(*args, matrix_source=None, **kwargs): return db.find(*args, **kwargs) -def _clear_all(): +def _reset(): global DB_LIST global SYS_DB SYS_DB = MatrixDb(SystemAccessor()) diff --git a/tests/test_remote_index.py b/tests/test_remote_index.py index 953a9b7..ce05034 100644 --- a/tests/test_remote_index.py +++ b/tests/test_remote_index.py @@ -13,13 +13,14 @@ import pytest from earthkit.regrid import interpolate -from earthkit.regrid.db import _clear_all +from earthkit.regrid.db import _reset @pytest.mark.download @pytest.mark.tmp_cache def test_remote_index_handling(): - _clear_all() + # we need to reset the db to ensure to simulate a fresh start + _reset() from earthkit.regrid.db import SYS_DB