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

make tests faster #2573

Merged
merged 15 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
2 changes: 2 additions & 0 deletions nf_core/components/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def install(self, component, silent=False):
self.install_included_components(component_dir)

if not silent:
modules_json.load()
modules_json.dump(run_prettier=True)
# Print include statement
component_name = "_".join(component.upper().split("/"))
log.info(f"Use the following statement to include this {self.component_type[:-1]}:")
Expand Down
33 changes: 19 additions & 14 deletions nf_core/components/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,21 @@ def update(self, component=None, silent=False, updated=None, check_diff_exist=Tr
updated.append(component)
recursive_update = True
modules_to_update, subworkflows_to_update = self.get_components_to_update(component)
if not silent and not self.update_all and len(modules_to_update + subworkflows_to_update) > 0:
log.warning(
f"All modules and subworkflows linked to the updated {self.component_type[:-1]} will be {'asked for update' if self.show_diff else 'automatically updated'}.\n"
"It is advised to keep all your modules and subworkflows up to date.\n"
"It is not guaranteed that a subworkflow will continue working as expected if all modules/subworkflows used in it are not up to date.\n"
)
if self.update_deps:
recursive_update = True
else:
recursive_update = questionary.confirm(
"Would you like to continue updating all modules and subworkflows?",
default=True,
style=nf_core.utils.nfcore_question_style,
).unsafe_ask()
if not silent and len(modules_to_update + subworkflows_to_update) > 0:
if not self.update_all:
log.warning(
f"All modules and subworkflows linked to the updated {self.component_type[:-1]} will be {'asked for update' if self.show_diff else 'automatically updated'}.\n"
"It is advised to keep all your modules and subworkflows up to date.\n"
"It is not guaranteed that a subworkflow will continue working as expected if all modules/subworkflows used in it are not up to date.\n"
)
if self.update_deps:
recursive_update = True
else:
recursive_update = questionary.confirm(
"Would you like to continue updating all modules and subworkflows?",
default=True,
style=nf_core.utils.nfcore_question_style,
).unsafe_ask()
if recursive_update and len(modules_to_update + subworkflows_to_update) > 0:
# Update linked components
self.update_linked_components(modules_to_update, subworkflows_to_update, updated)
Expand All @@ -323,8 +324,12 @@ def update(self, component=None, silent=False, updated=None, check_diff_exist=Tr
)
elif not all_patches_successful and not silent:
log.info(f"Updates complete. Please apply failed patch{plural_es(components_info)} manually.")
self.modules_json.load()
self.modules_json.dump(run_prettier=True)
elif not silent:
log.info("Updates complete :sparkles:")
self.modules_json.load()
self.modules_json.dump(run_prettier=True)

return exit_value

Expand Down
11 changes: 8 additions & 3 deletions nf_core/modules/modules_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil
import tempfile
from pathlib import Path
from typing import Union

import git
import questionary
Expand Down Expand Up @@ -41,7 +42,7 @@ def __init__(self, pipeline_dir):
self.modules_dir = Path(self.dir, "modules")
self.subworkflows_dir = Path(self.dir, "subworkflows")
self.modules_json_path = Path(self.dir, "modules.json")
self.modules_json = None
self.modules_json: Union(dict, None) = None
self.pipeline_modules = None
self.pipeline_subworkflows = None
self.pipeline_components = None
Expand Down Expand Up @@ -1035,13 +1036,17 @@ def get_component_branch(self, component_type, component, repo_url, install_dir)
)
return branch

def dump(self):
def dump(self, run_prettier: bool = False):
"""
Sort the modules.json, and write it to file
"""
# Sort the modules.json
self.modules_json["repos"] = nf_core.utils.sort_dictionary(self.modules_json["repos"])
dump_json_with_prettier(self.modules_json_path, self.modules_json)
if run_prettier:
dump_json_with_prettier(self.modules_json_path, self.modules_json)
else:
with open(self.modules_json_path, "w") as fh:
json.dump(self.modules_json, fh, indent=4)

