From b7293bc8a0328a90dccc93b323757ea136f45350 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Tue, 20 Aug 2024 12:59:49 +0200 Subject: [PATCH 1/6] beforeText and afterText for summaries --- .../validation/SchemaValidator.groovy | 2 ++ .../validation/config/SummaryConfig.groovy | 28 +++++++++++++++++++ .../validation/config/ValidationConfig.groovy | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 plugins/nf-schema/src/main/nextflow/validation/config/SummaryConfig.groovy diff --git a/plugins/nf-schema/src/main/nextflow/validation/SchemaValidator.groovy b/plugins/nf-schema/src/main/nextflow/validation/SchemaValidator.groovy index 8a826b8e..2b1ce7d9 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/SchemaValidator.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/SchemaValidator.groovy @@ -500,6 +500,7 @@ Please contact the pipeline maintainer(s) if you see this warning as a user. def colors = Utils.logColours(config.monochromeLogs) String output = '' + output += config.summary.beforeText def Map paramsMap = paramsSummaryMap(workflow, parameters_schema: schemaFilename) paramsMap.each { key, value -> paramsMap[key] = flattenNestedParamsMap(value as Map) @@ -517,6 +518,7 @@ Please contact the pipeline maintainer(s) if you see this warning as a user. } output += "!! Only displaying parameters that differ from the pipeline defaults !!\n" output += "-${colors.dim}----------------------------------------------------${colors.reset}-" + output += config.summary.afterText return output } diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/SummaryConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/SummaryConfig.groovy new file mode 100644 index 00000000..2987623e --- /dev/null +++ b/plugins/nf-schema/src/main/nextflow/validation/config/SummaryConfig.groovy @@ -0,0 +1,28 @@ +package nextflow.validation + +import groovy.util.logging.Slf4j +import groovy.transform.PackageScope + + +/** + * This class allows to model a specific configuration, extracting values from a map and converting + * + * We anotate this class as @PackageScope to restrict the access of their methods only to class in the + * same package + * + * @author : nvnieuwk + * + */ + +@Slf4j +@PackageScope +class SummaryConfig { + final public String beforeText + final public String afterText + + SummaryConfig(Map map) { + def config = map ?: Collections.emptyMap() + beforeText = config.beforeText ?: "" + afterText = config.afterText ?: "" + } +} \ No newline at end of file diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy index bb347e51..8ebff8d4 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy @@ -24,6 +24,7 @@ class ValidationConfig { final public String parametersSchema final public Boolean showHiddenParams = false final public HelpConfig help + final public SummaryConfig summary final public List ignoreParams @@ -37,6 +38,7 @@ class ValidationConfig { } parametersSchema = config.parametersSchema ?: "nextflow_schema.json" help = new HelpConfig(config.help as Map ?: [:], params) + summary = new SummaryConfig(config.summary as Map ?: [:]) if(config.ignoreParams && !(config.ignoreParams instanceof List)) { throw new SchemaValidationException("Config value 'validation.ignoreParams' should be a list of String values") From 97fb26d07be40963bfe51aee3f5ab6455d40e4e1 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Tue, 20 Aug 2024 13:13:09 +0200 Subject: [PATCH 2/6] add a color filter to text options --- .../src/main/nextflow/validation/Utils.groovy | 9 +++++++++ .../nextflow/validation/config/HelpConfig.groovy | 14 ++++++++++---- .../validation/config/SummaryConfig.groovy | 11 ++++++++--- .../validation/config/ValidationConfig.groovy | 6 ++---- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/plugins/nf-schema/src/main/nextflow/validation/Utils.groovy b/plugins/nf-schema/src/main/nextflow/validation/Utils.groovy index 1ff9a98c..f6744002 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/Utils.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/Utils.groovy @@ -270,6 +270,15 @@ public class Utils { return colorcodes } + public static String removeColors(String input) { + String output = input + List colors = logColours(false).collect { it.value } + colors.each { color -> + output = output.replace(color, "") + } + return output + } + // // This function tries to read a JSON params file // diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/HelpConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/HelpConfig.groovy index 1a9d7d2d..f78791d5 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/config/HelpConfig.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/config/HelpConfig.groovy @@ -26,15 +26,21 @@ class HelpConfig { final public String command final public Boolean showHidden - HelpConfig(Map map, Map params) { + HelpConfig(Map map, Map params, Boolean monochromeLogs) { def config = map ?: Collections.emptyMap() enabled = config.enabled ?: false shortParameter = config.shortParameter ?: "help" fullParameter = config.fullParameter ?: "helpFull" showHiddenParameter = config.showHiddenParameter ?: "showHidden" - beforeText = config.beforeText ?: "" - afterText = config.afterText ?: "" - command = config.command ?: "" + if (monochromeLogs) { + beforeText = config.beforeText ? Utils.removeColors(config.beforeText): "" + afterText = config.afterText ? Utils.removeColors(config.afterText) : "" + command = config.command ? Utils.removeColors(config.afterText) : "" + } else { + beforeText = config.beforeText ?: "" + afterText = config.afterText ?: "" + command = config.command ?: "" + } showHidden = params.get(showHiddenParameter) ?: config.showHidden ?: false } } \ No newline at end of file diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/SummaryConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/SummaryConfig.groovy index 2987623e..9b177864 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/config/SummaryConfig.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/config/SummaryConfig.groovy @@ -20,9 +20,14 @@ class SummaryConfig { final public String beforeText final public String afterText - SummaryConfig(Map map) { + SummaryConfig(Map map, Boolean monochromeLogs) { def config = map ?: Collections.emptyMap() - beforeText = config.beforeText ?: "" - afterText = config.afterText ?: "" + if (monochromeLogs) { + beforeText = config.beforeText ? Utils.removeColors(config.beforeText): "" + afterText = config.afterText ? Utils.removeColors(config.afterText) : "" + } else { + beforeText = config.beforeText ?: "" + afterText = config.afterText ?: "" + } } } \ No newline at end of file diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy index 8ebff8d4..438f1441 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy @@ -37,8 +37,8 @@ class ValidationConfig { log.warn("configuration option `validation.showHiddenParams` is deprecated, please use `validation.help.showHidden` or the `--showHidden` parameter instead") } parametersSchema = config.parametersSchema ?: "nextflow_schema.json" - help = new HelpConfig(config.help as Map ?: [:], params) - summary = new SummaryConfig(config.summary as Map ?: [:]) + help = new HelpConfig(config.help as Map ?: [:], params, monochromeLogs) + summary = new SummaryConfig(config.summary as Map ?: [:], monochromeLogs) if(config.ignoreParams && !(config.ignoreParams instanceof List)) { throw new SchemaValidationException("Config value 'validation.ignoreParams' should be a list of String values") @@ -49,6 +49,4 @@ class ValidationConfig { } ignoreParams += config.defaultIgnoreParams ?: [] } - - String getPrefix() { prefix } } \ No newline at end of file From 40722377f1db03abddc935337e3088f95831bdc7 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Tue, 20 Aug 2024 13:16:14 +0200 Subject: [PATCH 3/6] update changelog --- CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e4710d5..e5e3796e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ 1. The plugin now fully supports nested parameters! 2. Added a config option `validation.parametersSchema` which can be used to set the parameters JSON schema in a config file. The default is `nextflow_schema.json` 3. The parameter summary log will now automatically show nested parameters. +4. Added two new configuration options: `validation.summary.beforeText` and `validation.summary.afterText` to automatically add some text before and after the output of the `paramsSummaryLog()` function. The colors from these texts will be automatically filtered out if `validation.monochromeLogs` is set to `true`. ## Help message changes @@ -21,9 +22,9 @@ - `validation.help.fullParameter`: The parameter to use for the expanded help message. This help message will show all parameters no matter how deeply nested they are. Default = `helpFull` - `validation.help.showHiddenParameter`: The parameter to use to also show all parameters with the `hidden: true` keyword in the schema. Default = `showHidden` - `validation.help.showHidden`: Set this to `true` to show hidden parameters by default. This configuration option is overwritten by the value supplied to the parameter in `validation.help.showHiddenParameter`. Default = `false` - - `validation.help.beforeText`: Some custom text to add before the help message. - - `validation.help.afterText`: Some custom text to add after the help message. - - `validation.help.command`: An example command to add to the top of the help message + - `validation.help.beforeText`: Some custom text to add before the help message. The colors from this text will be automatically filtered out if `validation.monochromeLogs` is set to `true`. + - `validation.help.afterText`: Some custom text to add after the help message. The colors from this text will be automatically filtered out if `validation.monochromeLogs` is set to `true`. + - `validation.help.command`: An example command to add to the top of the help message. The colors from this text will be automatically filtered out if `validation.monochromeLogs` is set to `true`. 3. Added support for nested parameters to the help message. A detailed help message using `--help ` will now also contain all nested parameters. The parameter supplied to `--help` can be a nested parameter too (e.g. `--help top_parameter.nested_parameter.deeper_parameter`) 4. The help message now won't show empty parameter groups. 5. The help message will now automatically contain the three parameters used to get help messages. From 8e47c56c1d903d315a881a1b997033fc86f9a01b Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Tue, 20 Aug 2024 13:30:09 +0200 Subject: [PATCH 4/6] fix some issues and add a test --- .../src/main/nextflow/validation/Utils.groovy | 1 + .../validation/config/HelpConfig.groovy | 2 +- .../validation/ParamsSummaryLogTest.groovy | 46 +++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/plugins/nf-schema/src/main/nextflow/validation/Utils.groovy b/plugins/nf-schema/src/main/nextflow/validation/Utils.groovy index f6744002..c016b14a 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/Utils.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/Utils.groovy @@ -271,6 +271,7 @@ public class Utils { } public static String removeColors(String input) { + if (!input) {return input} String output = input List colors = logColours(false).collect { it.value } colors.each { color -> diff --git a/plugins/nf-schema/src/main/nextflow/validation/config/HelpConfig.groovy b/plugins/nf-schema/src/main/nextflow/validation/config/HelpConfig.groovy index f78791d5..d184e48e 100644 --- a/plugins/nf-schema/src/main/nextflow/validation/config/HelpConfig.groovy +++ b/plugins/nf-schema/src/main/nextflow/validation/config/HelpConfig.groovy @@ -35,7 +35,7 @@ class HelpConfig { if (monochromeLogs) { beforeText = config.beforeText ? Utils.removeColors(config.beforeText): "" afterText = config.afterText ? Utils.removeColors(config.afterText) : "" - command = config.command ? Utils.removeColors(config.afterText) : "" + command = config.command ? Utils.removeColors(config.command) : "" } else { beforeText = config.beforeText ?: "" afterText = config.afterText ?: "" diff --git a/plugins/nf-schema/src/test/nextflow/validation/ParamsSummaryLogTest.groovy b/plugins/nf-schema/src/test/nextflow/validation/ParamsSummaryLogTest.groovy index b4cb5073..61ef1798 100644 --- a/plugins/nf-schema/src/test/nextflow/validation/ParamsSummaryLogTest.groovy +++ b/plugins/nf-schema/src/test/nextflow/validation/ParamsSummaryLogTest.groovy @@ -138,4 +138,50 @@ class ParamsSummaryLogTest extends Dsl2Spec{ stdout.size() == 11 stdout ==~ /.*\[0;34mthis.is.so.deep: .\[0;32mchanged_value.*/ } + + def 'should print params summary - adds before and after text' () { + given: + def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString() + def SCRIPT = """ + params.outdir = "outDir" + include { paramsSummaryLog } from 'plugin/nf-schema' + + def summary_params = paramsSummaryLog(workflow, parameters_schema: '$schema') + log.info summary_params + """ + + when: + def config = [ + "validation": [ + "summary": [ + "beforeText": "This text is printed before \n", + "afterText": "\nThis text is printed after", + ] + ] + ] + def result = new MockScriptRunner(config).setScript(SCRIPT).execute() + def stdout = capture + .toString() + .readLines() + .findResults { !it.contains("DEBUG") && !it.contains("after]]") ? it : null } + .findResults {it.contains('Only displaying parameters that differ from the pipeline defaults') || + it.contains('Core Nextflow options') || + it.contains('runName') || + it.contains('launchDir') || + it.contains('workDir') || + it.contains('projectDir') || + it.contains('userName') || + it.contains('profile') || + it.contains('configFiles') || + it.contains('Input/output options') || + it.contains('outdir') || + it.contains('This text is printed before') || + it.contains('This text is printed after') + ? it : null } + + then: + noExceptionThrown() + stdout.size() == 13 + stdout ==~ /.*\[0;34moutdir : .\[0;32moutDir.*/ + } } \ No newline at end of file From 15f2f39aa4ac23a760b539a1df1ca5fa3acb6b4b Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Tue, 20 Aug 2024 13:36:00 +0200 Subject: [PATCH 5/6] update docs --- docs/configuration/configuration.md | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index e052a9da..e21b99e7 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -148,6 +148,10 @@ Any string provided to this option will printed before the help message. validation.help.beforeText = "Running pipeline version 1.0" // default: "" ``` +!!! info + + All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true` + ### command !!! example "This option does not affect the help message created by the `paramsHelp()` function" @@ -166,6 +170,10 @@ Typical pipeline command: nextflow run main.nf --input samplesheet.csv --outdir output ``` +!!! info + + All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true` + ### afterText !!! example "This option does not affect the help message created by the `paramsHelp()` function" @@ -175,3 +183,37 @@ Any string provided to this option will be printed after the help message. ```groovy validation.help.afterText = "Please cite the pipeline owners when using this pipeline" // default: "" ``` + +!!! info + + All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true` + +## Summary + +The `validation.summary` config scope can be used to configure the output of the `paramsSummaryLog()` function. + +This scope contains the following options: + +### beforeText + +Any string provided to this option will printed before the parameters log message. + +```groovy +validation.summary.beforeText = "Running pipeline version 1.0" // default: "" +``` + +!!! info + + All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true` + +### afterText + +Any string provided to this option will be printed after the parameters log message. + +```groovy +validation.summary.afterText = "Please cite the pipeline owners when using this pipeline" // default: "" +``` + +!!! info + + All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true` \ No newline at end of file From fd485028e337de43098c181d560055a5fb8216c3 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Tue, 20 Aug 2024 13:48:25 +0200 Subject: [PATCH 6/6] prettier --- docs/configuration/configuration.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index e21b99e7..55e98b70 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -148,7 +148,7 @@ Any string provided to this option will printed before the help message. validation.help.beforeText = "Running pipeline version 1.0" // default: "" ``` -!!! info +!!! info All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true` @@ -170,7 +170,7 @@ Typical pipeline command: nextflow run main.nf --input samplesheet.csv --outdir output ``` -!!! info +!!! info All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true` @@ -184,7 +184,7 @@ Any string provided to this option will be printed after the help message. validation.help.afterText = "Please cite the pipeline owners when using this pipeline" // default: "" ``` -!!! info +!!! info All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true` @@ -202,7 +202,7 @@ Any string provided to this option will printed before the parameters log messag validation.summary.beforeText = "Running pipeline version 1.0" // default: "" ``` -!!! info +!!! info All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true` @@ -214,6 +214,6 @@ Any string provided to this option will be printed after the parameters log mess validation.summary.afterText = "Please cite the pipeline owners when using this pipeline" // default: "" ``` -!!! info +!!! info - All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true` \ No newline at end of file + All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true`