Downloads prepared GCS folder to local folder.
(
gcs_folder: epath.Path,
local_folder: epath.PathLike,
max_simultaneous_downloads: int = 25,
)
| 110 | |
| 111 | |
| 112 | def download_gcs_folder( |
| 113 | gcs_folder: epath.Path, |
| 114 | local_folder: epath.PathLike, |
| 115 | max_simultaneous_downloads: int = 25, |
| 116 | ) -> None: |
| 117 | """Downloads prepared GCS folder to local folder.""" |
| 118 | if _is_gcs_disabled: |
| 119 | raise AssertionError('Cannot download from GCS when _is_gcs_disabled') |
| 120 | |
| 121 | # Filter out the diffs folder if present |
| 122 | paths_to_dl = [p for p in gcs_folder.iterdir() if p.name != 'diffs'] |
| 123 | |
| 124 | with tqdm_utils.async_tqdm( |
| 125 | total=len(paths_to_dl), desc='Dl Completed...', unit=' file' |
| 126 | ) as pbar: |
| 127 | |
| 128 | def _copy(gcs_path_: epath.Path): |
| 129 | # Copy 'gs://tfds-data/datasets/ds/1.0.0/file' -> `local_dir/file` |
| 130 | gcs_path_.copy(dst=os.path.join(local_folder, gcs_path_.name)) |
| 131 | pbar.update(1) |
| 132 | |
| 133 | with concurrent.futures.ThreadPoolExecutor( |
| 134 | max_workers=max_simultaneous_downloads |
| 135 | ) as executor: |
| 136 | futures = [executor.submit(_copy, path) for path in paths_to_dl] |
| 137 | for future in concurrent.futures.as_completed(futures): |
| 138 | future.result() |
| 139 | |
| 140 | |
| 141 | def download_gcs_dataset( |
no test coverage detected