Skip to content

Commit

Permalink
Dx green with nf-core/rnaseq
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed Sep 14, 2020
1 parent 22a0ff3 commit 8dc0adf
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 19 deletions.
Expand Up @@ -441,6 +441,10 @@ class BashWrapperBuilder {
throw new IllegalArgumentException("Unknown container engine: $engine")
}

protected boolean getAllowContainerMounts() {
return true
}

/**
* Build a {@link DockerBuilder} object to handle Docker commands
*
Expand All @@ -458,16 +462,18 @@ class BashWrapperBuilder {
* initialise the builder
*/
// do not mount inputs when they are copied in the task work dir -- see #1105
if( stageInMode != 'copy' )
if( stageInMode != 'copy' && allowContainerMounts )
builder.addMountForInputs(inputFiles)

builder.addMount(binDir)
if( allowContainerMounts )
builder.addMount(binDir)

if(this.containerMount)
builder.addMount(containerMount)

// task work dir
builder.setWorkDir(workDir)
if( allowContainerMounts )
builder.setWorkDir(workDir)

// set the name
builder.setName('$NXF_BOXID')
Expand Down
Expand Up @@ -59,7 +59,7 @@ class AwsBatchFileCopyStrategy extends SimpleFileCopyStrategy {
@Override
String getEnvScript(Map environment, boolean container) {
if( container )
throw new IllegalArgumentException("Parameter `wrapHandler` not supported by ${this.class.simpleName}")
throw new IllegalArgumentException("Parameter `container` not supported by ${this.class.simpleName}")

final result = new StringBuilder()
final copy = environment ? new HashMap<String,String>(environment) : Collections.<String,String>emptyMap()
Expand Down
@@ -0,0 +1,45 @@
package nextflow.cloud.aws.util

import nextflow.file.FileHelper
import spock.lang.Specification
import spock.lang.Unroll

/**
*
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com>
*/
class S3PathTest extends Specification {

@Unroll
def 'should convert to uri string' () {

expect:
FileHelper.asPath(PATH).toUriString() == STR

where:
_ | PATH | STR
_ | 's3://foo' | 's3://foo/'
_ | 's3://foo/bar' | 's3://foo/bar'
_ | 's3://foo/b a r' | 's3://foo/b a r'
_ | 's3://f o o/bar' | 's3://f o o/bar'
_ | 's3://f_o_o/bar' | 's3://f_o_o/bar'

}

@Unroll
def 'should convert to string' () {

expect:
FileHelper.asPath(PATH).toString() == STR

where:
_ | PATH | STR
_ | 's3://foo' | '/foo/'
_ | 's3://foo/bar' | '/foo/bar'
_ | 's3://foo/b a r' | '/foo/b a r'
_ | 's3://f o o/bar' | '/f o o/bar'
_ | 's3://f_o_o/bar' | '/f_o_o/bar'

}

}
13 changes: 6 additions & 7 deletions modules/nf-commons/src/main/nextflow/extension/FilesEx.groovy
Expand Up @@ -17,8 +17,7 @@

package nextflow.extension

import org.codehaus.groovy.runtime.InvokerHelper
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
import static java.nio.file.StandardCopyOption.*

import java.nio.ByteBuffer
import java.nio.channels.SeekableByteChannel
Expand All @@ -43,6 +42,7 @@ import groovy.transform.stc.ClosureParams
import groovy.transform.stc.FromString
import groovy.util.logging.Slf4j
import nextflow.file.FileHelper
import nextflow.file.FileSystemPathFactory
import nextflow.io.ByteBufferBackedInputStream
import nextflow.util.CharsetHelper
import nextflow.util.CheckHelper
Expand Down Expand Up @@ -1492,11 +1492,10 @@ class FilesEx {
return path.toString()
if( scheme == 's3' )
return "$scheme:/$path".toString()
if( scheme == 'gs' ) {
final bucket = InvokerHelper.invokeMethod(path, 'bucket', InvokerHelper.EMPTY_ARGS)
return "$scheme://$bucket$path".toString()
}
return path.toUri().toString()
//
final result = FileSystemPathFactory.getUriString(path)
//
return result ?: path.toUri().toString()
}

static String getScheme(Path path) {
Expand Down
Expand Up @@ -29,10 +29,29 @@ import groovy.transform.Memoized
@CompileStatic
abstract class FileSystemPathFactory {

/**
* Converts path uri string to the corresponding {@link Path} object
*
* @param uri
* A fully qualified path uri including the protocol scheme
* @return
* A {@link Path} for the given path or {@code null} if protocol is unknown
*/
abstract protected Path parseUri(String uri)

/**
* Converts a {@link Path} object to a fully qualified uri string
*
* @param path
* The {@link Path} object to be converted
* @return
* The uri string corresponding to the specified path or {@code null}
* if the no provider is found
*/
abstract protected String toUriString(Path path)

static Path parse(String uri) {
def factories = factories0()
final factories = factories0()
for( int i=0; i<factories.size(); i++ ) {
final result = factories[i].parseUri(uri)
if( result )
Expand All @@ -41,6 +60,16 @@ abstract class FileSystemPathFactory {
return null
}

static String getUriString(Path path) {
final factories = factories0()
for( int i=0; i<factories.size(); i++ ) {
final result = factories[i].toUriString(path)
if( result )
return result
}
return null
}

@Memoized
private static List<FileSystemPathFactory> factories0() {
final result = new ArrayList(10)
Expand Down
Expand Up @@ -20,12 +20,12 @@ import java.nio.file.Path

import com.google.cloud.storage.contrib.nio.CloudStorageConfiguration
import com.google.cloud.storage.contrib.nio.CloudStorageFileSystem
import com.google.cloud.storage.contrib.nio.CloudStoragePath
import groovy.transform.CompileStatic
import nextflow.Global
import nextflow.Session
import nextflow.cloud.google.lifesciences.GoogleLifeSciencesConfig
import nextflow.file.FileSystemPathFactory

/**
* Implements FileSystemPathFactory interface for Google storage
*
Expand Down Expand Up @@ -62,4 +62,12 @@ class GsPathFactory extends FileSystemPathFactory {
? CloudStorageFileSystem.forBucket(str, storageConfig).getPath('')
: CloudStorageFileSystem.forBucket(str.substring(0,p), storageConfig).getPath(str.substring(p)) )
}

@Override
protected String toUriString(Path path) {
if( path instanceof CloudStoragePath ) {
return "gs://${path.bucket()}$path".toString()
}
return null
}
}
Expand Up @@ -36,14 +36,15 @@ class GsPathFactoryTest extends Specification {

expect:
factory.parseUri(PATH).toUriString() == PATH
factory.parseUri(PATH).toString() == STR

where:
_ | PATH
_ | 'gs://foo'
_ | 'gs://foo/bar'
_ | 'gs://foo/b a r'
_ | 'gs://f o o/bar'
_ | 'gs://f_o_o/bar'
_ | PATH | STR
_ | 'gs://foo' | ''
_ | 'gs://foo/bar' | '/bar'
_ | 'gs://foo/b a r' | '/b a r'
_ | 'gs://f o o/bar' | '/bar'
_ | 'gs://f_o_o/bar' | '/bar'
}

def 'should use requester pays' () {
Expand Down

0 comments on commit 8dc0adf

Please sign in to comment.