def resolve_missing_installation(self, missing_installation, component_type):
missing_but_in_mod_json = [
Expand Down
41 changes: 21 additions & 20 deletions nf_core/synced_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import os
import shutil
from pathlib import Path
from typing import Dict
from typing import Dict, Union

import git
import rich.progress
from git.cmd import Git
from git.exc import GitCommandError
from git.repo import Repo

from nf_core.utils import load_tools_config

Expand Down Expand Up @@ -44,19 +45,19 @@ def __init__(self, progress_bar, repo_name, remote_url, operation):
state="Waiting for response",
)

def update(self, op_code, cur_count, max_count=None, message=""):
def update(self, op_code, cur_count, max_count, message=""):
"""
Overrides git.RemoteProgress.update.
Called every time there is a change in the remote operation
"""
if not self.progress_bar.tasks[self.tid].started:
self.progress_bar.start_task(self.tid)
self.progress_bar.update(
self.tid, total=max_count, completed=cur_count, state=f"{cur_count / max_count * 100:.1f}%"
self.tid, total=max_count, completed=cur_count, state=f"{float(cur_count) / float(max_count) * 100:.1f}%"
)


class SyncedRepo:
class SyncedRepo(Repo):
"""
An object to store details about a locally cached code repository.
"""
Expand Down Expand Up @@ -90,7 +91,7 @@ def get_remote_branches(remote_url):
(set[str]): All branches found in the remote
"""
try:
unparsed_branches = git.Git().ls_remote(remote_url)
unparsed_branches = Git().ls_remote(remote_url)
except git.GitCommandError:
raise LookupError(f"Was unable to fetch branches from '{remote_url}'")
else:
Expand Down Expand Up @@ -174,8 +175,11 @@ def setup_branch(self, branch):
else:
self.branch = branch

# Verify that the branch exists by checking it out
self.branch_exists()
# Verify that the branch exists using git
try:
self.checkout_branch()
except git.GitCommandError:
raise LookupError(f"Branch '{self.branch}' not found in '{self.remote_url}'")

def get_default_branch(self):
"""
Expand All @@ -185,15 +189,6 @@ def get_default_branch(self):
_, branch = origin_head.ref.name.split("/")
return branch

def branch_exists(self):
"""
Verifies that the branch exists in the repository by trying to check it out
"""
try:
self.checkout_branch()
except GitCommandError:
raise LookupError(f"Branch '{self.branch}' not found in '{self.remote_url}'")

def verify_branch(self):
"""
Verifies the active branch conforms to the correct directory structure
Expand All @@ -211,7 +206,9 @@ def checkout_branch(self):
"""
Checks out the specified branch of the repository
"""
self.repo.git.checkout(self.branch)
# only checkout if we're on a detached head or if we're not already on the branch
if self.repo.head.is_detached or self.repo.active_branch.name != self.branch:
self.repo.git.checkout(self.branch)

def checkout(self, commit):
"""
Expand All @@ -220,7 +217,9 @@ def checkout(self, commit):
Args:
commit (str): Git SHA of the commit
"""
self.repo.git.checkout(commit)
# only checkout if we are not already on the commit
if self.repo.head.commit.hexsha != commit:
self.repo.git.checkout(commit)

def component_exists(self, component_name, component_type, checkout=True, commit=None):
"""
Expand Down Expand Up @@ -249,7 +248,9 @@ def get_component_dir(self, component_name, component_type):
elif component_type == "subworkflows":
return os.path.join(self.subworkflows_dir, component_name)

def install_component(self, component_name, install_dir, commit, component_type):
def install_component(
self, component_name: Union[str, Path], install_dir: str, commit: str, component_type: str
) -> bool:
"""
Install the module/subworkflow files into a pipeline at the given commit

Expand Down
Loading