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
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d445eeb
Give better suggestion when modules.json file is out-of-date.
mashehu Aug 5, 2022
0e3560a
Merge branch 'dev' of https://github.com/nf-core/tools into better-fi…
mashehu Aug 5, 2022
1f1ff4f
change message in new commands
mashehu Aug 5, 2022
f7dbfe4
[automated] Fix linting with Prettier
nf-core-bot Aug 5, 2022
a7a7b29
recreate modules.json instead of complaining
mashehu Aug 5, 2022
d600c8f
remove `has_module_file` method, as all commands relying on a module.…
mashehu Aug 5, 2022
e90c406
Merge branch 'dev' of https://github.com/nf-core/tools into better-fi…
mashehu Aug 5, 2022
7227f77
Merge branch 'better-fix-suggestion' of https://github.com/mashehu/to…
mashehu Aug 5, 2022
dc2408c
add `has_modules_file()` back in for lint and remove command
mashehu Aug 8, 2022
6dd5b8b
Improve error handling, assign `modules_json` variable already in `.c…
mashehu Aug 8, 2022
fc7693e
add test for module.json with incorrect format
mashehu Aug 8, 2022
4db1ed2
Merge branch 'dev' of https://github.com/nf-core/tools into better-fi…
mashehu Aug 9, 2022
ca39fb9
fix test for incorrect mod_json
mashehu Aug 9, 2022
6d3717a
fix isort
mashehu Aug 9, 2022
47d551b
updated changelog
mashehu Aug 9, 2022
5c05171
rename `has_git_url_and_base_path` to `has_correct_format` and includ…
mashehu Aug 16, 2022
3c07afb
Merge branch 'dev' of https://github.com/nf-core/tools into better-fi…
mashehu Aug 18, 2022
3f209ab
rename to has_git_url_and_modules (in expectation of removal of base_…
mashehu Aug 18, 2022
6ca8836
fix isort error
mashehu Aug 18, 2022
c743e84
Apply suggestions from code review
mashehu Aug 18, 2022
04c79d4
Merge branch 'dev' of https://github.com/nf-core/tools into better-fi…
Aug 22, 2022
b1f4501
fix isort
Aug 22, 2022
e2f50c4
update ubuntu version for docs GHA
Aug 22, 2022
863c390
update changelog
Aug 22, 2022
db147b4
fix typo
Aug 22, 2022
c9ea870
Merge branch 'dev' into better-fix-suggestion
mashehu Aug 23, 2022
ef9474e
Merge branch 'dev' of https://github.com/nf-core/tools into better-fi…
mashehu Aug 23, 2022
b042c18
Merge branch 'better-fix-suggestion' of https://github.com/mashehu/to…
mashehu Aug 23, 2022
364e240
update changelog
mashehu Aug 23, 2022
4d608ae
add link to PR
fabianegli Aug 23, 2022
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 @@ -72,6 +72,7 @@
- Fix misc. issues with `--branch` and `--base-path` ([#1726](https://github.com/nf-core/tools/issues/1726))
- Add `branch` field to module entries in `modules.json` to record what branch a module was installed from ([#1728](https://github.com/nf-core/tools/issues/1728))
- Fix unbound variable issues and minor refactoring [#1742](https://github.com/nf-core/tools/pull/1742/)
- Recreate modules.json file instead of complaining about incorrectly formatted file. ([#1741](https://github.com/nf-core/tools/pull/1741)

## [v2.4.1 - Cobolt Koala Patch](https://github.com/nf-core/tools/releases/tag/2.4) - [2022-05-16]

Expand Down
3 changes: 2 additions & 1 deletion nf_core/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def run_linting(
# Create the modules lint object
module_lint_obj = nf_core.modules.lint.ModuleLint(pipeline_dir)

# Verify that the pipeline is correctly configured
# Verify that the pipeline is correctly configured and has a modules.json file
module_lint_obj.has_valid_directory()
module_lint_obj.has_modules_file()

# Run only the tests we want
if key:
Expand Down
2 changes: 1 addition & 1 deletion nf_core/modules/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def pattern_msg(keywords):
repo_modules = repo_entry.get("modules")
if repo_modules is None:
raise UserWarning(
"You 'modules.json' file is not up to date. Please remove it and rerun the command"
"You 'modules.json' file is not up to date. You can fix it by running 'nf-core modules update'."
mashehu marked this conversation as resolved.
Show resolved Hide resolved
)
module_entry = repo_modules.get(module)

Expand Down
1 change: 0 additions & 1 deletion nf_core/modules/modules_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def has_valid_directory(self):
nf_config = os.path.join(self.dir, "nextflow.config")
if not os.path.exists(main_nf) and not os.path.exists(nf_config):
raise UserWarning(f"Could not find a 'main.nf' or 'nextflow.config' file in '{self.dir}'")
self.has_modules_file()
return True
Comment on lines 64 to 65
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.


def has_modules_file(self):
Expand Down
20 changes: 11 additions & 9 deletions nf_core/modules/modules_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ def create(self):
modules_json["repos"][repo_name]["modules"] = self.determine_module_branches_and_shas(
repo_name, remote_url, base_path, module_names
)

# write the modules.json file and assign it to the object
modules_json_path = Path(self.dir, "modules.json")
with open(modules_json_path, "w") as fh:
json.dump(modules_json, fh, indent=4)
fh.write("\n")
self.modules_json = modules_json

def get_pipeline_module_repositories(self, modules_dir, repos=None):
"""
Expand Down Expand Up @@ -354,7 +355,7 @@ def unsynced_modules(self):
if "git_sha" not in modules[module] or "branch" not in modules[module]:
raise UserWarning(
"The 'modules.json' file is not up to date. "
"Please reinstall it by removing it and rerunning the command."
"You can fix it by running 'nf-core modules update'."
)
missing_installation[module_repo_name]["modules"].pop(module)
if len(missing_installation[module_repo_name]["modules"]) == 0:
Expand All @@ -368,7 +369,7 @@ def unsynced_modules(self):
def has_git_url_and_base_path(self):
"""
Check that that all repo entries in the modules.json
has a git url and a base_path
have a git url and a base_path

Returns:
(bool): True if they are found for all repos, False otherwise
Expand Down Expand Up @@ -430,12 +431,13 @@ def check_up_to_date(self):
If a module is installed but the entry in 'modules.json' is missing we iterate through
the commit log in the remote to try to determine the SHA.
"""
self.load()
if not self.has_git_url_and_base_path():
raise UserWarning(
"The 'modules.json' file is not up to date. "
"Please reinstall it by removing it and rerunning the command."
)
try:
self.load()
if not self.has_git_url_and_base_path():
raise KeyError
except (UserWarning, KeyError):
log.info("The 'modules.json' file is not up to date. Recreating the 'module.json' file.")
self.create()

missing_from_modules_json, missing_installation = self.unsynced_modules()

Expand Down
3 changes: 2 additions & 1 deletion nf_core/modules/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def remove(self, module):
log.error("You cannot remove a module in a clone of nf-core/modules")
return False

# Check whether pipelines is valid
# Check whether pipeline is valid and with a modules.json file
self.has_valid_directory()
self.has_modules_file()

repo_name = self.modules_repo.fullname
if module is None:
Expand Down
16 changes: 16 additions & 0 deletions tests/modules/modules_json.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import json
import os
import shutil
Expand Down Expand Up @@ -176,3 +177,18 @@ def test_mod_json_dump(self):
with open(mod_json_path, "r") as f:
mod_json_new = json.load(f)
assert mod_json == mod_json_new


def test_mod_json_with_missing_base_path_fail(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
1 change: 1 addition & 0 deletions tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def test_modulesrepo_class(self):
test_mod_json_up_to_date_module_removed,
test_mod_json_up_to_date_reinstall_fails,
test_mod_json_update,
test_mod_json_with_missing_base_path_fail,
)
from .modules.patch import (
test_create_patch_change,
Expand Down