Skip to content

Commit

Permalink
Merge pull request #1536 from fabianegli/fabianegli-update-refactor
Browse files Browse the repository at this point in the history
improve `update.py`
  • Loading branch information
ErikDanielsson authored Jul 21, 2022
2 parents 1d427a2 + 22f9ca7 commit f8eb445
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 332 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
- Command `nf-core modules test` obtains module name suggestions from installed modules ([#1624](https://github.com/nf-core/tools/pull/1624))
- Add `--base-path` flag to `nf-core modules` to specify the base path for the modules in a remote. Also refactored `modules.json` code. ([#1643](https://github.com/nf-core/tools/issues/1643))
- Rename methods in `ModulesJson` to remove explicit reference to `modules.json`
- Fix inconsistencies in the `--save-diff` flag `nf-core modules update`. Refactor `nf-core modules update` ([#1536](https://github.com/nf-core/tools/pull/1536))
- Fix bug in `ModulesJson.check_up_to_date` causing it to ask for the remote of local modules

## [v2.4.1 - Cobolt Koala Patch](https://github.com/nf-core/tools/releases/tag/2.4) - [2022-05-16]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1119,8 +1119,8 @@ There are five additional flags that you can use with this command:
- `--force`: Reinstall module even if it appears to be up to date
- `--prompt`: Select the module version using a cli prompt.
- `--sha <commit_sha>`: Install the module at a specific commit from the `nf-core/modules` repository.
- `--diff`: Show the diff between the installed files and the new version before installing.
- `--diff-file <filename>`: Specify where the diffs between the local and remote versions of a module should be written
- `--preview/--no-preview`: Show the diff between the installed files and the new version before installing.
- `--save-diff <filename>`: Save diffs to a file instead of updating in place. The diffs can then be applied with `git apply <filename>`.
- `--all`: Use this flag to run the command on all modules in the pipeline.

If you don't want to update certain modules or want to update them to specific versions, you can make use of the `.nf-core.yml` configuration file. For example, you can prevent the `star/align` module installed from `nf-core/modules` from being updated by adding the following to the `.nf-core.yml` file:
Expand Down
2 changes: 1 addition & 1 deletion nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def install(ctx, tool, dir, prompt, force, sha):
help="Preview / no preview of changes before applying",
)
@click.option(
"-p",
"-D",
"--save-diff",
type=str,
metavar="<filename>",
Expand Down
7 changes: 3 additions & 4 deletions nf_core/modules/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ def install(self, module):
current_version = modules_json.get_module_version(module, self.modules_repo.fullname)

# Set the install folder based on the repository name
install_folder = [self.dir, "modules"]
install_folder.extend(os.path.split(self.modules_repo.fullname))
install_folder = os.path.join(self.dir, "modules", self.modules_repo.fullname)

# Compute the module directory
module_dir = os.path.join(*install_folder, module)
module_dir = os.path.join(install_folder, module)

# Check that the module is not already installed
if (current_version is not None and os.path.exists(module_dir)) and not self.force:
Expand Down Expand Up @@ -135,7 +134,7 @@ def install(self, module):

# Print include statement
module_name = "_".join(module.upper().split("/"))
log.info(f"Include statement: include {{ {module_name} }} from '.{os.path.join(*install_folder, module)}/main'")
log.info(f"Include statement: include {{ {module_name} }} from '.{os.path.join(install_folder, module)}/main'")

# Update module.json with newly installed module
modules_json.update(self.modules_repo, module, version)
Expand Down
5 changes: 2 additions & 3 deletions nf_core/modules/modules_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def check_up_to_date(self):
base_path = contents["base_path"]

modules_repo = nf_core.modules.modules_repo.ModulesRepo(remote_url=remote, base_path=base_path)
install_folder = os.path.split(modules_repo.fullname)
install_dir = os.path.join(self.dir, "modules", modules_repo.fullname)

for module, entry in modules.items():
sha = entry.get("git_sha")
Expand All @@ -313,8 +313,7 @@ def check_up_to_date(self):
)
remove_from_mod_json[repo].append(module)
continue
module_dir = [self.dir, "modules", *install_folder]
if not modules_repo.install_module(module, module_dir, sha):
if not modules_repo.install_module(module, install_dir, sha):
if repo not in remove_from_mod_json:
remove_from_mod_json[repo] = []
log.warning(f"Could not install module '{module}' in '{repo}' - removing from modules.json")
Expand Down
8 changes: 7 additions & 1 deletion nf_core/modules/modules_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def install_module(self, module_name, install_dir, commit):
return False

# Copy the files from the repo to the install folder
shutil.copytree(self.get_module_dir(module_name), os.path.join(*install_dir, module_name))
shutil.copytree(self.get_module_dir(module_name), os.path.join(install_dir, module_name))

# Switch back to the tip of the branch
self.checkout_branch()
Expand Down Expand Up @@ -338,6 +338,12 @@ def get_module_git_log(self, module_name, depth=None, since="2021-07-07T00:00:00
commits = ({"git_sha": commit.hexsha, "trunc_message": commit.message.partition("\n")[0]} for commit in commits)
return commits

def get_latest_module_version(self, module_name):
"""
Returns the latest commit in the repository
"""
return list(self.get_module_git_log(module_name, depth=1))[0]["git_sha"]

def sha_exists_on_branch(self, sha):
"""
Verifies that a given commit sha exists on the branch
Expand Down
Loading

0 comments on commit f8eb445

Please sign in to comment.