From 935bb1e59ce4a73d521743ad3e41704e4218acad Mon Sep 17 00:00:00 2001
From: greenberga <38597857+greenberga@users.noreply.github.com>
Date: Thu, 16 May 2024 14:48:42 -0400
Subject: [PATCH] Add 'preview' to workflow runtime metadata (#4985)
Signed-off-by: Aaron Greenberg
Signed-off-by: Paolo Di Tommaso
Co-authored-by: Paolo Di Tommaso
---
docs/metadata.md | 5 +++++
.../src/main/groovy/nextflow/Session.groovy | 8 ++++++++
.../groovy/nextflow/config/ConfigBuilder.groovy | 3 +++
.../nextflow/script/WorkflowMetadata.groovy | 6 ++++++
.../nextflow/config/ConfigBuilderTest.groovy | 17 ++++++++++++++++-
.../nextflow/script/WorkflowMetadataTest.groovy | 3 +++
6 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/docs/metadata.md b/docs/metadata.md
index 193396be09..4fdc3faeb2 100644
--- a/docs/metadata.md
+++ b/docs/metadata.md
@@ -73,6 +73,11 @@ The following table lists the properties that can be accessed on the `workflow`
`workflow.manifest`
: Entries of the workflow manifest.
+`workflow.preview`
+: :::{versionadded} 24.04.0
+ :::
+: Returns `true` whenever the current instance is a preview execution.
+
`workflow.profile`
: Used configuration profile.
diff --git a/modules/nextflow/src/main/groovy/nextflow/Session.groovy b/modules/nextflow/src/main/groovy/nextflow/Session.groovy
index ccc99fc379..fc52baf840 100644
--- a/modules/nextflow/src/main/groovy/nextflow/Session.groovy
+++ b/modules/nextflow/src/main/groovy/nextflow/Session.groovy
@@ -153,6 +153,11 @@ class Session implements ISession {
*/
boolean stubRun
+ /**
+ * Enable preview mode
+ */
+ boolean preview
+
/**
* Folder(s) containing libs and classes to be added to the classpath
*/
@@ -345,6 +350,9 @@ class Session implements ISession {
// -- dry run
this.stubRun = config.stubRun
+ // -- preview
+ this.preview = config.preview
+
// -- normalize taskConfig object
if( config.process == null ) config.process = [:]
if( config.env == null ) config.env = [:]
diff --git a/modules/nextflow/src/main/groovy/nextflow/config/ConfigBuilder.groovy b/modules/nextflow/src/main/groovy/nextflow/config/ConfigBuilder.groovy
index 13ec5f0bf2..08d5f3f011 100644
--- a/modules/nextflow/src/main/groovy/nextflow/config/ConfigBuilder.groovy
+++ b/modules/nextflow/src/main/groovy/nextflow/config/ConfigBuilder.groovy
@@ -545,6 +545,9 @@ class ConfigBuilder {
if( cmdRun.stubRun )
config.stubRun = cmdRun.stubRun
+ if( cmdRun.preview )
+ config.preview = cmdRun.preview
+
// -- sets the working directory
if( cmdRun.workDir )
config.workDir = cmdRun.workDir
diff --git a/modules/nextflow/src/main/groovy/nextflow/script/WorkflowMetadata.groovy b/modules/nextflow/src/main/groovy/nextflow/script/WorkflowMetadata.groovy
index a053212216..9a8fe29421 100644
--- a/modules/nextflow/src/main/groovy/nextflow/script/WorkflowMetadata.groovy
+++ b/modules/nextflow/src/main/groovy/nextflow/script/WorkflowMetadata.groovy
@@ -189,6 +189,11 @@ class WorkflowMetadata {
*/
boolean stubRun
+ /**
+ * Returns ``true`` whenever the current instance is in preview mode
+ */
+ boolean preview
+
/**
* Which container engine was used to execute the workflow
*/
@@ -253,6 +258,7 @@ class WorkflowMetadata {
this.sessionId = session.uniqueId
this.resume = session.resumeMode
this.stubRun = session.stubRun
+ this.preview = session.preview
this.runName = session.runName
this.containerEngine = containerEngine0(session)
this.configFiles = session.configFiles?.collect { it.toAbsolutePath() }
diff --git a/modules/nextflow/src/test/groovy/nextflow/config/ConfigBuilderTest.groovy b/modules/nextflow/src/test/groovy/nextflow/config/ConfigBuilderTest.groovy
index 6a5114ffa9..d670ad1286 100644
--- a/modules/nextflow/src/test/groovy/nextflow/config/ConfigBuilderTest.groovy
+++ b/modules/nextflow/src/test/groovy/nextflow/config/ConfigBuilderTest.groovy
@@ -1873,7 +1873,22 @@ class ConfigBuilderTest extends Specification {
then:
config.stubRun == true
}
-
+
+ def 'should configure preview mode' () {
+ given:
+ Map config
+
+ when:
+ config = new ConfigBuilder().setCmdRun(new CmdRun()).build()
+ then:
+ !config.preview
+
+ when:
+ config = new ConfigBuilder().setCmdRun(new CmdRun(preview: true)).build()
+ then:
+ config.preview == true
+ }
+
def 'should merge profiles' () {
given:
def ENV = [:]
diff --git a/modules/nextflow/src/test/groovy/nextflow/script/WorkflowMetadataTest.groovy b/modules/nextflow/src/test/groovy/nextflow/script/WorkflowMetadataTest.groovy
index edf6d8459c..0220477697 100644
--- a/modules/nextflow/src/test/groovy/nextflow/script/WorkflowMetadataTest.groovy
+++ b/modules/nextflow/src/test/groovy/nextflow/script/WorkflowMetadataTest.groovy
@@ -96,6 +96,7 @@ class WorkflowMetadataTest extends Specification {
metadata.configFiles == [Paths.get('foo').toAbsolutePath(), Paths.get('bar').toAbsolutePath()]
metadata.resume == false
metadata.stubRun == false
+ metadata.preview == false
metadata.userName == System.getProperty('user.name')
metadata.homeDir == Paths.get(System.getProperty('user.home'))
metadata.manifest.version == '1.0.0'
@@ -114,11 +115,13 @@ class WorkflowMetadataTest extends Specification {
session.profile >> 'foo_profile'
session.resumeMode >> true
session.stubRun >> true
+ session.preview >> true
metadata = new WorkflowMetadata(session, script)
then:
metadata.profile == 'foo_profile'
metadata.resume
metadata.stubRun
+ metadata.preview
}
def foo_test_method() {