-
Notifications
You must be signed in to change notification settings - Fork 187
/
module_changes.py
70 lines (63 loc) · 2.44 KB
/
module_changes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Check whether the content of a module has changed compared to the original repository
"""
import shutil
import tempfile
from pathlib import Path
import nf_core.modules.modules_repo
from nf_core.modules.modules_differ import ModulesDiffer
def module_changes(module_lint_object, module):
"""
Checks whether installed nf-core modules have changed compared to the
original repository
Downloads the ``main.nf`` and ``meta.yml`` files for every module
and compares them to the local copies
If the module has a commit SHA entry in the ``modules.json``, the file content is
compared against the files in the remote at this SHA.
Only runs when linting a pipeline, not the modules repository
"""
if module.is_patched:
# If the module is patched, we need to apply
# the patch in reverse before comparing with the remote
tempdir_parent = Path(tempfile.mkdtemp())
tempdir = tempdir_parent / "tmp_module_dir"
shutil.copytree(module.component_dir, tempdir)
try:
new_lines = ModulesDiffer.try_apply_patch(
module.component_name,
module.org,
module.patch_path,
tempdir,
reverse=True,
)
for file, lines in new_lines.items():
with open(tempdir / file, "w") as fh:
fh.writelines(lines)
except LookupError:
# This error is already reported by module_patch, so just return
return
else:
tempdir = module.component_dir
module.branch = module_lint_object.modules_json.get_component_branch(
"modules", module.component_name, module.repo_url, module.org
)
modules_repo = nf_core.modules.modules_repo.ModulesRepo(remote_url=module.repo_url, branch=module.branch)
for f, same in modules_repo.component_files_identical(
module.component_name, tempdir, module.git_sha, "modules"
).items():
if same:
module.passed.append(
(
"check_local_copy",
"Local copy of module up to date",
f"{Path(module.component_dir, f)}",
)
)
else:
module.failed.append(
(
"check_local_copy",
"Local copy of module does not match remote",
f"{Path(module.component_dir, f)}",
)
)