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

Fix undefined behaviour in update.py #1742

Merged
merged 3 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -70,6 +70,7 @@
- Add links in `README.md` for `info` and `patch` commands ([#1722](https://github.com/nf-core/tools/issues/1722)])
- 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/)

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

Expand Down
27 changes: 11 additions & 16 deletions nf_core/modules/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ def __init__(
self.modules_json = ModulesJson(self.dir)
self.branch = branch

class DiffEnum(enum.Enum):
"""Enumeration to keeping track of file diffs.

Used for the --save-diff and --preview options
"""

UNCHANGED = enum.auto()
CHANGED = enum.auto()
CREATED = enum.auto()
REMOVED = enum.auto()

def _parameter_checks(self):
"""Checks the compatibilty of the supplied parameters.

Expand Down Expand Up @@ -431,18 +420,24 @@ def get_all_modules_info(self, branch=None):

# Get the git urls from the modules.json
modules_info = (
(self.modules_json.get_git_url(repo_name), branch, self.modules_json.get_base_path(repo_name), mods_shas)
(
repo_name,
self.modules_json.get_git_url(repo_name),
branch,
self.modules_json.get_base_path(repo_name),
mods_shas,
)
for (repo_name, branch), mods_shas in repos_and_branches.items()
)

# Create ModulesRepo objects
repo_objs_mods = []
for repo_url, branch, base_path, mods_shas in modules_info:
for repo_name, repo_url, branch, base_path, mods_shas in modules_info:
try:
modules_repo = ModulesRepo(remote_url=repo_url, branch=branch, base_path=base_path)
except LookupError as e:
log.warning(e)
log.info(f"Skipping modules in '{modules_repo.fullname}'")
log.info(f"Skipping modules in '{repo_name}'")
else:
repo_objs_mods.append((modules_repo, mods_shas))

Expand All @@ -453,13 +448,13 @@ def get_all_modules_info(self, branch=None):
# don't try to update those that don't
i = 0
while i < len(modules_info):
repo, module, _ = modules_info[i]
repo, module, sha = modules_info[i]
if not repo.module_exists(module):
log.warning(f"Module '{module}' does not exist in '{repo.fullname}'. Skipping...")
modules_info.pop(i)
elif sha is not None and not repo.sha_exists_on_branch(sha):
log.warning(
f"Git sha '{sha}' does not exists on the '{branch}' of '{repo.fullname}'. Skipping module '{mod}'"
f"Git sha '{sha}' does not exists on the '{repo.branch}' of '{repo.fullname}'. Skipping module '{module}'"
)
modules_info.pop(i)
else:
Expand Down