Skip to content

Commit

Permalink
stub dynamic URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
drernie committed Oct 14, 2024
1 parent 2a8738b commit ef67536
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
14 changes: 3 additions & 11 deletions plugins/nf-quilt/src/main/nextflow/quilt/QuiltPathify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class QuiltPathify {
String folder = parts.join('/')
String sub_path = folder.length() > 0 ? folder + '/' + file : file

println("uriFromS3File: $bucket/$prefix/$suffix/$sub_path")
log.debug("uriFromS3File: $bucket/$prefix/$suffix/$sub_path")
String base = "quilt+s3://${bucket}#package=${prefix}%2f${suffix}"
String uri = base + '&path=' + sub_path
return uri
Expand Down Expand Up @@ -119,7 +119,6 @@ class QuiltPathify {
println("findQuiltPath.path: $path")
pkg = path.pkg()
println("findQuiltPath.pkg: $pkg")
println("findQuiltPath.uri2: $uri")
return true
}

Expand All @@ -146,15 +145,8 @@ class QuiltPathify {
return pkg.toKey()
}

boolean hasRoot() {
return (QuiltPackage.hasKey(pkgKey()))
}

QuiltPackage getRoot() {
if (hasRoot()) {
return QuiltPackage.forKey(pkgKey())
}
return null
String toString() {
return "QuiltPathify[${uri}]"
}

}
4 changes: 3 additions & 1 deletion plugins/nf-quilt/src/main/nextflow/quilt/QuiltProduct.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ ${nextflow}
this.path = pathify.path
this.pkg = pathify.pkg
this.msg = pkg.toString()
this.meta = [pkg: msg, time_start: now()]
this.meta = pkg.meta + [pkg: msg, time_start: now()]
this.session = session

if (session.isSuccess() || pkg.is_force()) {
Expand Down Expand Up @@ -163,6 +163,7 @@ ${nextflow}
}

boolean shouldSkip(key) {
println("shouldSkip[$key]: ${pkg.meta}")
return pkg.meta.containsKey(key) && pkg.meta[key] == KEY_SKIP
}

Expand All @@ -188,6 +189,7 @@ ${nextflow}
}

Map getMetadata(Map cf) {
// add metadata from quilt and URI
if (cf != null) {
cf.remove('executor')
cf.remove('params')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class QuiltPackage {
return PKGS.values().last()
}

String pkgKey = parsed.toPackageString()
String pkgKey = parsed.toPackageString(true) // ignore metadata for Key
log.debug("QuiltPackage.forParsed[${pkgKey}]")
def pkg = PKGS.get(pkgKey)
if (pkg) { return pkg }
Expand Down Expand Up @@ -330,11 +330,13 @@ class QuiltPackage {
}

String toUriString() {
println(' QuiltPackage.toUriString')
return parsed.toUriString()
}

String toKey() {
return parsed.toPackageString()
println(' QuiltPackage.toKey:true')
return parsed.toPackageString(true)
}

String meta_overrides(String key, Serializable baseline = null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ class QuiltParser {
return options?.get(key)
}

String toPackageString() {
String toPackageString(boolean forKey = false) {
String str = "${getBucket()}"
if (metadata) {
if (metadata && !forKey) {
str += "?${unparseQuery(metadata)}"
}
if (packageName) {
Expand All @@ -292,11 +292,12 @@ class QuiltParser {
if (tag) { pkg += ":$tag" }
str += "#package=${pkg.replace('/', '%2f')}"
}
// log.debug("toPackageString: ${str}")
println(" toPackageString[forKey:$forKey, metdata:$metadata]: ${str}")
return str
}

String toString() {
println(' QuiltParser.toString')
String str = toPackageString()
if (!hasPath()) { return str }
str += (packageName) ? '&' : '#'
Expand All @@ -314,6 +315,7 @@ class QuiltParser {
}

String toUriString() {
println(' QuiltParser.toUriString')
return PREFIX + toString()
}

Expand Down
27 changes: 20 additions & 7 deletions plugins/nf-quilt/src/test/nextflow/quilt/QuiltPathifyTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,43 @@ class QuiltPathifyTest extends QuiltSpecification {
void 'test findQuiltPath overrides attributes'() {
when:
QuiltPathify pathify = getPathify()
println("pathify1: ${pathify.uri}")
pathify.findQuiltPath('buck#package=prefix%2fsuffix&path=.%2fFILE.md')
println("pathify2: ${pathify.uri}")

then:
pathify.isOverlay == false
pathify.uri == 'quilt+s3://buck#package=prefix%2fsuffix&path=.%2fFILE.md'
pathify.path.toString() == 'buck#package=prefix%2fsuffix&path=.%2fFILE.md'
pathify.pkg.toUriString() == 'quilt+s3://buck#package=prefix%2fsuffix&path=.%2fFILE.md'
pathify.pkgKey() == 'buck#package=prefix%2fsuffix'
}

void 'test findQuiltPath preserves metadata'() {
when:
String pathWithout = 'bucket#package=prefix%2fsuffix&path=FILE.md'
String pathWith = pathWithout.replace('#', '?key=value#')
String uriWith = "quilt+s3://${pathWith}"
println('\nMETADATA: findQuiltPath preserves metadata\n')
String meta = '?key=value'
String uriWithout = 'quilt+s3://bucket#package=prefix%2fsuffix&path=FILE.md'
String uriWith = uriWithout.replace('#', meta + '#')
println("pathify1.uriWith: $uriWith")
QuiltPathify pathify = getPathify(uriWith)
println("pathify1.uri: ${pathify.uri}")
println("pathify1.uriString: ${pathify.pkg.toUriString()}")

then:
uriWith.contains(meta)
pathify.uri == uriWith
pathify.pkg.toUriString() == uriWith

when:
println('pathify2.uriWithout: $uriWithout')
QuiltPathify pathify2 = getPathify(uriWithout)
println("pathify2.uri: ${pathify2.uri}")
println("pathify2.uriString: ${pathify2.pkg.toUriString()}")

then:
pathify2.pkgKey() == pathify.pkgKey()
pathify2.uri == uriWithout
pathify2.pkg.toUriString() == uriWith
}

// Test findQuiltPath.getRoot() retrieves metadata from prior package
// Test makeQuiltPath creates new uri/path/pkg
// Test makeQuiltPath sets isOverlay
// Test copyToPackage copies overly file to package folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class QuiltProductTest extends QuiltSpecification {
product.pkg
product.session != null
product.session.getWorkflowMetadata() != null
product.meta != null
product.meta.size() == 4
product.meta.key == 'val'
}

void 'should generate solid string for timestamp from now'() {
Expand Down

0 comments on commit ef67536

Please sign in to comment.