Skip to content

Commit

Permalink
feat: #231 fix pkg-input (#232)
Browse files Browse the repository at this point in the history
#231 
> Files.copy -> FileUtils.copyDirectory
Because Java's Files.copy WILL copy a directory withOUT its contents.

---------

Co-authored-by: Dr. Ernie Prabhakar <[email protected]>
  • Loading branch information
drernie and drernie authored Sep 3, 2024
1 parent 6f0aecf commit 185762c
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ jobs:
with:
name: nf-quilt-test-reports-${{ matrix.os }}-${{ matrix.java_version }}
path: |
${{ github.workspace }}/nf-quilt/plugins/nf-quilt/build/reports/tests/test/
${{ github.workspace }}/plugins/nf-quilt/build/reports/tests/test/
overwrite: true

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Nextflow plugin for reading and writing Quilt packages as a FileSystem
developed by [Quilt Data](https://quiltdata.com/) that enables you read and write directly
to Quilt packages using `quilt+s3` URIs wherever your Nextflow pipeline currently use `s3` URIs.

In v0.8.0, the plugin can even be used with "native" URIs, and it will automatically register a Quilt package at the root of the bucket.
In v0.8+, the plugin can even be used with "native" URIs, and it will automatically register a Quilt package at the root of the bucket.

Inspired by the original [`nf-quilt`](https://github.com/nextflow-io/nf-quilt) plugin (v0.2.0) developed by Seqera labs.

Expand Down Expand Up @@ -80,8 +80,8 @@ From the command-line, do, e.g.:
```bash
# export NXF_VER=23.04.3
export LOG4J_DEBUG=true # for verbose logging
export NXF_PLUGINS_TEST_REPOSITORY=https://github.com/quiltdata/nf-quilt/releases/download/0.7.16/nf-quilt-0.7.16-meta.json
nextflow run main.nf -plugins nf-quilt@0.7.16
export NXF_PLUGINS_TEST_REPOSITORY=https://github.com/quiltdata/nf-quilt/releases/download/0.8.0/nf-quilt-0.8.0-meta.json
nextflow run main.nf -plugins nf-quilt@0.8.0
```

For Tower, you can use the "Pre-run script" to set the environment variables.
Expand Down
1 change: 1 addition & 0 deletions plugins/nf-quilt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ dependencies {
compileOnly 'black.ninia:jep:4.2.0'
runtime 'black.ninia:jep:4.2.0'
runtimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'
implementation 'commons-io:commons-io:2.11.0'
implementation 'black.ninia:jep:4.2.0'
testImplementation 'black.ninia:jep:4.2.0'
//testImplementation(testFixtures('black.ninia:jep:4.0.3'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import java.nio.file.spi.FileSystemProvider
import java.nio.file.FileSystems
import java.nio.file.FileAlreadyExistsException

import org.apache.commons.io.FileUtils
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import nextflow.Global
Expand Down Expand Up @@ -139,7 +140,11 @@ class QuiltFileSystemProvider extends FileSystemProvider implements FileSystemTr
throw new FileAlreadyExistsException(localDestination.toString())
}

Files.copy(cachedFile, localDestination, options)
if (Files.isDirectory(cachedFile)) {
FileUtils.copyDirectory(cachedFile.toFile(), localDestination.toFile())
} else {
Files.copy(cachedFile, localDestination, options)
}
}

void upload(Path localFile, Path remoteDestination, CopyOption... options) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class QuiltSpecification extends Specification {

Path makeObject(String url, String text) {
assert url
Path path = Paths.get(new URI(url))
Path path = QuiltPathFactory.parse(url)
return makeObject(path, text)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class QuiltPackageTest extends QuiltSpecification {
Files.readAttributes(qpath, BasicFileAttributes)
}

@IgnoreIf({ System.getProperty('os.name').contains('indows') })
void 'should successfully install files and get attributes'() {
expect:
pkg.install()
Expand All @@ -120,7 +119,6 @@ class QuiltPackageTest extends QuiltSpecification {
Files.readAttributes(qpath, BasicFileAttributes)
}

@IgnoreIf({ System.getProperty('os.name').contains('indows') })
void 'should download the specified path'() {
given:
def qpath = factory.parseUri(TEST_URL)
Expand Down Expand Up @@ -167,7 +165,6 @@ class QuiltPackageTest extends QuiltSpecification {
thrown(RuntimeException)
}

@IgnoreIf({ System.getProperty('os.name').contains('indows') })
void 'should deinstall files'() {
expect:
Files.exists(qpath.localPath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ package nextflow.quilt.nio
import nextflow.quilt.QuiltSpecification
import groovy.transform.CompileDynamic
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.Files
import java.nio.file.CopyOption
import java.nio.file.StandardCopyOption
import groovy.util.logging.Slf4j
import spock.lang.IgnoreIf

/**
*
Expand All @@ -28,12 +28,11 @@ class QuiltFileSystemProviderTest extends QuiltSpecification {
// newDirectoryStream returns package path for write
// do we need a new schema for quilt+local?

@IgnoreIf({ System.getProperty('os.name').contains('indows') })
void 'should download file from remote to local destination'() {
given:
QuiltFileSystemProvider provider = new QuiltFileSystemProvider()
String filename = 'README.md'
Path remoteFile = Paths.get('quilt+s3://quilt-example#package=examples%2fhurdat2&path=' + filename)
Path remoteFile = QuiltPathFactory.parse('quilt+s3://quilt-example#package=examples%2fhurdat2&path=' + filename)
Path tempFolder = Files.createTempDirectory('quilt')
Path tempFile = tempFolder.resolve(filename)

Expand All @@ -45,4 +44,18 @@ class QuiltFileSystemProviderTest extends QuiltSpecification {
Files.size(tempFile) > 0
}

void 'should download folders from remote to local destination'() {
given:
QuiltFileSystemProvider provider = new QuiltFileSystemProvider()
Path remoteFolder = QuiltPathFactory.parse('quilt+s3://quilt-example#package=examples%2fhurdat2')
Path tempFolder = Files.createTempDirectory('quilt')
CopyOption opt = StandardCopyOption.REPLACE_EXISTING
when:
provider.download(remoteFolder, tempFolder, opt)

then:
Files.exists(tempFolder)
Files.list(tempFolder).count() > 0
}

}
14 changes: 7 additions & 7 deletions plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltNioTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ class QuiltNioTest extends QuiltSpecification {
readObject(path).trim() == TEXT
}

@IgnoreIf({ System.getProperty('os.name').contains('indows') })
void 'should read from a path'() {
given:
QuiltPath path = Paths.get(new URI(READ_URL)) as QuiltPath
QuiltPath path = QuiltPathFactory.parse(READ_URL)
path.pkg().install()

when:
Expand All @@ -80,15 +79,15 @@ class QuiltNioTest extends QuiltSpecification {
text.startsWith('id')
}

@IgnoreIf({ System.getProperty('os.name').contains('ux') })
@IgnoreIf({ System.getProperty('os.name').contains('indows') })
@IgnoreIf({ System.getProperty('os.name').toLowerCase().contains('windows') ||
System.getProperty('os.name').toLowerCase().contains('linux') })
void 'should read file attributes'() {
given:
final start = System.currentTimeMillis()
final root = 'folder'
final start_path = "${root}/${start}.txt"
final start_url = packagePath(start_path)
Path path = Paths.get(new URI(start_url))
Path path = QuiltPathFactory.parse(start_url)

when:
makeObject(path, TEXT)
Expand Down Expand Up @@ -513,7 +512,8 @@ class QuiltNioTest extends QuiltSpecification {
list == [ 'file4.txt' ]
}

@IgnoreIf({ System.getProperty('os.name').contains('indows') })
// \QuiltPackage.quilt_dev_null_test_null\foo
@IgnoreIf({ System.getProperty('os.name').toLowerCase().contains('windows') })
void 'should check walkTree'() {
given:
makeObject(null_path('foo/file1.txt'), 'A')
Expand All @@ -526,7 +526,7 @@ class QuiltNioTest extends QuiltSpecification {
when:
List<String> dirs = []
Map<String,BasicFileAttributes> files = [:]
Path base = Paths.get(new URI(NULL_URL))
Path base = QuiltPathFactory.parse(NULL_URL)
Files.walkFileTree(base, new SimpleFileVisitor<Path>() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import nextflow.quilt.jep.QuiltParser
import nextflow.quilt.jep.QuiltPackage

import java.nio.file.Path
import java.nio.file.Paths
import groovy.util.logging.Slf4j
import groovy.transform.CompileDynamic

Expand All @@ -28,13 +27,12 @@ class QuiltPathTest extends QuiltSpecification {

QuiltPath pathify(String path) {
if (!path.contains(BKT)) {
URI uri = new URI(PKG_URL)
QuiltPath pkgPath = Paths.get(uri)
QuiltPath pkgPath = QuiltPathFactory.parse(PKG_URL)
QuiltFileSystem qfs = pkgPath.getFileSystem()
return qfs.getPath(path)
}
String url = QuiltParser.PREFIX + path
return Paths.get(new URI(url))
return QuiltPathFactory.parse(url)
}

@Unroll
Expand Down Expand Up @@ -240,7 +238,7 @@ class QuiltPathTest extends QuiltSpecification {
}

@Unroll
@IgnoreIf({ System.getProperty('os.name').contains('indows') })
@IgnoreIf({ System.getProperty('os.name').toLowerCase().contains('windows') })
void 'should validate relativize'() {
expect:
pathify(path).relativize(pathify(other)).toString() == pathify(expected).toString()
Expand Down

0 comments on commit 185762c

Please sign in to comment.