Skip to content

Commit f41e572

Browse files
author
Azure Pipelines
committed
Merge remote-tracking branch 'origin/main' into publication
2 parents b56646e + d499638 commit f41e572

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

.actions/assistant.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -560,37 +560,44 @@ def group_folders(
560560
"""
561561
with open(fpath_gitdiff) as fopen:
562562
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]
576564
# append a path to root in case you call this from other path then root
577565
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]
579567
# 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:
582570
# in case that the diff item comes from removed folder
583571
if not os.path.isdir(dir):
584-
dirs_expanded += [dir]
572+
dirs += [dir]
585573
continue
586574
# list folder and skip all internal files, starting with . or _
587575
sub_dirs = [os.path.join(dir, it) for it in os.listdir(dir) if it[0] not in (".", "_")]
588576
# filter only folders
589577
sub_dirs = [it for it in sub_dirs if os.path.isdir(it)]
590578
# 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+
]
592599
# unique folders only, drop duplicates
593-
dirs = set(dirs_expanded)
600+
dirs = set(dirs)
594601
# valid folder has meta
595602
dirs_exist = [d for d in dirs if os.path.isdir(d)]
596603
dirs_invalid = [d for d in dirs_exist if not AssistantCLI._find_meta(d)]
@@ -602,13 +609,13 @@ def group_folders(
602609
if dirs_invalid:
603610
raise FileNotFoundError(f"{msg} nor sub-folder: \n {os.linesep.join(dirs_invalid)}")
604611

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)]
606613
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)))
608615

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)]
610617
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)))
612619

613620
@staticmethod
614621
def generate_matrix(fpath_change_folders: str, json_indent: Optional[int] = None) -> str:

0 commit comments

Comments
 (0)