Skip to content

Commit

Permalink
ci_find*: include some sub/parent dirs
Browse files Browse the repository at this point in the history
include also tools/repos with:

- change of test data
- change of supplementary scripts
  (this already was the case for ci_find_repos)
- change of macros where the tools are in sub-directories
  (this failed for ci_find_repos if each tool has an
   individual shed file)
- change of a single tool in a collection where the shed
  file is in the parent
  • Loading branch information
bernt-matthias committed Jan 17, 2021
1 parent bea6a16 commit 44d0c6a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
46 changes: 39 additions & 7 deletions planemo/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import print_function

import copy
import glob
import math
import os

Expand All @@ -11,6 +12,10 @@
from planemo import git
from planemo import io
from planemo.shed import REPO_METADATA_FILES
from planemo.tools import (
is_tool_load_error,
yield_tool_sources_on_paths
)


def filter_paths(ctx, raw_paths, path_type="repo", **kwds):
Expand All @@ -26,14 +31,9 @@ def filter_paths(ctx, raw_paths, path_type="repo", **kwds):
if changed_in_commit_range is not None:
diff_files = git.diff(ctx, cwd, changed_in_commit_range)
if path_type == "repo":
diff_dirs = set(os.path.dirname(p) for p in diff_files)
diff_paths = set()
for diff_dir in diff_dirs:
diff_path = metadata_file_in_path(diff_dir)
if diff_path:
diff_paths.add(diff_path)
diff_paths = changed_repos(diff_files)
else:
diff_paths = diff_files
diff_paths = changes_tools(diff_files)

unique_paths = set(os.path.relpath(p, cwd) for p in raw_paths)
if diff_paths is not None:
Expand All @@ -55,6 +55,38 @@ def filter_paths(ctx, raw_paths, path_type="repo", **kwds):
return chunked_paths


def changed_repos(diff_files):
diff_dirs = set(os.path.dirname(p) for p in diff_files)
diff_paths = set()
for diff_dir in diff_dirs:
new_diff_paths = set()
while diff_dir != "" and len(new_diff_paths) == 0:
for sub_dir in glob.glob(diff_dir + "/**/", recursive=True):
diff_path = metadata_file_in_path(sub_dir)
if diff_path:
new_diff_paths.add(diff_path)
diff_dir = os.path.split(diff_dir)[0]
diff_paths |= new_diff_paths
return diff_paths


def changed_tools(diff_files):
diff_paths = set()
for diff_file in diff_files:
diff_dir = os.path.dirname(diff_file)
# search for tool files in each non-root parent*
new_diff_paths = set()
while diff_dir != '' and len(new_diff_paths) == 0:
for (tool_path, tool_source) in yield_tool_sources_on_paths(ctx, [diff_dir], recursive=True):
if is_tool_load_error(tool_source):
continue
new_diff_paths.add(tool_path)
diff_dir = os.path.split(diff_dir)[0]
diff_paths |= new_diff_paths
diff_paths = set(os.path.relpath(p, cwd) for p in diff_paths)
return diff_paths


def metadata_file_in_path(diff_dir):
while diff_dir:
for metadata_file in REPO_METADATA_FILES:
Expand Down
3 changes: 2 additions & 1 deletion planemo/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,8 @@ def filter_exclude_from_option():
def filter_changed_in_commit_option():
return planemo_option(
"--changed_in_commit_range",
help="Exclude paths unchanged in git commit range.",
help="Include only tools (resp. repositories) contained in (non-root)"
"directories that include a file that changed in the given commit range.",
)


Expand Down

0 comments on commit 44d0c6a

Please sign in to comment.