From 2d7ab6914671758921484022010e1d1b2bea0b71 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Sun, 17 Jan 2021 14:28:27 +0100 Subject: [PATCH] ci_find*: include sub/parent dirs 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 --- planemo/ci.py | 46 +++++++++++++++++++++++++++++++++++++++------- planemo/options.py | 3 ++- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/planemo/ci.py b/planemo/ci.py index 1b947b331..fbfeccde0 100644 --- a/planemo/ci.py +++ b/planemo/ci.py @@ -3,6 +3,7 @@ from __future__ import print_function import copy +import glob import math import os @@ -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): @@ -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, ctx, cwd) unique_paths = set(os.path.relpath(p, cwd) for p in raw_paths) if diff_paths is not None: @@ -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: diff --git a/planemo/options.py b/planemo/options.py index 1221cc7d1..824cd49e1 100644 --- a/planemo/options.py +++ b/planemo/options.py @@ -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.", )