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

Update catalog store public status during validation #24

Merged
merged 2 commits into from
Apr 23, 2024
Merged
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
15 changes: 15 additions & 0 deletions leap_data_management_utils/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pydantic
import pydantic_core
import upath
import xarray as xr
import yaml


Expand All @@ -13,6 +14,7 @@ class Store(pydantic.BaseModel):
name: str = pydantic.Field(None, description='Name of the store')
url: str = pydantic.Field(..., description='URL of the store')
rechunking: list[dict[str, str]] | None = pydantic.Field(None, alias='ncviewjs:rechunking')
public: bool | None = pydantic.Field(None, description='Whether the store is public')


class Link(pydantic.BaseModel):
Expand Down Expand Up @@ -118,6 +120,10 @@ def validate_feedstocks(*, feedstocks: list[upath.UPath]) -> list[Feedstock]:
for feedstock in feedstocks:
try:
feed = Feedstock.from_yaml(convert_to_raw_github_url(feedstock))
print('🔄 Checking stores')
for index, store in enumerate(feed.stores):
print(f' 🚦 {store.id} ({index + 1}/{len(feed.stores)})')
feed.stores[index].public = is_store_public(store.url)
valid.append({'feedstock': str(feedstock), 'status': 'valid'})
catalog.append(feed)
except Exception:
Expand All @@ -136,6 +142,15 @@ def validate_feedstocks(*, feedstocks: list[upath.UPath]) -> list[Feedstock]:
return catalog


def is_store_public(store) -> bool:
try:
xr.open_dataset(store, engine='zarr', chunks={})
return True
except Exception:
print(f'Store {store} is not public')
return False


def validate(args):
if args.single:
# If single file path is provided, validate just this one feedstock
Expand Down