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

Updated nf-core modules remove to remove entry in modules.json #1132

Merged
merged 4 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Use Biocontainers API instead of quayi.io API for `nf-core modules create` [[#875](https://github.com/nf-core/tools/issues/875)]
* Update `nf-core modules install` to handle different versions of modules [#1116](https://github.com/nf-core/tools/pull/1116)
* Refactored `nf-core modules` command into one file per command [#1124](https://github.com/nf-core/tools/pull/1124)
* Updated `nf-core modules remove` to also remove entry in `modules.json` file ([#1115](https://github.com/nf-core/tools/issues/1115))

#### Sync

Expand Down
24 changes: 23 additions & 1 deletion nf_core/modules/remove.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import json
import questionary
import logging

Expand Down Expand Up @@ -43,7 +44,6 @@ def remove(self, module):

# Set the install folder based on the repository name
install_folder = ["nf-core", "software"]
print(self.modules_repo.name)
if not self.modules_repo.name == "nf-core/modules":
install_folder = ["external"]

Expand All @@ -58,5 +58,27 @@ def remove(self, module):

log.info("Removing {}".format(module))

# Remove entry from modules.json
if not self.remove_modules_json_entry(module):
return False
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the other command, I would rather print that the module entry couldn't be found in the modules.json and not prompt for it.


# Remove the module
return self.clear_module_dir(module_name=module, module_dir=module_dir)

def remove_modules_json_entry(self, module):
# Load 'modules.json'
modules_json_path = os.path.join(self.dir, "modules.json")
with open(modules_json_path, "r") as fh:
modules_json = json.load(fh)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably verify that the modules.json and catch the exception if it doesn't to still remove the module. Just to be sure, for the initial phase ... maybe some people won't have the file. Although I think that the transition will be really fast.

Copy link
Contributor Author

@ErikDanielsson ErikDanielsson Jun 28, 2021

Choose a reason for hiding this comment

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

I thought about it, but didn't add it in the end since we check for the file in has_valid_pipeline. But I guess it doesn't do any harm checking for it, and if the code is changed at some point it might cause errors.

if module in modules_json.get("modules", {}):
modules_json["modules"].pop(module)
else:
# If the module is missing from modules.json we can still clear the directory
# in which the untracked module resides
log.error(f"Module '{module}' is missing from 'modules.json' file.")
return questionary.confirm(
f"Do you wish to continue removing module '{module}'?", default=False
).unsafe_ask()
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say we don't need a prompt here, maybe just say that a modules.json is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I guess we can rely on the user knowing rm -rf atleast.

with open(modules_json_path, "w") as fh:
json.dump(modules_json, fh, indent=4)
return True