diff --git a/modules/nf-core/jupyternotebook/main.nf b/modules/nf-core/jupyternotebook/main.nf index 9775a8622840..b78bdf25514c 100644 --- a/modules/nf-core/jupyternotebook/main.nf +++ b/modules/nf-core/jupyternotebook/main.nf @@ -14,6 +14,7 @@ process JUPYTERNOTEBOOK { tuple val(meta), path(notebook) val parameters path input_files + val kernel_ output: tuple val(meta), path("*.html") , emit: report @@ -25,38 +26,25 @@ process JUPYTERNOTEBOOK { script: def prefix = task.ext.prefix ?: "${meta.id}" - def parametrize = (task.ext.parametrize == null) ? true : task.ext.parametrize - def implicit_params = (task.ext.implicit_params == null) ? true : task.ext.implicit_params - def meta_params = (task.ext.meta_params == null) ? true : task.ext.meta_params - def kernel = task.ext.kernel ?: '-' + def kernel = kernel_ ?: '-' + // Implicit parameters can be overwritten by supplying a value with parameters + notebook_parameters = [ + meta: meta, + cpus: task.cpus, + ] + (parameters ?: [:]) // Dump parameters to yaml file. // Using a yaml file over using the CLI params because // * no issue with escaping // * allows to pass nested maps instead of just single values - def params_cmd = "" - def render_cmd = "" - def meta_string = meta.collect { key, value -> "${key}: ${value}" }.join('\n') - def params_string = parameters.collect { key, value -> "${key}: ${value}" }.join('\n') - if (parametrize) { - if (implicit_params) { - params_cmd += 'echo cpus: ' + task.cpus + ' >> ./.params.yml \n' - params_cmd += 'echo "artifact_dir: artifacts" >> ./.params.yml \n' - params_cmd += 'echo "input_dir: ./" >> ./.params.yml \n' - } - if (meta_params) { - params_cmd += 'echo "' + meta_string + '" >> ./.params.yml \n' - } - params_cmd += 'echo "' + params_string + '" >> ./.params.yml' - render_cmd = "papermill -f .params.yml" - } else { - render_cmd = "papermill" - } + def yamlBuilder = new groovy.yaml.YamlBuilder() + yamlBuilder.call(notebook_parameters) + def yaml_content = yamlBuilder.toString().tokenize('\n').join("\n ") """ - set -o pipefail - - # write .params.yml file if required - $params_cmd + # Dump parameters to yaml file + cat <<- END_YAML_PARAMS > params.yml + ${yaml_content} + END_YAML_PARAMS # Create output directory mkdir artifacts @@ -72,7 +60,7 @@ process JUPYTERNOTEBOOK { # Convert notebook to ipynb using jupytext, execute using papermill, convert using nbconvert jupytext --to notebook --output - --set-kernel ${kernel} ${notebook} > ${notebook}.ipynb - ${render_cmd} ${notebook}.ipynb ${notebook}.executed.ipynb + papermill -f params.yml ${notebook}.ipynb ${notebook}.executed.ipynb jupyter nbconvert --stdin --to html --output ${prefix}.html < ${notebook}.executed.ipynb cat <<-END_VERSIONS > versions.yml diff --git a/modules/nf-core/jupyternotebook/meta.yml b/modules/nf-core/jupyternotebook/meta.yml index bd8701a223d1..6ad2a9b76a7f 100644 --- a/modules/nf-core/jupyternotebook/meta.yml +++ b/modules/nf-core/jupyternotebook/meta.yml @@ -15,21 +15,24 @@ tools: homepage: https://github.com/mwouts/jupytext/ documentation: https://jupyter.org/documentation tool_dev_url: https://github.com/mwouts/jupytext/ - license: ["MIT"] + license: + - "MIT" identifier: "" - papermill: description: Parameterize, execute, and analyze notebooks homepage: https://github.com/nteract/papermill documentation: http://papermill.readthedocs.io/en/latest/ tool_dev_url: https://github.com/nteract/papermill - license: ["BSD 3-clause"] + license: + - "BSD 3-clause" identifier: "" - nbconvert: description: Parameterize, execute, and analyze notebooks homepage: https://nbconvert.readthedocs.io/en/latest/ documentation: https://nbconvert.readthedocs.io/en/latest/ tool_dev_url: https://github.com/jupyter/nbconvert - license: ["BSD 3-clause"] + license: + - "BSD 3-clause" identifier: "" input: - - meta: @@ -42,8 +45,8 @@ input: description: Jupyter notebook or jupytext representation thereof pattern: "*.{ipynb,py,md,Rmd,myst}" ontologies: - - edam: http://edamontology.org/format_3996 # Python script - - edam: http://edamontology.org/format_4000 # R markdown + - edam: http://edamontology.org/format_3996 + - edam: http://edamontology.org/format_4000 - parameters: type: map description: | @@ -54,6 +57,9 @@ input: description: One or multiple files serving as input data for the notebook. pattern: "*" ontologies: [] + - kernel_: + type: string + description: Name of the kernel to use. output: report: - - meta: @@ -82,7 +88,7 @@ output: description: File containing software versions pattern: "versions.yml" ontologies: - - edam: http://edamontology.org/format_3750 # YAML + - edam: http://edamontology.org/format_3750 authors: - "@grst" maintainers: diff --git a/modules/nf-core/jupyternotebook/tests/main.nf.test b/modules/nf-core/jupyternotebook/tests/main.nf.test index 8af13903d9d8..be711e9f407b 100644 --- a/modules/nf-core/jupyternotebook/tests/main.nf.test +++ b/modules/nf-core/jupyternotebook/tests/main.nf.test @@ -12,15 +12,13 @@ nextflow_process { test("generic - md") { when { - params { - module_args = ['parametrize':false] - } process { """ input[0] = [[id:'test_jupyter'], file(params.modules_testdata_base_path + 'generic/notebooks/jupyter/ipython_notebook.md', checkIfExists:true)] input[1] = [:] input[2] = [] + input[3] = '' """ } } @@ -39,15 +37,13 @@ nextflow_process { test("generic - md - parametrize") { when { - params { - module_args = ['parametrize':true] - } process { """ input[0] = [[id:'test_jupyter'], file(params.modules_testdata_base_path + 'generic/notebooks/jupyter/ipython_notebook.md', checkIfExists:true)] input[1] = [input_filename:"hello.txt", n_iter:12] input[2] = file(params.modules_testdata_base_path + 'generic/txt/hello.txt', checkIfExists:true) + input[3] = '' """ } } @@ -68,15 +64,13 @@ nextflow_process { when { - params { - module_args = ['parametrize':true] - } process { """ input[0] = [[id:'test_jupyter'], file(params.modules_testdata_base_path + 'generic/notebooks/jupyter/ipython_notebook.ipynb', checkIfExists:true)] input[1] = [input_filename:"hello.txt", n_iter:12] input[2] = file(params.modules_testdata_base_path + 'generic/txt/hello.txt', checkIfExists:true) + input[3] = '' """ } } @@ -98,15 +92,13 @@ nextflow_process { options "-stub" when { - params { - module_args = ['parametrize':false] - } process { """ input[0] = [[id:'test_jupyter'], file(params.modules_testdata_base_path + 'generic/notebooks/jupyter/ipython_notebook.md', checkIfExists:true)] input[1] = [:] input[2] = [] + input[3] = '' """ } } diff --git a/modules/nf-core/jupyternotebook/tests/main.nf.test.snap b/modules/nf-core/jupyternotebook/tests/main.nf.test.snap index a15ef70e6ae4..ec725999fae2 100644 --- a/modules/nf-core/jupyternotebook/tests/main.nf.test.snap +++ b/modules/nf-core/jupyternotebook/tests/main.nf.test.snap @@ -9,19 +9,19 @@ "id": "test_jupyter" }, [ - "artifact.txt:md5,8ddd8be4b179a529afa5f2ffae4b9858" + ] ] ], [ - "versions.yml:md5,d117eb87cb1392fe15e7b46ba822825a" + "versions.yml:md5,fc2a7a3269fbae7ce3d9c8a17b91de01" ] ], + "timestamp": "2026-03-13T20:41:47.791483035", "meta": { - "nf-test": "0.9.2", - "nextflow": "24.10.6" - }, - "timestamp": "2025-05-30T11:35:17.89341504" + "nf-test": "0.9.4", + "nextflow": "25.10.4" + } }, "generic - md - stub": { "content": [ @@ -70,11 +70,11 @@ ] } ], + "timestamp": "2025-05-29T14:34:50.943899122", "meta": { "nf-test": "0.9.2", "nextflow": "25.04.2" - }, - "timestamp": "2025-05-29T14:34:50.943899122" + } }, "generic - md - parametrize": { "content": [ @@ -86,19 +86,19 @@ "id": "test_jupyter" }, [ - "artifact.txt:md5,8ddd8be4b179a529afa5f2ffae4b9858" + ] ] ], [ - "versions.yml:md5,d117eb87cb1392fe15e7b46ba822825a" + "versions.yml:md5,fc2a7a3269fbae7ce3d9c8a17b91de01" ] ], + "timestamp": "2026-03-13T20:41:31.036482511", "meta": { - "nf-test": "0.9.2", - "nextflow": "24.10.6" - }, - "timestamp": "2025-05-30T11:34:58.272377123" + "nf-test": "0.9.4", + "nextflow": "25.10.4" + } }, "generic - md": { "content": [ @@ -108,10 +108,10 @@ "versions.yml:md5,fc2a7a3269fbae7ce3d9c8a17b91de01" ] ], + "timestamp": "2025-05-30T11:28:28.193453013", "meta": { "nf-test": "0.9.2", "nextflow": "24.10.6" - }, - "timestamp": "2025-05-30T11:28:28.193453013" + } } } \ No newline at end of file diff --git a/modules/nf-core/jupyternotebook/tests/nextflow.config b/modules/nf-core/jupyternotebook/tests/nextflow.config index 83e9cb436969..e69de29bb2d1 100644 --- a/modules/nf-core/jupyternotebook/tests/nextflow.config +++ b/modules/nf-core/jupyternotebook/tests/nextflow.config @@ -1,5 +0,0 @@ -process { - withName: "JUPYTERNOTEBOOK" { - ext = params.module_args - } -}