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

Give better suggestion when modules.json file is out-of-date. #1741

Merged
merged 30 commits into from
Aug 24, 2022

Conversation

mashehu
Copy link
Contributor

@mashehu mashehu commented Aug 5, 2022

Running nf-core modules info never recreates the modules.json. So, if it is out-of-date, the suggested help message is not useful. I think explicitly stating a command is more useful here.

@mashehu mashehu requested a review from ErikDanielsson August 5, 2022 15:12
@codecov
Copy link

codecov bot commented Aug 5, 2022

Codecov Report

Merging #1741 (4d608ae) into dev (9c8614b) will increase coverage by 0.08%.
The diff coverage is 95.45%.

@@            Coverage Diff             @@
##              dev    #1741      +/-   ##
==========================================
+ Coverage   69.14%   69.22%   +0.08%     
==========================================
  Files          59       59              
  Lines        7133     7142       +9     
==========================================
+ Hits         4932     4944      +12     
+ Misses       2201     2198       -3     
Impacted Files Coverage Δ
nf_core/modules/list.py 71.83% <ø> (+0.59%) ⬆️
nf_core/modules/modules_command.py 83.56% <ø> (-0.23%) ⬇️
nf_core/modules/modules_json.py 74.65% <95.00%> (+1.28%) ⬆️
nf_core/lint/__init__.py 74.07% <100.00%> (+0.10%) ⬆️
nf_core/modules/remove.py 82.75% <100.00%> (+0.61%) ⬆️

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

@mashehu
Copy link
Contributor Author

mashehu commented Aug 5, 2022

@nf-core-bot fix linting

@ErikDanielsson
Copy link
Contributor

I think that a better solution would be to call the ModulesJson.has_modules_file from all commands that use the modules.json -- there is no need to have the user run another command. We could even call it from the ModulesJson.check_up_to_date that checks whether the modules.json correspond to the modules present in the pipeline

Comment on lines 433 to 437
self.load()
if not self.has_git_url_and_base_path():
raise UserWarning(
"The 'modules.json' file is not up to date. " "You can fix it by running 'nf-core modules update'."
)
log.info("The 'modules.json' file is not up to date. Recreating the 'module.json' file.")
self.create()
self.load()
Copy link
Contributor

@ErikDanielsson ErikDanielsson Aug 5, 2022

Choose a reason for hiding this comment

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

I'd say it would be better with a try catch block around the call to self.load that catches the LookupError that it will throw if the file does not exist. You could also assign the modules_json variable to self.modules_json in create and skip the second call to load since there should be no need to go via the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, changed it accordingly.
Now I am actually wondering, if we need all of the

if self.modules_json is None:
    self.load()

in the different submethods, when they are (as far as I saw) all called after a check_up_to_date() call. Or is that just to be extra sure for future methods?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. Just grep for the creation of ModulesJson objects and make sure that they are not created without check_up_to_date being called. This will atleast be true for some tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I will actually leave it for now. Too many possible downstream effects, I might not be aware of now. But I added a test for .check_up_to_date(), so this PR should be good to go. 🙂

Copy link
Contributor

@ErikDanielsson ErikDanielsson left a comment

Choose a reason for hiding this comment

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

This is starting to look good!

nf_core/modules/list.py Outdated Show resolved Hide resolved
Comment on lines 64 to 65
raise UserWarning(f"Could not find a 'main.nf' or 'nextflow.config' file in '{self.dir}'")
self.has_modules_file()
return True
Copy link
Contributor

@ErikDanielsson ErikDanielsson Aug 9, 2022

Choose a reason for hiding this comment

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

I'm not sure I'm following why you removed this line, and added it as standalone calls (:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we discussed this on slack: all commands that used this function use check_up_to_date anyway, except for linting. So I kept it there.

…e check for missing `git_sha` and `branch` fields in it
Co-authored-by: Fabian Egli <fabianegli@users.noreply.github.com>
@mashehu mashehu added this to the 2.5 milestone Aug 22, 2022
Copy link
Member

@mirpedrol mirpedrol left a comment

Choose a reason for hiding this comment

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

After #1754 is merged, there are some conflicts to resolve. Apart from that, if the comments from other reviewers are solved, it looks good to me :)

nf_core/modules/modules_json.py Outdated Show resolved Hide resolved
Comment on lines 182 to 194
def test_mod_json_with_missing_base_path_entry(self):
# Load module.json and remove the base_path entry
mod_json_obj = ModulesJson(self.pipeline_dir)
mod_json_orig = mod_json_obj.get_modules_json()
mod_json = copy.deepcopy(mod_json_orig)
mod_json["repos"]["nf-core/modules"].pop("base_path")
# save the altered module.json and load it again to check if it will fix itself
mod_json_obj.modules_json = mod_json
mod_json_obj.dump()
mod_json_obj_new = ModulesJson(self.pipeline_dir)
mod_json_obj_new.check_up_to_date()
mod_json_new = mod_json_obj_new.get_modules_json()
assert mod_json_orig == mod_json_new
Copy link
Member

Choose a reason for hiding this comment

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

I think this test can also be removed after removing base_path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will update them to test with another entry. They should just make sure to be able to fix a broken modules.json

tests/modules/modules_json.py Outdated Show resolved Hide resolved
tests/modules/modules_json.py Outdated Show resolved Hide resolved
tests/test_modules.py Outdated Show resolved Hide resolved
mashehu and others added 5 commits August 23, 2022 13:14
@mashehu mashehu merged commit 20ad2aa into nf-core:dev Aug 24, 2022
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.

6 participants