Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/planemo/ci.py @ 5:9b1c78e6ba9c draft default tip
"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author | shellac |
---|---|
date | Mon, 01 Jun 2020 08:59:25 -0400 |
parents | 79f47841a781 |
children |
comparison
equal
deleted
inserted
replaced
4:79f47841a781 | 5:9b1c78e6ba9c |
---|---|
1 """Utilities for dealing with continous integration systems.""" | |
2 | |
3 from __future__ import print_function | |
4 | |
5 import copy | |
6 import math | |
7 import os | |
8 | |
9 import yaml | |
10 | |
11 from planemo import git | |
12 from planemo import io | |
13 from planemo.shed import SHED_CONFIG_NAME | |
14 | |
15 | |
16 def filter_paths(ctx, raw_paths, path_type="repo", **kwds): | |
17 """Filter ``paths``. | |
18 | |
19 ``path_type`` is ``repo`` or ``file``. | |
20 """ | |
21 cwd = os.getcwd() | |
22 | |
23 filter_kwds = copy.deepcopy(kwds) | |
24 changed_in_commit_range = kwds.get("changed_in_commit_range", None) | |
25 diff_paths = None | |
26 if changed_in_commit_range is not None: | |
27 diff_files = git.diff(ctx, cwd, changed_in_commit_range) | |
28 if path_type == "repo": | |
29 diff_dirs = set(os.path.dirname(p) for p in diff_files) | |
30 diff_paths = set() | |
31 for diff_dir in diff_dirs: | |
32 while diff_dir: | |
33 if os.path.isfile(os.path.join(diff_dir, SHED_CONFIG_NAME)): | |
34 diff_paths.add(diff_dir) | |
35 break | |
36 diff_dir = os.path.dirname(diff_dir) | |
37 else: | |
38 diff_paths = diff_files | |
39 | |
40 unique_paths = set(os.path.relpath(p, cwd) for p in raw_paths) | |
41 if diff_paths is not None: | |
42 new_unique_paths = [] | |
43 for path in unique_paths: | |
44 if path in diff_paths: | |
45 new_unique_paths.append(path) | |
46 unique_paths = new_unique_paths | |
47 filtered_paths = sorted(io.filter_paths(unique_paths, cwd=cwd, **filter_kwds)) | |
48 excluded_paths = sorted(set(unique_paths) - set(filtered_paths)) | |
49 if excluded_paths: | |
50 ctx.log("List of excluded paths: %s" % excluded_paths) | |
51 | |
52 path_count = len(filtered_paths) | |
53 chunk_size = ((1.0 * path_count) / kwds["chunk_count"]) | |
54 chunk = kwds["chunk"] | |
55 | |
56 chunked_paths = [] | |
57 for i, path in enumerate(filtered_paths): | |
58 if int(math.floor(i / chunk_size)) == chunk: | |
59 chunked_paths.append(path) | |
60 | |
61 return chunked_paths | |
62 | |
63 | |
64 def print_path_list(paths, **kwds): | |
65 with io.open_file_or_standard_output(kwds["output"], "w") as f: | |
66 for path in paths: | |
67 print(path, file=f) | |
68 | |
69 | |
70 def print_as_yaml(item, **kwds): | |
71 with io.open_file_or_standard_output(kwds["output"], "w") as f: | |
72 f.write(yaml.safe_dump(item)) |