Skip to content

Commit

Permalink
copy all files when reverting a patch
Browse files Browse the repository at this point in the history
  • Loading branch information
mashehu committed Mar 12, 2024
1 parent d4e5243 commit 80748f3
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions nf_core/modules/modules_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,9 @@ def get_patch_fn(self, module_name, repo_url, install_dir):
)
return Path(path) if path is not None else None

def try_apply_patch_reverse(self, module, repo_name, patch_relpath, module_dir):
def try_apply_patch_reverse(
self, module: str, repo_name: str, patch_relpath: Union[Path, str], module_dir: Union[Path, str]
) -> Path:
"""
Try reverse applying a patch file to the modified module files
Expand All @@ -822,17 +824,30 @@ def try_apply_patch_reverse(self, module, repo_name, patch_relpath, module_dir):
new_files = ModulesDiffer.try_apply_patch(module, repo_name, patch_path, module_dir, reverse=True)
except LookupError as e:
raise LookupError(f"Failed to apply patch in reverse for module '{module_fullname}' due to: {e}")

# Write the patched files to a temporary directory
log.debug("Writing patched files to tmpdir")
# get all files of the module

module_files = list(Path(module_dir).rglob("*"))
# exclude the patch file
log.info(f"Excluding patch file '{patch_path}' from the patched files")
unpatched_module_files = [f for f in module_files if f != patch_path]
# Write the patched files and rest of the files to a temporary directory
log.info("Writing patched files to tmpdir")
temp_dir = Path(tempfile.mkdtemp())
temp_module_dir = temp_dir / module
temp_module_dir.mkdir(parents=True, exist_ok=True)

for file, new_content in new_files.items():
fn = temp_module_dir / file
with open(fn, "w") as fh:
fh.writelines(new_content)

# copy old files to the temp dir
for file in unpatched_module_files:
if file.is_file():
shutil.copy(file, temp_module_dir / file.relative_to(module_dir))
else:
shutil.copytree(file, temp_module_dir / file.relative_to(module_dir))

return temp_module_dir

def repo_present(self, repo_name):
Expand Down

0 comments on commit 80748f3

Please sign in to comment.