Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: code to enable dsl1 in 23.10.0 #25

Open
wants to merge 2 commits into
base: 23.10.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ temp
plugins-prod
sandbox
wave-tests
.DS_Store
14 changes: 8 additions & 6 deletions modules/nextflow/src/main/groovy/nextflow/NextflowMeta.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ class NextflowMeta {
boolean recursion

void setDsl( float num ) {
if( num == 1 )
throw new IllegalArgumentException(DSL1_EOL_MESSAGE)
if( num != 2 )
// if( num == 1 )
// throw new IllegalArgumentException(DSL1_EOL_MESSAGE)
// if( num != 2 )
if( num != 2 && num != 1 )
throw new IllegalArgumentException("Not a valid DSL version number: $num")
if( num == 2 && !ignoreWarnDsl2 )
log.warn1 "DSL 2 PREVIEW MODE IS DEPRECATED - USE THE STABLE VERSION INSTEAD. Read more at https://www.nextflow.io/docs/latest/dsl2.html#dsl2-migration-notes"
Expand Down Expand Up @@ -148,9 +149,10 @@ class NextflowMeta {
}

void enableDsl(String value) {
if( value == '1' )
throw new AbortOperationException(DSL1_EOL_MESSAGE)
if( value != '2' ) {
// if( value == '1' )
// throw new AbortOperationException(DSL1_EOL_MESSAGE)
// if( value != '2' ) {
if( value !in ['1','2'] ) {
throw new AbortOperationException("Invalid Nextflow DSL value: $value")
}
this.enable.dsl = value=='1' ? 1f : 2f
Expand Down
41 changes: 36 additions & 5 deletions modules/nextflow/src/main/groovy/nextflow/script/BaseScript.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package nextflow.script

import groovy.transform.PackageScope
import nextflow.processor.TaskProcessor

import java.lang.reflect.InvocationTargetException
import java.nio.file.Paths

Expand All @@ -32,6 +35,8 @@ import nextflow.exception.AbortOperationException
@Slf4j
abstract class BaseScript extends Script implements ExecutionContext {

private TaskProcessor taskProcessor

private Session session

private ProcessFactory processFactory
Expand All @@ -56,13 +61,22 @@ abstract class BaseScript extends Script implements ExecutionContext {
(ScriptBinding)super.getBinding()
}

/**
* Access to the last *process* object -- only for testing purpose
*/
@PackageScope
TaskProcessor getTaskProcessor() { taskProcessor }

/**
* Holds the configuration object which will used to execution the user tasks
*/
@Deprecated
protected Map getConfig() {
final msg = "The access of `config` object is deprecated"
throw new DeprecationException(msg)
if( NF.dsl2 )
throw new DeprecationException(msg)
log.warn(msg)
session.getConfig()
}

/**
Expand Down Expand Up @@ -95,7 +109,9 @@ abstract class BaseScript extends Script implements ExecutionContext {
meta.addDefinition(process)
}
else {
throw new UnsupportedOperationException("DSL1 is not supported anymore")
// legacy process definition an execution
taskProcessor = processFactory.createProcessor(name, body)
taskProcessor.run()
}
}

Expand All @@ -106,6 +122,8 @@ abstract class BaseScript extends Script implements ExecutionContext {
* @return The result of workflow execution
*/
protected workflow(Closure<BodyDef> workflowBody) {
if(!NF.isDsl2())
throw new IllegalStateException("Module feature not enabled -- Set `nextflow.enable.dsl=2` to allow the definition of workflow components")
// launch the execution
final workflow = new WorkflowDef(this, workflowBody)
// capture the main (unnamed) workflow definition
Expand All @@ -120,6 +138,8 @@ abstract class BaseScript extends Script implements ExecutionContext {
}

protected IncludeDef include( IncludeDef include ) {
if(!NF.isDsl2())
throw new IllegalStateException("Module feature not enabled -- Set `nextflow.enable.dsl=2` to import module files")
if(ExecutionStack.withinWorkflow())
throw new IllegalStateException("Include statement is not allowed within a workflow definition")
include .setSession(session)
Expand All @@ -137,10 +157,20 @@ abstract class BaseScript extends Script implements ExecutionContext {
*/
@Override
Object invokeMethod(String name, Object args) {
binding.invokeMethod(name, args)
if(NF.isDsl2())
binding.invokeMethod(name, args)
else
super.invokeMethod(name, args)
}

private runDsl1() {
session.notifyBeforeWorkflowExecution()
final ret = runScript()
session.notifyAfterWorkflowExecution()
return ret
}

private run0() {
private runDsl2() {
final result = runScript()
if( meta.isModule() ) {
return result
Expand Down Expand Up @@ -189,7 +219,8 @@ abstract class BaseScript extends Script implements ExecutionContext {
setup()
ExecutionStack.push(this)
try {
run0()
// run0()
NF.dsl2 ? runDsl2() : runDsl1()
}
catch( InvocationTargetException e ) {
// provide the exception cause which is more informative than InvocationTargetException
Expand Down
Loading