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

2311 interpret docker.registry automatically #2318

Merged
merged 8 commits into from
Jun 15, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Remove schema validation from `lib` folder and use Nextflow [nf-validation plugin](https://nextflow-io.github.io/nf-validation/) instead ([#1771](https://github.com/nf-core/tools/pull/1771/))
- Fix parsing of container directive when it is not typical nf-core format ([#2306](https://github.com/nf-core/tools/pull/2306))
- Add ability to specify custom registry for linting modules, defaults to quay.io ([#2313](https://github.com/nf-core/tools/pull/2313))
- Add ability to interpret `docker.registry` from `nextflow.config` file. If not found defaults to quay.io. ([#2318](https://github.com/nf-core/tools/pull/2318))

### Download

Expand Down
8 changes: 7 additions & 1 deletion nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,12 @@ def create_test_yml(ctx, tool, run_tests, output, force, no_prompts):
@click.argument("tool", type=str, required=False, metavar="<tool> or <tool/subtool>")
@click.option("-d", "--dir", type=click.Path(exists=True), default=".", metavar="<pipeline/modules directory>")
@click.option(
"-r", "--registry", type=str, metavar="<registry>", default="quay.io", help="Registry to use for containers"
"-r",
"--registry",
type=str,
metavar="<registry>",
default=None,
help="Registry to use for containers. If not specified it will use docker.registry value in the nextflow.config file",
)
@click.option("-k", "--key", type=str, metavar="<test>", multiple=True, help="Run only these lint tests")
@click.option("-a", "--all", is_flag=True, help="Run on all modules")
Expand Down Expand Up @@ -842,6 +847,7 @@ def lint(
module_lint = ModuleLint(
dir,
fail_warned=fail_warned,
registry=ctx.params["registry"],
remote_url=ctx.obj["modules_repo_url"],
branch=ctx.obj["modules_repo_branch"],
no_pull=ctx.obj["modules_repo_no_pull"],
Expand Down
15 changes: 13 additions & 2 deletions nf_core/modules/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(
remote_url=None,
branch=None,
no_pull=False,
registry=None,
hide_progress=False,
):
super().__init__(
Expand Down Expand Up @@ -114,6 +115,7 @@ def __init__(
)
for m in self.get_local_components()
]
self.config = nf_core.utils.fetch_wf_config(self.dir, cache_config=True)
else:
module_dir = Path(self.dir, self.default_modules_path)
self.all_remote_modules = [
Expand All @@ -124,6 +126,15 @@ def __init__(
if not self.all_remote_modules:
raise LookupError("No modules in 'modules' directory")

# This could be better, perhaps glob for all nextflow.config files in?
self.config = nf_core.utils.fetch_wf_config(Path(self.dir).joinpath("tests", "config"), cache_config=True)

if registry is None:
self.registry = self.config.get("docker.registry", "quay.io")
else:
self.registry = registry
log.debug(f"Registry set to {self.registry}")

self.lint_config = None
self.modules_json = None

Expand Down Expand Up @@ -313,7 +324,7 @@ def lint_module(self, mod, progress_bar, registry, local=False, fix_version=Fals

# Only check the main script in case of a local module
if local:
self.main_nf(mod, fix_version, registry, progress_bar)
self.main_nf(mod, fix_version, self.registry, progress_bar)
self.passed += [LintResult(mod, *m) for m in mod.passed]
warned = [LintResult(mod, *m) for m in (mod.warned + mod.failed)]
if not self.fail_warned:
Expand All @@ -325,7 +336,7 @@ def lint_module(self, mod, progress_bar, registry, local=False, fix_version=Fals
else:
for test_name in self.lint_tests:
if test_name == "main_nf":
getattr(self, test_name)(mod, fix_version, registry, progress_bar)
getattr(self, test_name)(mod, fix_version, self.registry, progress_bar)
else:
getattr(self, test_name)(mod)

Expand Down
9 changes: 7 additions & 2 deletions nf_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def fetch_wf_config(wf_path, cache_config=True):

if cache_basedir and cache_fn:
cache_path = os.path.join(cache_basedir, cache_fn)
if os.path.isfile(cache_path):
if os.path.isfile(cache_path) and cache_config is True:
log.debug(f"Found a config cache, loading: {cache_path}")
with open(cache_path, "r") as fh:
try:
Expand All @@ -274,7 +274,7 @@ def fetch_wf_config(wf_path, cache_config=True):
ul = l.decode("utf-8")
try:
k, v = ul.split(" = ", 1)
config[k] = v
config[k] = v.strip("'\"")
except ValueError:
log.debug(f"Couldn't find key=value config pair:\n {ul}")

Expand Down Expand Up @@ -303,6 +303,11 @@ def fetch_wf_config(wf_path, cache_config=True):
return config


def parse_nf_config(wf_path, cache_config=True):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this function used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I don't think it is!

config = fetch_wf_config(wf_path=wf_path, cache_config=True)
return config


def nextflow_cmd(cmd):
"""Run a Nextflow command and capture the output. Handle errors nicely"""
try:
Expand Down
7 changes: 4 additions & 3 deletions tests/modules/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ def test_modules_lint_multiple_remotes(self):
def test_modules_lint_registry(self):
"""Test linting the samtools module and alternative registry"""
self.mods_install.install("samtools")
module_lint = nf_core.modules.ModuleLint(dir=self.pipeline_dir)
module_lint.lint(print_results=False, registry="public.ecr.aws", module="samtools")
module_lint = nf_core.modules.ModuleLint(dir=self.pipeline_dir, registry="public.ecr.aws")
module_lint.lint(print_results=False, module="samtools")
assert len(module_lint.failed) == 0, f"Linting failed with {[x.__dict__ for x in module_lint.failed]}"
assert len(module_lint.passed) > 0
assert len(module_lint.warned) >= 0
module_lint.lint(print_results=False, registry="quay.io", module="samtools")
module_lint = nf_core.modules.ModuleLint(dir=self.pipeline_dir)
module_lint.lint(print_results=False, module="samtools")
assert len(module_lint.failed) == 0, f"Linting failed with {[x.__dict__ for x in module_lint.failed]}"
assert len(module_lint.passed) > 0
assert len(module_lint.warned) >= 0
Expand Down
2 changes: 1 addition & 1 deletion tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_wf_use_local_configs(self, tmp_path):
# Test the function
download_obj.wf_use_local_configs("workflow")
wf_config = nf_core.utils.fetch_wf_config(os.path.join(test_outdir, "workflow"), cache_config=False)
assert wf_config["params.custom_config_base"] == f"'{test_outdir}/workflow/../configs/'"
assert wf_config["params.custom_config_base"] == f"{test_outdir}/workflow/../configs/"

#
# Tests for 'find_container_images'
Expand Down