Skip to content

Commit

Permalink
Merge pull request #2771 from mirpedrol/extra-module-file
Browse files Browse the repository at this point in the history
Modules: patch: handle file not found when it is an added file to a module
  • Loading branch information
mirpedrol authored Feb 19, 2024
2 parents cc99981 + a24a733 commit fa9ca91
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
### Modules

- Handle dirty local module repos by force checkout of commits and branches if needed ([#2734](https://github.com/nf-core/tools/pull/2734))
- Patch: handle file not found when it is an added file to a module ([#2771](https://github.com/nf-core/tools/pull/2771))
- Handle symlinks when migrating pytest ([#2770](https://github.com/nf-core/tools/pull/2770))
- Add `--profile` parameter to nf-test command ([#2767](https://github.com/nf-core/tools/pull/2767))

Expand Down
8 changes: 6 additions & 2 deletions nf_core/modules/modules_differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,12 @@ def try_apply_patch(module, repo_path, patch_path, module_dir, reverse=False):
log.debug(f"Applying patch to {file}")
fn = Path(file).relative_to(module_relpath)
file_path = module_dir / fn
with open(file_path) as fh:
file_lines = fh.readlines()
try:
with open(file_path) as fh:
file_lines = fh.readlines()
except FileNotFoundError:
# The file was added with the patch
file_lines = [""]
patched_new_lines = ModulesDiffer.try_apply_single_patch(file_lines, patch, reverse=reverse)
new_files[str(fn)] = patched_new_lines
return new_files

0 comments on commit fa9ca91

Please sign in to comment.