File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,12 +28,24 @@ def maybe_get_from_cache(
2828 remote_file_path : epath .PathLike ,
2929 cache_subdir : str ,
3030) -> epath .Path :
31- """Returns the cached file if exists, otherwise returns the remote file path."""
32- filename = epath .Path (remote_file_path ).name
31+ """Returns the cached file if exists, otherwise downloads it and returns local path."""
32+ remote_path_str = str (remote_file_path )
33+ filename = epath .Path (remote_path_str ).name
3334
34- cache_filepath = _get_cache_dir () / cache_subdir / filename
35+ cache_dir = _get_cache_dir () / cache_subdir
36+ cache_filepath = cache_dir / filename
3537 if cache_filepath .exists ():
3638 return cache_filepath
39+
40+ if remote_path_str .startswith ('gs://' ):
41+ cache_dir .mkdir (parents = True , exist_ok = True )
42+ http_url = remote_path_str .replace ('gs://' , 'https://storage.googleapis.com/' )
43+ print (f"Downloading { filename } to { cache_filepath } ..." )
44+
45+ import urllib .request
46+ urllib .request .urlretrieve (http_url , str (cache_filepath ))
47+ return cache_filepath
48+
3749 return epath .Path (remote_file_path )
3850
3951
You can’t perform that action at this time.
0 commit comments