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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add a function to check if patch files contain outdated paths
  • Loading branch information
mirpedrol committed Oct 5, 2022
commit 22357fbc2be22d05b7893459cc9e89051c484b5a
27 changes: 26 additions & 1 deletion nf_core/modules/modules_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,36 @@ def check_modules_structure(self):
# Move wrong modules to the right directory
for module in wrong_location_modules:
modules_dir = Path("modules").resolve()
correct_dir = Path(modules_dir, self.modules_repo.repo_path, Path(*module.parts[2:]))
module_name = str(Path(*module.parts[2:]))
correct_dir = Path(modules_dir, self.modules_repo.repo_path, Path(module_name))
wrong_dir = Path(modules_dir, module)
shutil.move(wrong_dir, correct_dir)
log.info(f"Moved {wrong_dir} to {correct_dir}.")
# Check if a path file exists
patch_path = correct_dir / Path(module_name + ".diff")
self.check_patch_paths(patch_path, module_name)
shutil.rmtree(Path(self.dir, "modules", self.modules_repo.repo_path, "modules"))
# Regenerate modules.json file
modules_json = ModulesJson(self.dir)
modules_json.check_up_to_date()

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():
rewrite = False
with open(patch_path, "r") as fh:
lines = fh.readlines()
for line in 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
line.replace(
f"modules/{self.modules_repo.repo_path}/modules/{module_name}/",
f"modules/{self.modules_repo.repo_path}/{module_name}/",
)
if rewrite:
with open(patch_path, "w") as fh:
for line in lines:
fh.write(line)
2 changes: 1 addition & 1 deletion nf_core/modules/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def patch(self, module=None):
module_dir = [dir for dir, m in modules if m == module][0]
module_fullname = str(Path("modules", module_dir, module))

# Verify that the module has an entry is the modules.json file
# Verify that the module has an entry in the modules.json file
if not self.modules_json.module_present(module, self.modules_repo.remote_url, module_dir):
raise UserWarning(
f"The '{module_fullname}' module does not have an entry in the 'modules.json' file. Cannot compute patch"
Expand Down