@@ -560,37 +560,44 @@ def group_folders(
560
560
"""
561
561
with open (fpath_gitdiff ) as fopen :
562
562
changed = [ln .strip () for ln in fopen .readlines ()]
563
- dirs = [os .path .dirname (ln ) for ln in changed ]
564
-
565
- if fpath_actual_dirs :
566
- assert isinstance (fpath_actual_dirs , list )
567
- assert all (os .path .isfile (p ) for p in fpath_actual_dirs )
568
- dir_sets = [{ln .strip () for ln in open (fp ).readlines ()} for fp in fpath_actual_dirs ]
569
- # get only different
570
- dirs += list (set .union (* dir_sets ) - set .intersection (* dir_sets ))
571
- # not empty paths
572
- dirs = [ln for ln in dirs if ln ]
573
-
574
- # drop folder that start with . or _ as they are meant to be internal use only
575
- dirs = [pdir for pdir in dirs if not any (ndir [0 ] in ("." , "_" ) for ndir in pdir .split (os .path .sep ))]
563
+ dirs_changed = [os .path .dirname (ln ) for ln in changed ]
576
564
# append a path to root in case you call this from other path then root
577
565
if root_path :
578
- dirs = [os .path .join (root_path , d ) for d in dirs ]
566
+ dirs_changed = [os .path .join (root_path , d ) for d in dirs_changed ]
579
567
# append all subfolders in case of parent requirements has been changed all related notebooks shall be updated
580
- dirs_expanded = []
581
- for dir in dirs :
568
+ dirs = []
569
+ for dir in dirs_changed :
582
570
# in case that the diff item comes from removed folder
583
571
if not os .path .isdir (dir ):
584
- dirs_expanded += [dir ]
572
+ dirs += [dir ]
585
573
continue
586
574
# list folder and skip all internal files, starting with . or _
587
575
sub_dirs = [os .path .join (dir , it ) for it in os .listdir (dir ) if it [0 ] not in ("." , "_" )]
588
576
# filter only folders
589
577
sub_dirs = [it for it in sub_dirs if os .path .isdir (it )]
590
578
# if the dir has sub-folder append then otherwise append the dir itself
591
- dirs_expanded += sub_dirs if sub_dirs else [dir ]
579
+ dirs += sub_dirs if sub_dirs else [dir ]
580
+
581
+ if fpath_actual_dirs :
582
+ assert isinstance (fpath_actual_dirs , list )
583
+ assert all (os .path .isfile (p ) for p in fpath_actual_dirs )
584
+ dir_sets = [{ln .strip () for ln in open (fp ).readlines ()} for fp in fpath_actual_dirs ]
585
+ # get only different
586
+ dirs_diff = list (set .union (* dir_sets ) - set .intersection (* dir_sets ))
587
+ # append a path to root in case you call this from other path then root
588
+ if root_path :
589
+ dirs_diff = [os .path .join (root_path , d ) for d in dirs_diff ]
590
+ dirs += dirs_diff
591
+
592
+ # not empty paths
593
+ dirs = [ln for ln in dirs if ln ]
594
+ # drop folder that start with . or _ as they are meant to be internal use only
595
+ # when walk the folder skip empty names which is artifact of absolute path starting with /
596
+ dirs = [
597
+ pdir for pdir in dirs if not any (folder [0 ] in ("." , "_" ) for folder in pdir .split (os .path .sep ) if folder )
598
+ ]
592
599
# unique folders only, drop duplicates
593
- dirs = set (dirs_expanded )
600
+ dirs = set (dirs )
594
601
# valid folder has meta
595
602
dirs_exist = [d for d in dirs if os .path .isdir (d )]
596
603
dirs_invalid = [d for d in dirs_exist if not AssistantCLI ._find_meta (d )]
@@ -602,13 +609,13 @@ def group_folders(
602
609
if dirs_invalid :
603
610
raise FileNotFoundError (f"{ msg } nor sub-folder: \n { os .linesep .join (dirs_invalid )} " )
604
611
605
- dirs_change = [d for d in dirs_exist if AssistantCLI ._find_meta (d )]
612
+ dirs_with_change = [d for d in dirs_exist if AssistantCLI ._find_meta (d )]
606
613
with open (fpath_change_folders , "w" ) as fopen :
607
- fopen .write (os .linesep .join (sorted (dirs_change )))
614
+ fopen .write (os .linesep .join (sorted (dirs_with_change )))
608
615
609
- dirs_drop = [d for d in dirs if not os .path .isdir (d )]
616
+ dirs_were_dropped = [d for d in dirs if not os .path .isdir (d )]
610
617
with open (fpath_drop_folders , "w" ) as fopen :
611
- fopen .write (os .linesep .join (sorted (dirs_drop )))
618
+ fopen .write (os .linesep .join (sorted (dirs_were_dropped )))
612
619
613
620
@staticmethod
614
621
def generate_matrix (fpath_change_folders : str , json_indent : Optional [int ] = None ) -> str :
0 commit comments