@@ -35,7 +35,18 @@ def _box_find_dataset_folder_id_direct(client, *, parent_folder_id: str, dataset
3535 f"Dataset '{ dataset_name } ' not found directly under Box folder { parent_folder_id } ."
3636 )
3737
38- def _box_mirror_folder (client , folder_id : str , out_dir : Path ) -> None :
38+ def _box_mirror_folder (client , folder_id : str , out_dir : Path , exclude_folders : list = None ) -> None :
39+ """Mirror a Box folder to local directory, optionally excluding specified folders.
40+
41+ Args:
42+ client: Box client instance
43+ folder_id: Box folder ID to mirror
44+ out_dir: Local output directory
45+ exclude_folders: List of folder names to skip (e.g., ["derivatives"])
46+ """
47+ if exclude_folders is None :
48+ exclude_folders = []
49+
3950 out_dir .mkdir (parents = True , exist_ok = True )
4051 def _walk (fid : str , local : Path ):
4152 local .mkdir (parents = True , exist_ok = True )
@@ -51,7 +62,9 @@ def _walk(fid: str, local: Path):
5162 with open (tgt , "wb" ) as fh :
5263 client .file (item .id ).download_to (fh )
5364 elif item .type == "folder" :
54- _walk (item .id , local / item .name )
65+ # Skip excluded folders
66+ if item .name not in exclude_folders :
67+ _walk (item .id , local / item .name )
5568 if count < limit :
5669 break
5770 offset += limit
@@ -80,7 +93,8 @@ def ensure_dataset_present(project_name: str, meg_data_root: Path) -> Path:
8093 client , parent_folder_id = parent_folder_id , dataset_name = project_name
8194 )
8295
83- _box_mirror_folder (client , dataset_folder_id , bids_root )
96+ # Exclude derivatives folder to ensure tests generate fresh outputs
97+ _box_mirror_folder (client , dataset_folder_id , bids_root , exclude_folders = ["derivatives" ])
8498 if not _has_local_dataset (bids_root ):
8599 raise AssertionError (f"Downloaded dataset appears empty at { bids_root } " )
86100 return bids_root
0 commit comments