Skip to content

Commit 0aa76af

Browse files
Include all processes in inspect command (#5580)
Signed-off-by: Ben Sherman <[email protected]> Signed-off-by: Paolo Di Tommaso <[email protected]> Co-authored-by: Paolo Di Tommaso <[email protected]>
1 parent b325378 commit 0aa76af

File tree

7 files changed

+62
-54
lines changed

7 files changed

+62
-54
lines changed

modules/nextflow/src/main/groovy/nextflow/cli/CmdInspect.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class CmdInspect extends CmdBase {
9292

9393
protected void applyInspect(Session session) {
9494
// run the inspector
95-
new ContainersInspector(session.dag, concretize)
95+
new ContainersInspector(concretize)
9696
.withFormat(format)
9797
.withIgnoreErrors(ignoreErrors)
9898
.printContainers()

modules/nextflow/src/main/groovy/nextflow/container/ContainerHandler.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,4 @@ class ContainerHandler {
308308
// in all other case it's supposed to be the name of an image
309309
return "${normalizeDockerImageName(img)}"
310310
}
311-
}
311+
}

modules/nextflow/src/main/groovy/nextflow/container/inspect/ContainersInspector.groovy

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import groovy.json.JsonBuilder
2424
import groovy.json.JsonOutput
2525
import groovy.transform.CompileStatic
2626
import groovy.util.logging.Slf4j
27-
import nextflow.dag.DAG
2827
import nextflow.exception.AbortOperationException
2928
import nextflow.processor.TaskRun
29+
import nextflow.script.ScriptMeta
3030
import org.codehaus.groovy.util.ListHashMap
3131
/**
3232
* Preview the list of containers used by a pipeline.
@@ -37,16 +37,13 @@ import org.codehaus.groovy.util.ListHashMap
3737
@CompileStatic
3838
class ContainersInspector {
3939

40-
private DAG dag
41-
4240
private String format
4341

4442
private boolean ignoreErrors
4543

4644
private boolean concretize
4745

48-
ContainersInspector(DAG dag, boolean concretize) {
49-
this.dag = dag
46+
ContainersInspector(boolean concretize) {
5047
this.concretize = concretize
5148
}
5249

@@ -83,15 +80,10 @@ class ContainersInspector {
8380
final containers = new ListHashMap<String,String>()
8481

8582
List<TaskRun> tasks = new ArrayList<>()
86-
for( def vertex : dag.vertices ) {
87-
// skip nodes that are not processes
88-
final process = vertex.process
89-
if( !process )
90-
continue
91-
83+
for( final process : ScriptMeta.allProcesses() ) {
9284
try {
9385
// get container preview
94-
final task = process.createTaskPreview()
86+
final task = process.createTaskProcessor().createTaskPreview()
9587
final containerName = task.getContainer()
9688
containers[process.name] = containerName
9789
if( containerName )

modules/nextflow/src/main/groovy/nextflow/script/ProcessDef.groovy

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import nextflow.Global
2323
import nextflow.Session
2424
import nextflow.exception.ScriptRuntimeException
2525
import nextflow.extension.CH
26+
import nextflow.processor.TaskProcessor
2627
import nextflow.script.params.BaseInParam
2728
import nextflow.script.params.BaseOutParam
2829
import nextflow.script.params.EachInParam
@@ -208,20 +209,23 @@ class ProcessDef extends BindableDef implements IterableDef, ChainableDef {
208209
// make a copy of the output list because execution can change it
209210
output = new ChannelOut(declaredOutputs.clone())
210211

211-
// create the executor
212-
final executor = session
213-
.executorFactory
214-
.getExecutor(processName, processConfig, taskBody, session)
215-
216-
// create processor class
217-
session
218-
.newProcessFactory(owner)
219-
.newTaskProcessor(processName, executor, processConfig, taskBody)
220-
.run()
212+
// start processor
213+
createTaskProcessor().run()
221214

222215
// the result channels
223216
assert declaredOutputs.size()>0, "Process output should contains at least one channel"
224217
return output
225218
}
226219

220+
TaskProcessor createTaskProcessor() {
221+
if( !processConfig )
222+
initialize()
223+
final executor = session
224+
.executorFactory
225+
.getExecutor(processName, processConfig, taskBody, session)
226+
return session
227+
.newProcessFactory(owner)
228+
.newTaskProcessor(processName, executor, processConfig, taskBody)
229+
}
230+
227231
}

modules/nextflow/src/main/groovy/nextflow/script/ScriptMeta.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ class ScriptMeta {
7070
return result
7171
}
7272

73+
static Set<ProcessDef> allProcesses() {
74+
final result = new HashSet()
75+
for( final entry : REGISTRY.values() ) {
76+
final processes = entry.getDefinitions().findAll { d -> d instanceof ProcessDef }
77+
result.addAll(processes)
78+
}
79+
return result
80+
}
81+
7382
static void addResolvedName(String name) {
7483
resolvedProcessNames.add(name)
7584
}

modules/nextflow/src/main/groovy/nextflow/script/ScriptRunner.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import groovy.transform.PackageScope
2525
import groovy.util.logging.Slf4j
2626
import nextflow.Global
2727
import nextflow.Session
28+
import nextflow.container.inspect.ContainerInspectMode
2829
import nextflow.exception.AbortOperationException
2930
import nextflow.exception.AbortRunException
3031
import nextflow.plugin.Plugins
@@ -226,6 +227,8 @@ class ScriptRunner {
226227
protected void parseScript( ScriptFile scriptFile, String entryName ) {
227228
scriptParser = new ScriptParser(session)
228229
.setEntryName(entryName)
230+
// setting module true when running in "inspect" mode to prevent the running the entry workflow
231+
.setModule(ContainerInspectMode.active())
229232
.parse(scriptFile.main)
230233
session.script = scriptParser.script
231234
}

modules/nextflow/src/test/groovy/nextflow/container/inspect/ContainersInspectorTest.groovy

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,46 @@
1717

1818
package nextflow.container.inspect
1919

20-
21-
import nextflow.dag.DAG
20+
import nextflow.NF
2221
import nextflow.processor.TaskProcessor
2322
import nextflow.processor.TaskRun
23+
import nextflow.script.BaseScript
24+
import nextflow.script.ProcessDef
25+
import nextflow.script.ScriptMeta
2426
import spock.lang.Specification
2527
/**
2628
*
2729
* @author Ben Sherman <[email protected]>
2830
*/
2931
class ContainersInspectorTest extends Specification {
3032

31-
def makeVertex(DAG dag, String name, String container) {
32-
final processor = Mock(TaskProcessor)
33-
processor.name >> name
34-
processor.createTaskPreview() >> Mock(TaskRun) {
35-
getContainer() >> container
36-
}
37-
38-
final vertex = new DAG.Vertex(dag, DAG.Type.PROCESS)
39-
vertex.process = processor
33+
def setup() {
34+
ScriptMeta.reset()
35+
NF.init()
36+
}
4037

41-
return vertex
38+
def makeProcess(String name, String container) {
39+
final script = new BaseScript() {
40+
Object runScript() {}
41+
}
42+
final processDef = Mock(ProcessDef) {
43+
getName() >> name
44+
createTaskProcessor() >> Mock(TaskProcessor) {
45+
createTaskPreview() >> Mock(TaskRun) {
46+
getContainer() >> container
47+
}
48+
}
49+
}
50+
ScriptMeta.get(script).addDefinition(processDef)
4251
}
4352

4453
def 'should get containers' () {
4554
given:
46-
def dag = Mock(DAG)
47-
dag.vertices >> [
48-
makeVertex(dag, 'proc1', 'container1'),
49-
makeVertex(dag, 'proc2', 'container2')
50-
]
55+
makeProcess('proc1', 'container1')
56+
makeProcess('proc2', 'container2')
5157

5258
when:
53-
def observer = new ContainersInspector(dag, false)
59+
def observer = new ContainersInspector(false)
5460
then:
5561
observer.getContainers() == [
5662
'proc1': 'container1',
@@ -60,14 +66,11 @@ class ContainersInspectorTest extends Specification {
6066

6167
def 'should render containers as json' () {
6268
given:
63-
def dag = Mock(DAG)
64-
dag.vertices >> [
65-
makeVertex(dag, 'proc1', 'container1'),
66-
makeVertex(dag, 'proc2', 'container2')
67-
]
69+
makeProcess('proc1', 'container1')
70+
makeProcess('proc2', 'container2')
6871

6972
when:
70-
def result = new ContainersInspector(dag, false)
73+
def result = new ContainersInspector(false)
7174
.withFormat('json')
7275
.renderContainers()
7376
then:
@@ -89,14 +92,11 @@ class ContainersInspectorTest extends Specification {
8992

9093
def 'should render containers as nextflow config' () {
9194
given:
92-
def dag = Mock(DAG)
93-
dag.vertices >> [
94-
makeVertex(dag, 'proc1', 'container1'),
95-
makeVertex(dag, 'proc2', 'container2')
96-
]
95+
makeProcess('proc1', 'container1')
96+
makeProcess('proc2', 'container2')
9797

9898
when:
99-
def result = new ContainersInspector(dag,false)
99+
def result = new ContainersInspector(false)
100100
.withFormat('config')
101101
.renderContainers()
102102
then:

0 commit comments

Comments
 (0)