Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a function to check if patch files contain outdated paths #1878

Merged
merged 7 commits into from
Oct 12, 2022

Conversation

mirpedrol
Copy link
Member

@mirpedrol mirpedrol commented Oct 5, 2022

Closes #1868

The new function runs in every nf-core modules command, when we check if the modules directory structure is outdated and try to fix it.
It updates paths from patch files.

PR checklist

  • This comment contains a description of changes (with reason)
  • CHANGELOG.md is updated
  • If you've fixed a bug or added code that should be tested, add tests!
  • Documentation in docs is updated

@codecov
Copy link

codecov bot commented Oct 5, 2022

Codecov Report

Merging #1878 (2bfed71) into dev (5be0720) will decrease coverage by 0.10%.
The diff coverage is 37.50%.

@@            Coverage Diff             @@
##              dev    #1878      +/-   ##
==========================================
- Coverage   60.06%   59.96%   -0.11%     
==========================================
  Files          37       37              
  Lines        4640     4663      +23     
==========================================
+ Hits         2787     2796       +9     
- Misses       1853     1867      +14     
Impacted Files Coverage Δ
nf_core/modules/modules_command.py 67.76% <37.50%> (-6.73%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

nf_core/modules/update.py Outdated Show resolved Hide resolved
mirpedrol and others added 2 commits October 5, 2022 17:12
Co-authored-by: Phil Ewels <phil.ewels@scilifelab.se>
Copy link
Contributor

@adamrtalbot adamrtalbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very familiar with the code but I'm pretty sure that addresses the issue I was seeing.

Comment on lines +192 to +221
def check_patch_paths(self, patch_path, module_name):
"""
Check that paths in patch files are updated to the new modules path
"""
if patch_path.exists():
log.info(f"Modules {module_name} contains a patch file.")
rewrite = False
with open(patch_path, "r") as fh:
lines = fh.readlines()
for index, line in enumerate(lines):
# Check if there are old paths in the patch file and replace
if f"modules/{self.modules_repo.repo_path}/modules/{module_name}/" in line:
rewrite = True
lines[index] = line.replace(
f"modules/{self.modules_repo.repo_path}/modules/{module_name}/",
f"modules/{self.modules_repo.repo_path}/{module_name}/",
)
if rewrite:
log.info(f"Updating paths in {patch_path}")
with open(patch_path, "w") as fh:
for line in lines:
fh.write(line)
# Update path in modules.json if the file is in the correct format
modules_json = ModulesJson(self.dir)
modules_json.load()
if modules_json.has_git_url_and_modules():
modules_json.modules_json["repos"][self.modules_repo.remote_url]["modules"][
self.modules_repo.repo_path
][module_name]["patch"] = str(patch_path.relative_to(Path(self.dir).resolve()))
modules_json.dump()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@mirpedrol mirpedrol merged commit d0901f7 into nf-core:dev Oct 12, 2022
@mirpedrol mirpedrol deleted the patch branch October 12, 2022 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants