From e7aa3a718f2ce3569215e6be4bf8c2cd1be3f758 Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Wed, 11 Dec 2024 13:32:47 -0600 Subject: [PATCH] Apply suggestions from review Signed-off-by: Ben Sherman --- .../nextflow/src/main/groovy/nextflow/cli/CmdInspect.groovy | 3 ++- .../main/groovy/nextflow/container/ContainerHandler.groovy | 6 +++--- .../nextflow/container/inspect/ContainerInspectMode.groovy | 6 ++++++ .../nextflow/container/inspect/ContainersInspector.groovy | 2 +- .../src/main/groovy/nextflow/script/ProcessDef.groovy | 4 ++-- .../src/main/groovy/nextflow/script/ScriptRunner.groovy | 5 +++-- .../container/inspect/ContainersInspectorTest.groovy | 2 +- .../src/main/io/seqera/wave/plugin/WaveClient.groovy | 4 ++-- .../src/test/io/seqera/wave/plugin/WaveClientTest.groovy | 4 ++-- 9 files changed, 22 insertions(+), 14 deletions(-) diff --git a/modules/nextflow/src/main/groovy/nextflow/cli/CmdInspect.groovy b/modules/nextflow/src/main/groovy/nextflow/cli/CmdInspect.groovy index 3a61e69cb9..c4e096a02a 100644 --- a/modules/nextflow/src/main/groovy/nextflow/cli/CmdInspect.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/cli/CmdInspect.groovy @@ -70,7 +70,8 @@ class CmdInspect extends CmdBase { @Override void run() { - ContainerInspectMode.activate(!concretize) + ContainerInspectMode.activate(true) + ContainerInspectMode.concretize(concretize) // configure quiet mode LoggerHelper.setQuiet(true) // setup the target run command diff --git a/modules/nextflow/src/main/groovy/nextflow/container/ContainerHandler.groovy b/modules/nextflow/src/main/groovy/nextflow/container/ContainerHandler.groovy index 96c0931e45..69ff7ae64f 100644 --- a/modules/nextflow/src/main/groovy/nextflow/container/ContainerHandler.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/container/ContainerHandler.groovy @@ -70,7 +70,7 @@ class ContainerHandler { if( normalizedImageName.startsWith('docker://') && config.canRunOciImage() ) return normalizedImageName final requiresCaching = normalizedImageName =~ IMAGE_URL_PREFIX - if( ContainerInspectMode.active() && requiresCaching ) + if( ContainerInspectMode.concretizeEnabled() && requiresCaching ) return imageName final result = requiresCaching ? createSingularityCache(this.config, normalizedImageName) : normalizedImageName return Escape.path(result) @@ -82,7 +82,7 @@ class ContainerHandler { if( normalizedImageName.startsWith('docker://') && config.canRunOciImage() ) return normalizedImageName final requiresCaching = normalizedImageName =~ IMAGE_URL_PREFIX - if( ContainerInspectMode.active() && requiresCaching ) + if( ContainerInspectMode.concretizeEnabled() && requiresCaching ) return imageName final result = requiresCaching ? createApptainerCache(this.config, normalizedImageName) : normalizedImageName return Escape.path(result) @@ -94,7 +94,7 @@ class ContainerHandler { // if the imagename starts with '/' it's an absolute path // otherwise we assume it's in a remote registry and pull it from there final requiresCaching = !imageName.startsWith('/') - if( ContainerInspectMode.active() && requiresCaching ) + if( ContainerInspectMode.concretizeEnabled() && requiresCaching ) return imageName final result = requiresCaching ? createCharliecloudCache(this.config, normalizedImageName) : normalizedImageName return Escape.path(result) diff --git a/modules/nextflow/src/main/groovy/nextflow/container/inspect/ContainerInspectMode.groovy b/modules/nextflow/src/main/groovy/nextflow/container/inspect/ContainerInspectMode.groovy index 4b3904e5db..e69f4987fc 100644 --- a/modules/nextflow/src/main/groovy/nextflow/container/inspect/ContainerInspectMode.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/container/inspect/ContainerInspectMode.groovy @@ -28,8 +28,14 @@ class ContainerInspectMode { private static Boolean active + private static Boolean concretize = true + static boolean active() { return active==true } static void activate(boolean value) { active = value } + static boolean concretizeEnabled() { return concretize==true } + + static void concretize(boolean value) { concretize = value } + } diff --git a/modules/nextflow/src/main/groovy/nextflow/container/inspect/ContainersInspector.groovy b/modules/nextflow/src/main/groovy/nextflow/container/inspect/ContainersInspector.groovy index 4b39c6bbdc..f293323701 100644 --- a/modules/nextflow/src/main/groovy/nextflow/container/inspect/ContainersInspector.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/container/inspect/ContainersInspector.groovy @@ -83,7 +83,7 @@ class ContainersInspector { for( final process : ScriptMeta.allProcesses() ) { try { // get container preview - final task = process.getTaskProcessor().createTaskPreview() + final task = process.createTaskProcessor().createTaskPreview() final containerName = task.getContainer() containers[process.name] = containerName if( containerName ) diff --git a/modules/nextflow/src/main/groovy/nextflow/script/ProcessDef.groovy b/modules/nextflow/src/main/groovy/nextflow/script/ProcessDef.groovy index aa5b83eea9..fc537c46e4 100644 --- a/modules/nextflow/src/main/groovy/nextflow/script/ProcessDef.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/script/ProcessDef.groovy @@ -210,14 +210,14 @@ class ProcessDef extends BindableDef implements IterableDef, ChainableDef { output = new ChannelOut(declaredOutputs.clone()) // start processor - getTaskProcessor().run() + createTaskProcessor().run() // the result channels assert declaredOutputs.size()>0, "Process output should contains at least one channel" return output } - TaskProcessor getTaskProcessor() { + TaskProcessor createTaskProcessor() { if( !processConfig ) initialize() final executor = session diff --git a/modules/nextflow/src/main/groovy/nextflow/script/ScriptRunner.groovy b/modules/nextflow/src/main/groovy/nextflow/script/ScriptRunner.groovy index 59a098872a..9d8c6dc66b 100644 --- a/modules/nextflow/src/main/groovy/nextflow/script/ScriptRunner.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/script/ScriptRunner.groovy @@ -25,6 +25,7 @@ import groovy.transform.PackageScope import groovy.util.logging.Slf4j import nextflow.Global import nextflow.Session +import nextflow.container.inspect.ContainerInspectMode import nextflow.exception.AbortOperationException import nextflow.exception.AbortRunException import nextflow.plugin.Plugins @@ -226,8 +227,8 @@ class ScriptRunner { protected void parseScript( ScriptFile scriptFile, String entryName ) { scriptParser = new ScriptParser(session) scriptParser.setEntryName(entryName) - // don't execute entry workflow if preview action (i.e. inspect command) is specified - if( previewAction ) + // don't execute entry workflow in the inspect command + if( ContainerInspectMode.acitve() ) scriptParser.setModule(true) scriptParser.parse(scriptFile.main) session.script = scriptParser.script diff --git a/modules/nextflow/src/test/groovy/nextflow/container/inspect/ContainersInspectorTest.groovy b/modules/nextflow/src/test/groovy/nextflow/container/inspect/ContainersInspectorTest.groovy index 4a7a7df8ee..8234ede231 100644 --- a/modules/nextflow/src/test/groovy/nextflow/container/inspect/ContainersInspectorTest.groovy +++ b/modules/nextflow/src/test/groovy/nextflow/container/inspect/ContainersInspectorTest.groovy @@ -41,7 +41,7 @@ class ContainersInspectorTest extends Specification { } final processDef = Mock(ProcessDef) { getName() >> name - getTaskProcessor() >> Mock(TaskProcessor) { + createTaskProcessor() >> Mock(TaskProcessor) { createTaskPreview() >> Mock(TaskRun) { getContainer() >> container } diff --git a/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy b/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy index c3640ce42d..bfb35978ce 100644 --- a/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy +++ b/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy @@ -222,7 +222,7 @@ class WaveClient { fingerprint: assets.fingerprint(), freeze: config.freezeMode(), format: assets.singularity ? 'sif' : null, - dryRun: ContainerInspectMode.active(), + dryRun: ContainerInspectMode.concretizeEnabled(), mirror: config.mirrorMode(), scanMode: config.scanMode(), scanLevels: config.scanAllowedLevels() @@ -249,7 +249,7 @@ class WaveClient { towerEndpoint: tower.endpoint, workflowId: tower.workflowId, freeze: config.freezeMode(), - dryRun: ContainerInspectMode.active(), + dryRun: ContainerInspectMode.concretizeEnabled(), mirror: config.mirrorMode(), scanMode: config.scanMode(), scanLevels: config.scanAllowedLevels() diff --git a/plugins/nf-wave/src/test/io/seqera/wave/plugin/WaveClientTest.groovy b/plugins/nf-wave/src/test/io/seqera/wave/plugin/WaveClientTest.groovy index 1f54b0a3d7..a3df255755 100644 --- a/plugins/nf-wave/src/test/io/seqera/wave/plugin/WaveClientTest.groovy +++ b/plugins/nf-wave/src/test/io/seqera/wave/plugin/WaveClientTest.groovy @@ -285,7 +285,7 @@ class WaveClientTest extends Specification { def 'should create request object with dry-run mode' () { given: - ContainerInspectMode.activate(true) + ContainerInspectMode.concretize(false) def session = Mock(Session) { getConfig() >> [:]} def IMAGE = 'foo:latest' def wave = new WaveClient(session) @@ -306,7 +306,7 @@ class WaveClientTest extends Specification { req.timestamp instanceof String cleanup: - ContainerInspectMode.activate(false) + ContainerInspectMode.concretize(true) } def 'should create request object and platform' () {