Skip to content

Commit 2e18eb1

Browse files
committed
add new method to show that a file was found
1 parent 8fd441c commit 2e18eb1

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

src/herbie/v2/_base.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,27 @@ def xarray(
666666

667667
return ds
668668

669+
def found(self) -> dict[str, tuple]:
670+
"""
671+
Resolve and return the first available GRIB source and index file.
672+
673+
Unlike ``status()``, which fires parallel HEAD requests to *every*
674+
source, ``found()`` walks sources in priority order and stops at the
675+
first hit — exactly the same logic used by ``inventory()``,
676+
``download()``, and ``xarray()``. Call it to confirm which source
677+
will actually be used before doing any real work.
678+
679+
Results are cached, so repeated calls are free.
680+
"""
681+
# Trigger lazy resolution (cached after the first call)
682+
grib_src, grib_url = self._found_grib
683+
idx_src, idx_url = self._found_index
684+
685+
return {
686+
"grib": self._found_grib,
687+
"index": self._found_index,
688+
}
689+
669690
def status(self) -> None:
670691
"""
671692
Check and display the availability of all sources and local files.
@@ -972,11 +993,11 @@ def _repr_html_(self) -> str:
972993
<b>Valid:</b> {self.valid_date:%Y-%b-%d %H:%M UTC}
973994
</p>
974995
<details style="margin-top:8px">
975-
<summary style="cursor:pointer;font-weight:bold">Parameters</summary>
996+
<summary style="cursor:pointer;font-weight:bold"> Parameters</summary>
976997
<table style="border-collapse:collapse;margin-top:4px">{params_html}</table>
977998
</details>
978999
<details style="margin-top:4px" open>
979-
<summary style="cursor:pointer;font-weight:bold">Sources</summary>
1000+
<summary style="cursor:pointer;font-weight:bold"> Sources</summary>
9801001
<p style="margin:6px 0 4px 0">
9811002
<b>Resolved:</b> {resolved_badge} &nbsp;&nbsp;
9821003
<b>Local:</b> <code style="font-size:0.85em">{self.local_path}</code>

0 commit comments

Comments
 (0)