Skip to content

Commit 3ed83fd

Browse files
authored
Merge branch 'master' into more-s3
2 parents 7d92d95 + 24df409 commit 3ed83fd

File tree

5 files changed

+67
-45
lines changed

5 files changed

+67
-45
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
### Bug fixes
66

7-
- Do not check S3 URL paths with `PathValidator` `FilePathValidator` and `DirectoryPathValidator` ([#105](https://github.com/nextflow-io/nf-validation/pull/105))
7+
- Do not check S3 URL paths with `PathValidator` `FilePathValidator` and `DirectoryPathValidator` ([#106](https://github.com/nextflow-io/nf-validation/pull/106))
8+
- Make monochrome_logs an option in `paramsSummaryLog()`, `paramsSummaryMap()` and `paramsHelp()` instead of a global parameter ([#101](https://github.com/nextflow-io/nf-validation/pull/101))
89

910
# Version 0.3.3
1011

docs/parameters/help_text.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ params.validationShowHiddenParams = true
7979

8080
By default, the help output is coloured using ANSI escape codes.
8181

82-
If you prefer, you can disable these by using `--monochrome_logs` or `params.monochrome_logs = true`.
82+
If you prefer, you can disable these by using the argument monochrome_logs, e.g. `paramsHelp(monochrome_logs: true)`. Alternatively this can be set at a global level via parameter `--monochrome_logs` or adding `params.monochrome_logs = true` to a configuration file. Not `--monochromeLogs` or `params.monochromeLogs` is also supported.
8383

8484
=== "Default (coloured)"
8585

docs/parameters/summary_log.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Output:
5151

5252
By default, the summary output is coloured using ANSI escape codes.
5353

54-
If you prefer, you can disable these by using `--monochrome_logs` or `params.monochrome_logs = true`.
54+
If you prefer, you can disable these by using the argument monochrome_logs, e.g. `paramsHelp(monochrome_logs: true)`. Alternatively this can be set at a global level via parameter `--monochrome_logs` or adding `params.monochrome_logs = true` to a configuration file. Not `--monochromeLogs` or `params.monochromeLogs` is also supported.
5555

5656
=== "Default (coloured)"
5757

plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ class SchemaValidator extends PluginExtensionPoint {
130130
//
131131
// Resolve Schema path relative to main workflow directory
132132
//
133-
static String getSchemaPath(String baseDir, String schema_filename='nextflow_schema.json') {
134-
if (Path.of(schema_filename).exists()) {
135-
return schema_filename
133+
static String getSchemaPath(String baseDir, String schemaFilename='nextflow_schema.json') {
134+
if (Path.of(schemaFilename).exists()) {
135+
return schemaFilename
136136
} else {
137-
return "${baseDir}/${schema_filename}"
137+
return "${baseDir}/${schemaFilename}"
138138
}
139139
}
140140

@@ -221,9 +221,6 @@ class SchemaValidator extends PluginExtensionPoint {
221221
if( !params.containsKey("validationLenientMode") ) {
222222
params.validationLenientMode = false
223223
}
224-
if( !params.containsKey("monochrome_logs") ) {
225-
params.monochrome_logs = false
226-
}
227224
if( !params.containsKey("help") ) {
228225
params.help = false
229226
}
@@ -251,7 +248,6 @@ class SchemaValidator extends PluginExtensionPoint {
251248
def List expectedParams = [
252249
"validationFailUnrecognisedParams",
253250
"validationLenientMode",
254-
"monochrome_logs",
255251
"help",
256252
"validationShowHiddenParams",
257253
"validationSchemaIgnoreParams",
@@ -268,11 +264,18 @@ class SchemaValidator extends PluginExtensionPoint {
268264
* whether the given parameters adhere to the specifications
269265
*/
270266
@Function
271-
void validateParameters(String schema_filename='nextflow_schema.json') {
267+
void validateParameters(
268+
Map options = null,
269+
String schemaFilename
270+
) {
272271

273272
def Map params = initialiseExpectedParams(session.params)
274273
def String baseDir = session.baseDir
275274
def Boolean s3PathCheck = params.validationS3PathCheck ? params.validationS3PathCheck : false
275+
def Boolean useMonochromeLogs = options?.containsKey('monochrome_logs') ? options.monochrome_logs as Boolean :
276+
params.monochrome_logs ? params.monochrome_logs as Boolean :
277+
params.monochromeLogs ? params.monochromeLogs as Boolean :
278+
false
276279
log.debug "Starting parameters validation"
277280

278281
// Clean the parameters
@@ -283,7 +286,7 @@ class SchemaValidator extends PluginExtensionPoint {
283286
//=====================================================================//
284287
// Check for nextflow core params and unexpected params
285288
def slurper = new JsonSlurper()
286-
def Map parsed = (Map) slurper.parse( Path.of(getSchemaPath(baseDir, schema_filename)) )
289+
def Map parsed = (Map) slurper.parse( Path.of(getSchemaPath(baseDir, schemaFilename)) )
287290
def Map schemaParams = (Map) parsed.get('definitions')
288291
def specifiedParamKeys = params.keySet()
289292

@@ -335,7 +338,7 @@ class SchemaValidator extends PluginExtensionPoint {
335338

336339
//=====================================================================//
337340
// Validate parameters against the schema
338-
def String schema_string = Files.readString( Path.of(getSchemaPath(baseDir, schema_filename)) )
341+
def String schema_string = Files.readString( Path.of(getSchemaPath(baseDir, schemaFilename)) )
339342
final rawSchema = new JSONObject(new JSONTokener(schema_string))
340343
final SchemaLoader schemaLoader = SchemaLoader.builder()
341344
.schemaJson(rawSchema)
@@ -352,8 +355,7 @@ class SchemaValidator extends PluginExtensionPoint {
352355
}
353356

354357
// Colors
355-
def Boolean monochrome_logs = params.monochrome_logs
356-
def colors = logColours(monochrome_logs)
358+
def colors = logColours(useMonochromeLogs)
357359

358360
// Validate
359361
try {
@@ -412,7 +414,7 @@ class SchemaValidator extends PluginExtensionPoint {
412414
fileContent = file_path.splitCsv(header:true, strip:true, sep:delimiter)
413415
fileContentCasted = castToType(fileContent, types)
414416
}
415-
if (validateFile(monochrome_logs, key, fileContentCasted, schema_name, baseDir, s3PathCheck)) {
417+
if (validateFile(useMonochromeLogs, key, fileContentCasted, schema_name, baseDir, s3PathCheck)) {
416418
log.debug "Validation passed: '$key': '$file_path' with '$schema_name'"
417419
}
418420
}
@@ -426,13 +428,13 @@ class SchemaValidator extends PluginExtensionPoint {
426428
//
427429
// Function to obtain the variable types of properties from a JSON Schema
428430
//
429-
Map variableTypes(String schema_filename, String baseDir) {
431+
Map variableTypes(String schemaFilename, String baseDir) {
430432
def Map variableTypes = [:]
431433
def String type = ''
432434

433435
// Read the schema
434436
def slurper = new JsonSlurper()
435-
def Map parsed = (Map) slurper.parse( Path.of(getSchemaPath(baseDir, schema_filename)) )
437+
def Map parsed = (Map) slurper.parse( Path.of(getSchemaPath(baseDir, schemaFilename)) )
436438

437439
// Obtain the type of each variable in the schema
438440
def Map properties = (Map) parsed['items']['properties']
@@ -505,11 +507,13 @@ class SchemaValidator extends PluginExtensionPoint {
505507
//
506508
/* groovylint-disable-next-line UnusedPrivateMethodParameter */
507509
boolean validateFile(
508-
Boolean monochrome_logs, String paramName, Object fileContent, String schema_filename, String baseDir, Boolean s3PathCheck = false
510+
511+
Boolean monochrome_logs, String paramName, Object fileContent, String schemaFilename, String baseDir, Boolean s3PathCheck = false
512+
509513
) {
510514

511515
// Load the schema
512-
def String schema_string = Files.readString( Path.of(getSchemaPath(baseDir, schema_filename)) )
516+
def String schema_string = Files.readString( Path.of(getSchemaPath(baseDir, schemaFilename)) )
513517
final rawSchema = new JSONObject(new JSONTokener(schema_string))
514518
final SchemaLoader schemaLoader = SchemaLoader.builder()
515519
.schemaJson(rawSchema)
@@ -531,7 +535,7 @@ class SchemaValidator extends PluginExtensionPoint {
531535
//=====================================================================//
532536
// Check for params with expected values
533537
def slurper = new JsonSlurper()
534-
def Map parsed = (Map) slurper.parse( Path.of(getSchemaPath(baseDir, schema_filename)) )
538+
def Map parsed = (Map) slurper.parse( Path.of(getSchemaPath(baseDir, schemaFilename)) )
535539
def Map schemaParams = (Map) ["items": parsed.get('items')]
536540

537541
// Collect expected parameters from the schema
@@ -660,16 +664,25 @@ class SchemaValidator extends PluginExtensionPoint {
660664
// Beautify parameters for --help
661665
//
662666
@Function
663-
String paramsHelp(String command, String schema_filename='nextflow_schema.json') {
667+
String paramsHelp(
668+
Map options = null,
669+
String command
670+
) {
664671
def Map params = initialiseExpectedParams(session.params)
665672
def String baseDir = session.baseDir
666-
def Boolean monochrome_logs = params.monochrome_logs
667-
def colors = logColours(monochrome_logs)
673+
674+
def String schemaFilename = options?.containsKey('parameters_schema') ? options.parameters_schema as String : 'nextflow_schema.json'
675+
def Boolean useMonochromeLogs = options?.containsKey('monochrome_logs') ? options.monochrome_logs as Boolean :
676+
params.monochrome_logs ? params.monochrome_logs as Boolean :
677+
params.monochromeLogs ? params.monochromeLogs as Boolean :
678+
false
679+
680+
def colors = logColours(useMonochromeLogs)
668681
Integer num_hidden = 0
669682
String output = ''
670683
output += 'Typical pipeline command:\n\n'
671684
output += " ${colors.cyan}${command}${colors.reset}\n\n"
672-
Map params_map = paramsLoad( Path.of(getSchemaPath(baseDir, schema_filename)) )
685+
Map params_map = paramsLoad( Path.of(getSchemaPath(baseDir, schemaFilename)) )
673686
Integer max_chars = paramsMaxChars(params_map) + 1
674687
Integer desc_indent = max_chars + 14
675688
Integer dec_linewidth = 160 - desc_indent
@@ -753,7 +766,7 @@ class SchemaValidator extends PluginExtensionPoint {
753766
// Groovy Map summarising parameters/workflow options used by the pipeline
754767
//
755768
@Function
756-
public LinkedHashMap paramsSummaryMap(WorkflowMetadata workflow, String schema_filename='nextflow_schema.json') {
769+
public LinkedHashMap paramsSummaryMap(WorkflowMetadata workflow, String schemaFilename='nextflow_schema.json') {
757770

758771
def String baseDir = session.baseDir
759772
def Map params = session.params
@@ -780,7 +793,7 @@ class SchemaValidator extends PluginExtensionPoint {
780793

781794
// Get pipeline parameters defined in JSON Schema
782795
def Map params_summary = [:]
783-
def Map params_map = paramsLoad( Path.of(getSchemaPath(baseDir, schema_filename)) )
796+
def Map params_map = paramsLoad( Path.of(getSchemaPath(baseDir, schemaFilename)) )
784797
for (group in params_map.keySet()) {
785798
def sub_params = new LinkedHashMap()
786799
def Map group_params = params_map.get(group) as Map // This gets the parameters of that particular group
@@ -828,15 +841,23 @@ class SchemaValidator extends PluginExtensionPoint {
828841
// Beautify parameters for summary and return as string
829842
//
830843
@Function
831-
public String paramsSummaryLog(WorkflowMetadata workflow, String schema_filename='nextflow_schema.json') {
844+
public String paramsSummaryLog(
845+
Map options = null,
846+
WorkflowMetadata workflow
847+
) {
832848

833849
def String baseDir = session.baseDir
834850
def Map params = session.params
835851

836-
def Boolean monochrome_logs = params.monochrome_logs
837-
def colors = logColours(monochrome_logs)
852+
def String schemaFilename = options?.containsKey('parameters_schema') ? options.parameters_schema as String : 'nextflow_schema.json'
853+
def Boolean useMonochromeLogs = options?.containsKey('monochrome_logs') ? options.monochrome_logs as Boolean :
854+
params.monochrome_logs ? params.monochrome_logs as Boolean :
855+
params.monochromeLogs ? params.monochromeLogs as Boolean :
856+
false
857+
858+
def colors = logColours(useMonochromeLogs)
838859
String output = ''
839-
def LinkedHashMap params_map = paramsSummaryMap(workflow, schema_filename)
860+
def LinkedHashMap params_map = paramsSummaryMap(workflow, schemaFilename)
840861
def max_chars = paramsMaxChars(params_map)
841862
for (group in params_map.keySet()) {
842863
def Map group_params = params_map.get(group) as Map // This gets the parameters of that particular group

plugins/nf-validation/src/test/nextflow/validation/PluginExtensionMethodsTest.groovy

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
8080
params.monochrome_logs = true
8181
include { validateParameters } from 'plugin/nf-validation'
8282
83-
validateParameters('src/testResources/nextflow_schema.json')
83+
validateParameters('src/testResources/nextflow_schema.json', monochrome_logs: params.monochrome_logs)
8484
"""
8585

8686
when:
@@ -226,7 +226,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
226226
params.validationFailUnrecognisedParams = true
227227
include { validateParameters } from 'plugin/nf-validation'
228228
229-
validateParameters('$schema')
229+
validateParameters('$schema', monochrome_logs: params.monochrome_logs)
230230
"""
231231

232232
when:
@@ -251,7 +251,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
251251
params.outdir = 10
252252
include { validateParameters } from 'plugin/nf-validation'
253253
254-
validateParameters('$schema')
254+
validateParameters('$schema', monochrome_logs: params.monochrome_logs)
255255
"""
256256

257257
when:
@@ -303,7 +303,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
303303
params.max_time = '10.day'
304304
include { validateParameters } from 'plugin/nf-validation'
305305
306-
validateParameters('$schema')
306+
validateParameters('$schema', monochrome_logs: params.monochrome_logs)
307307
"""
308308

309309
when:
@@ -378,7 +378,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
378378
params.max_cpus = 1.2
379379
include { validateParameters } from 'plugin/nf-validation'
380380
381-
validateParameters('$schema')
381+
validateParameters('$schema', monochrome_logs: params.monochrome_logs)
382382
"""
383383

384384
when:
@@ -404,7 +404,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
404404
params.max_memory = '10'
405405
include { validateParameters } from 'plugin/nf-validation'
406406
407-
validateParameters('$schema')
407+
validateParameters('$schema', monochrome_logs: params.monochrome_logs)
408408
"""
409409

410410
when:
@@ -432,7 +432,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
432432
433433
def command = "nextflow run <pipeline> --input samplesheet.csv --outdir <OUTDIR> -profile docker"
434434
435-
def help_msg = paramsHelp(command, '$schema')
435+
def help_msg = paramsHelp(command, parameters_schema: '$schema')
436436
log.info help_msg
437437
"""
438438

@@ -466,7 +466,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
466466
params.validationShowHiddenParams = true
467467
def command = "nextflow run <pipeline> --input samplesheet.csv --outdir <OUTDIR> -profile docker"
468468
469-
def help_msg = paramsHelp(command, '$schema')
469+
def help_msg = paramsHelp(command, parameters_schema: '$schema')
470470
log.info help_msg
471471
"""
472472

@@ -493,7 +493,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
493493
494494
def command = "nextflow run <pipeline> --input samplesheet.csv --outdir <OUTDIR> -profile docker"
495495
496-
def help_msg = paramsHelp(command, '$schema')
496+
def help_msg = paramsHelp(command, parameters_schema: '$schema')
497497
log.info help_msg
498498
"""
499499

@@ -526,7 +526,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
526526
527527
def command = "nextflow run <pipeline> --input samplesheet.csv --outdir <OUTDIR> -profile docker"
528528
529-
def help_msg = paramsHelp(command, '$schema')
529+
def help_msg = paramsHelp(command, parameters_schema: '$schema')
530530
log.info help_msg
531531
"""
532532

@@ -554,7 +554,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
554554
params.outdir = "outDir"
555555
include { paramsSummaryLog } from 'plugin/nf-validation'
556556
557-
def summary_params = paramsSummaryLog(workflow, '$schema')
557+
def summary_params = paramsSummaryLog(workflow, parameters_schema: '$schema')
558558
log.info summary_params
559559
"""
560560

@@ -616,7 +616,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
616616
params.input = 'src/testResources/samplesheet_wrong_pattern.csv'
617617
include { validateParameters } from 'plugin/nf-validation'
618618
619-
validateParameters('$schema')
619+
validateParameters('$schema', monochrome_logs: params.monochrome_logs)
620620
"""
621621

622622
when:
@@ -640,7 +640,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{
640640
params.input = 'src/testResources/samplesheet_no_required.csv'
641641
include { validateParameters } from 'plugin/nf-validation'
642642
643-
validateParameters('$schema')
643+
validateParameters('$schema', monochrome_logs: params.monochrome_logs)
644644
"""
645645

646646
when:

0 commit comments

Comments
 (0)