From b75ba51dba493d8171e1bdb10d13b952a82f405b Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Tue, 1 Oct 2024 16:51:32 +0200 Subject: [PATCH] fix old nf-core sync command and use the info from .nf-core.yml to sync a pipeline --- nf_core/__main__.py | 5 +++-- nf_core/utils.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/nf_core/__main__.py b/nf_core/__main__.py index e0c1b85e9..08589fc24 100644 --- a/nf_core/__main__.py +++ b/nf_core/__main__.py @@ -1815,6 +1815,7 @@ def command_create_logo(logo_text, directory, name, theme, width, format, force) # nf-core sync (deprecated) @nf_core_cli.command("sync", hidden=True, deprecated=True) +@click.pass_context @click.option( "-d", "--dir", @@ -1845,14 +1846,14 @@ def command_create_logo(logo_text, directory, name, theme, width, format, force) @click.option("-g", "--github-repository", type=str, help="GitHub PR: target repository.") @click.option("-u", "--username", type=str, help="GitHub PR: auth username.") @click.option("-t", "--template-yaml", help="Pass a YAML file to customize the template") -def command_sync(directory, from_branch, pull_request, github_repository, username, template_yaml, force_pr): +def command_sync(ctx, directory, from_branch, pull_request, github_repository, username, template_yaml, force_pr): """ Use `nf-core pipelines sync` instead. """ log.warning( "The `[magenta]nf-core sync[/]` command is deprecated. Use `[magenta]nf-core pipelines sync[/]` instead." ) - pipelines_sync(directory, from_branch, pull_request, github_repository, username, template_yaml, force_pr) + pipelines_sync(ctx, directory, from_branch, pull_request, github_repository, username, template_yaml, force_pr) # nf-core bump-version (deprecated) diff --git a/nf_core/utils.py b/nf_core/utils.py index 663efb6b4..7795d0d27 100644 --- a/nf_core/utils.py +++ b/nf_core/utils.py @@ -1136,6 +1136,45 @@ def load_tools_config(directory: Union[str, Path] = ".") -> Tuple[Optional[Path] error_message += f"\n{error['loc'][0]}: {error['msg']}" raise AssertionError(error_message) + # Retrieve information if template from config file is empty + wf_config = fetch_wf_config(Path(directory)) + config_template_keys = tools_config["template"].keys() if "template" in tools_config else [] + if nf_core_yaml_config.template is None: + # The .nf-core.yml file did not contain template information + nf_core_yaml_config.template = NFCoreTemplateConfig( + org="nf-core", + name=wf_config["manifest.name"].strip('"').strip("'").split("/")[-1], + description=wf_config["manifest.description"].strip('"').strip("'"), + author=wf_config["manifest.author"].strip('"').strip("'"), + version=wf_config["manifest.version"].strip('"').strip("'"), + outdir=str(directory), + ) + elif "prefix" in config_template_keys or "skip" in config_template_keys: + # The .nf-core.yml file contained the old prefix or skip keys + nf_core_yaml_config.template = NFCoreTemplateConfig( + org=tools_config["template"]["prefix"] + if "prefix" in config_template_keys + else tools_config["template"]["org"] or "nf-core", + name=tools_config["template"]["name"] + if "name" in config_template_keys + else wf_config["manifest.name"].strip('"').strip("'").split("/")[-1], + description=tools_config["template"]["description"] + if "description" in config_template_keys + else wf_config["manifest.description"].strip('"').strip("'"), + author=tools_config["template"]["author"] + if "author" in config_template_keys + else wf_config["manifest.author"].strip('"').strip("'"), + version=tools_config["template"]["version"] + if "version" in config_template_keys + else wf_config["manifest.version"].strip('"').strip("'"), + outdir=tools_config["template"]["outdir"] if "outdir" in config_template_keys else str(directory), + skip_features=tools_config["template"]["skip"] + if "skip" in config_template_keys + else tools_config["template"]["skip_features"] + if "skip_features" in config_template_keys + else None, + ) + log.debug("Using config file: %s", config_fn) return config_fn, nf_core_yaml_config