Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Mar 11, 2024
1 parent a90fd56 commit fbe5d5c
Show file tree
Hide file tree
Showing 7 changed files with 389 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2013-2024, Seqera Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package nextflow.config.scope.nextflow

import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString

/**
* Model nextflow default options
*
* @author Paolo Di Tommaso <[email protected]>
*/
@ToString(includePackage = false, includeNames = true)
@EqualsAndHashCode
@CompileStatic
class DefaultOpts {

final PublishDirOpts publishDir

DefaultOpts(Map opts) {
publishDir = new PublishDirOpts( opts.publishDir as Map ?: Map.of())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2013-2024, Seqera Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package nextflow.config.scope.nextflow

import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString

/**
* Model nextflow options
*
* @author Paolo Di Tommaso <[email protected]>
*/
@ToString(includePackage = false, includeNames = true)
@EqualsAndHashCode
@CompileStatic
class NextflowOpts {

final DefaultOpts defaults

NextflowOpts(Map<String,Object> opts) {
defaults = new DefaultOpts(opts.defaults as Map<String,Object> ?: Map.<String,Object>of())
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2013-2024, Seqera Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package nextflow.config.scope.nextflow

import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString

/**
* Model publishDir options
*
* @author Paolo Di Tommaso <[email protected]>
*/
@ToString(includePackage = false, includeNames = true)
@EqualsAndHashCode
@CompileStatic
class PublishDirOpts {

static final public PublishDirOpts EMPTY = new PublishDirOpts(Map.of())


final String mode
final Boolean enabled
final Boolean failOnError
final String pattern
final Object contentType
final Boolean overwrite
final String storageClass
final Map<String,String> tags

PublishDirOpts(Map opts) {
mode = opts.mode
enabled = asBool(opts.enabled)
failOnError = asBool(opts.failOnError)
overwrite = asBool(opts.overwrite)
pattern = opts.pattern
contentType = opts.contentType
storageClass = opts.storageClass
tags = opts.tags as Map<String,String>
}

private Boolean asBool(Object value) {
if( value==null )
return null
return Boolean.valueOf(value as String)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import groovy.util.logging.Slf4j
import nextflow.Global
import nextflow.NF
import nextflow.Session
import nextflow.config.scope.nextflow.PublishDirOpts
import nextflow.extension.FilesEx
import nextflow.file.FileHelper
import nextflow.file.TagAwareFile
Expand Down Expand Up @@ -178,41 +179,55 @@ class PublishDir {
* @return An instance of {@link PublishDir} class
*/
@CompileDynamic
static PublishDir create( Map params ) {
static PublishDir create( Map params, PublishDirOpts defaults=PublishDirOpts.EMPTY ) {
assert params

def result = new PublishDir()
if( params.path )
result.path = params.path

if( params.mode )
result.mode = params.mode
final mode = params.mode as String ?: defaults.mode
if( mode )
result.setMode(mode as String)

if( params.pattern )
result.pattern = params.pattern
final pattern = params.pattern ?: defaults.pattern
if( pattern )
result.pattern = pattern

if( params.overwrite != null )
result.overwrite = Boolean.parseBoolean(params.overwrite.toString())
final overwrite = params.overwrite!=null
? Boolean.parseBoolean(params.overwrite.toString())
: defaults.overwrite
if( overwrite != null )
result.overwrite = overwrite

if( params.saveAs )
result.saveAs = (Closure) params.saveAs

if( params.enabled != null )
result.enabled = Boolean.parseBoolean(params.enabled.toString())

if( params.failOnError != null )
result.failOnError = Boolean.parseBoolean(params.failOnError.toString())

if( params.tags != null )
result.tags = params.tags

if( params.contentType instanceof Boolean )
result.contentType = params.contentType
else if( params.contentType )
result.contentType = params.contentType as String

if( params.storageClass )
result.storageClass = params.storageClass as String
final enabled = params.enabled!=null
? Boolean.parseBoolean(params.enabled.toString())
: defaults.enabled
if( enabled != null )
result.enabled = enabled

final failOnError = params.failOnError!=null
? Boolean.parseBoolean(params.failOnError.toString())
: defaults.failOnError
if( failOnError != null )
result.failOnError = failOnError

final tags = params.tags ?: defaults.tags
if( tags != null )
result.tags = tags

final contentType = params.contentType!=null ? params.contentType : defaults.contentType
if( contentType instanceof Boolean )
result.contentType = contentType
else if( contentType )
result.contentType = contentType as String

final storageClass = params.storageClass as String ?: defaults.storageClass
if( storageClass )
result.storageClass = storageClass

return result
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2013-2024, Seqera Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package nextflow.config.scope.nextflow

import spock.lang.Specification

/**
*
* @author Paolo Di Tommaso <[email protected]>
*/
class DefaultOptsTest extends Specification {

def 'should validate equals and hashcode' () {
given:
def o1 = new DefaultOpts([publishDir: [mode:'foo']])
def o2 = new DefaultOpts([publishDir: [mode:'foo']])
def o3 = new DefaultOpts([publishDir: [mode:'bar']])

expect:
o1 == o2
o1 != o3
and:
o1.hashCode() == o2.hashCode()
o1.hashCode() != o3.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2013-2024, Seqera Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package nextflow.config.scope.nextflow

import spock.lang.Specification

/**
*
* @author Paolo Di Tommaso <[email protected]>
*/
class NextflowOptsTest extends Specification {

def 'should validate equals and hashcode' () {
given:
def o1 = new NextflowOpts([defaults: [publishDir: [mode:'foo']]])
def o2 = new NextflowOpts([defaults: [publishDir: [mode:'foo']]])
def o3 = new NextflowOpts([defaults: [publishDir: [mode:'bar']]])

expect:
o1 == o2
o1 != o3
and:
o1.hashCode() == o2.hashCode()
o1.hashCode() != o3.hashCode()
}

def 'should create empty nextflow opts' () {
when:
def nextflow = new NextflowOpts([:])
then:
!nextflow.defaults.publishDir.enabled
!nextflow.defaults.publishDir.mode
!nextflow.defaults.publishDir.failOnError
!nextflow.defaults.publishDir.contentType
!nextflow.defaults.publishDir.overwrite
!nextflow.defaults.publishDir.contentType
!nextflow.defaults.publishDir.storageClass
!nextflow.defaults.publishDir.tags
}

def 'should create nextflow publishdir opts' () {
when:
def nextflow = new NextflowOpts([
defaults: [
publishDir: [
mode:'foo',
enabled: 'true',
failOnError: 'true',
contentType: 'some-content',
overwrite: 'true',
storageClass: 'some-storage',
tags: ['this':'one', 'that': 'two']
]
]])
then:
nextflow.defaults.publishDir.mode == 'foo'
nextflow.defaults.publishDir.enabled
nextflow.defaults.publishDir.failOnError
nextflow.defaults.publishDir.contentType == 'some-content'
nextflow.defaults.publishDir.overwrite
nextflow.defaults.publishDir.storageClass == 'some-storage'
nextflow.defaults.publishDir.tags == ['this':'one', 'that': 'two']
}

}
Loading

0 comments on commit fbe5d5c

Please sign in to comment.