Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = changed_tools(diff_files, ctx, cwd)

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, ctx, cwd):
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