-
Notifications
You must be signed in to change notification settings - Fork 191
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
Conversation
Codecov Report
@@ 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
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Co-authored-by: Phil Ewels <phil.ewels@scilifelab.se>
There was a problem hiding this 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.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Closes #1868
The new function runs in every
nf-core modules
command, when we check if themodules
directory structure is outdated and try to fix it.It updates paths from patch files.
PR checklist
CHANGELOG.md
is updateddocs
is updated