Skip to content

Commit

Permalink
Intellij code cleanup (#263)
Browse files Browse the repository at this point in the history
linter and permission fixes

---------

Co-authored-by: Dr. Ernie Prabhakar <[email protected]>
  • Loading branch information
drernie and drernie authored Nov 13, 2024
1 parent bd70b45 commit 88b3f50
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class QuiltObserverFactory implements TraceObserverFactory {
@Override
Collection<TraceObserver> create(Session session) {
//log.debug("`create` ${this}")
return (Collection<TraceObserver>) [new QuiltObserver()]
Collection<QuiltObserver> quiltObservers = new ArrayList<>()
quiltObservers.add(new QuiltObserver())

return quiltObservers as Collection<TraceObserver>
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class QuiltPathify {
Files.copy(source, dest)
}
catch (Exception e) {
log.error("writeString: cannot write `$source` to `$dest` in `${destRoot}`")
log.error("writeString: cannot write `$source` to `$dest` in `${destRoot}`\n$e")
}
}

Expand Down
80 changes: 49 additions & 31 deletions plugins/nf-quilt/src/main/nextflow/quilt/QuiltProduct.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package nextflow.quilt

import nextflow.quilt.jep.QuiltPackage
import nextflow.quilt.jep.QuiltParser
import nextflow.quilt.nio.QuiltPath
import nextflow.Session

Expand Down Expand Up @@ -47,14 +48,11 @@ class QuiltProduct {
public final static String README_FILE = 'README_NF_QUILT.md'
public final static String SUMMARY_FILE = 'quilt_summarize.json'

private final static String KEY_CATALOG = 'catalog'
private final static String KEY_FORCE = 'force'
private final static String KEY_META = 'meta'
private final static String KEY_MSG = 'message'
private final static String KEY_PKG = 'package'
private final static String KEY_QUILT = 'quilt'
private final static String KEY_README = 'readme'
private final static String KEY_SUMMARIZE = 'summarize'
public final static String KEY_META = 'meta'
public final static String KEY_MSG = 'message'
public final static String KEY_QUILT = 'quilt'
public final static String KEY_README = 'readme'
public final static String KEY_SUMMARIZE = 'summarize'

/* groovylint-disable-next-line GStringExpressionWithinString */
private final static String DEFAULT_MSG = '''
Expand Down Expand Up @@ -112,7 +110,7 @@ ${nextflow}
Files.write(path, text.bytes)
}
catch (Exception e) {
log.error("writeString: cannot write `$text` to `$path` for `${pkg}`")
log.error("writeString: cannot write `$text` to `$path` for `${pkg}`\n$e")
}
}

Expand All @@ -123,7 +121,7 @@ ${nextflow}
Files.copy(source, dest)
}
catch (Exception e) {
log.error("writeString: cannot write `$source` to `$dest` in `${destRoot}`")
log.error("writeString: cannot write `$source` to `$dest` in `${destRoot}`\n$e.message()")
}
}

Expand All @@ -148,15 +146,17 @@ ${nextflow}
])

QuiltProduct(QuiltPathify pathify, Session session) {
println("Creating QuiltProduct: ${pathify}")
this.session = session
this.config = session.config ?: [:]
this.path = pathify.path
println('QuiltProduct.path')
this.pkg = pathify.pkg
println("QuiltProduct.pkg: ${pkg.toUriString()}")
println('QuiltProduct.pkg')
this.metadata = getMetadata()
println("QuiltProduct.metadata: ${metadata}")
println("QuiltProduct.flags: ${flags}")
if (session.isSuccess() || flags.getProperty(KEY_FORCE)) {
println('QuiltProduct.metadata')
// println("QuiltProduct.flags: ${flags}")
if (session.isSuccess() || flags.getProperty(QuiltParser.P_FORCE) == true) {
publish()
} else {
log.info("not publishing: ${pkg} [unsuccessful session]")
Expand All @@ -168,7 +168,7 @@ ${nextflow}
log.info("SKIP: metadata for ${pkg}")
return [:]
}
println("getMetadata.config: ${config}")
// println("getMetadata.config: ${config}")
config.remove('executor')
config.remove('params')
config.remove('session')
Expand All @@ -181,19 +181,20 @@ ${nextflow}

Map<String, Object> cf_meta = quilt_cf.navigate(KEY_META) as Map<String, Object> ?: [:]
quilt_cf.remove(KEY_META)
Map pkg_meta = pkg.meta
// println("getMetadata.cf_meta: ${cf_meta}")
Map pkg_meta = pkg.getMetadata()
updateFlags(pkg_meta, quilt_cf)

Map params = session.getParams()
println("getMetadata.params: ${params}")
// println("getMetadata.params: ${params}")
if (params != null) {
writeMapToPackage(params, 'params')
params.remove('genomes')
params.remove('test_data')
printMap(params, 'params')
}
Map wf = session.getWorkflowMetadata()?.toMap()
println("getMetadata.wf: ${wf}")
// println("getMetadata.wf: ${wf}")
String start = wf?.get('start')
String complete = wf?.get('complete')
String cmd = wf?.get('commandLine')
Expand All @@ -209,8 +210,9 @@ ${nextflow}
log.info("\npublishing: ${wf['runName']}")
}

println("getMetadata.pkg_meta: ${pkg_meta}")
Map base_meta = cf_meta + pkg_meta
log.debug("getMetadata.base_meta: ${base_meta}")
log.info("getMetadata.base_meta: ${base_meta}")
return base_meta + [
cmd: cmd,
now: now(),
Expand All @@ -228,7 +230,7 @@ ${nextflow}
cmd: metadata.get('cmd'),
meta: metadata,
now: metadata.get('now'),
pkg: flags.getProperty(KEY_PKG)
pkg: flags.getProperty(QuiltParser.P_PKG)
]
return params
}
Expand All @@ -245,16 +247,17 @@ ${nextflow}
* @param cf Map of config (from nextflow.config)
*/
void updateFlags(Map meta, Map cf) {
for (String key : flags.properties.keySet()) {
//println("updateFlags.meta: ${meta}")
for (String key : flags.getProperties().keySet()) {
if (meta.containsKey(key)) {
flags.setProperty(key, meta[key])
} else if (cf.containsKey(key)) {
flags.setProperty(key, cf[key])
}
}
// FIXME: should this only work for names inferred from S3 URIs?
String pkgName = cf.containsKey(KEY_PKG) ? cf[KEY_PKG] : pkg.packageName
flags.setProperty(KEY_PKG, pkgName)
String pkgName = cf.containsKey(QuiltParser.P_PKG) ? cf[QuiltParser.P_PKG] : pkg.packageName
flags.setProperty(QuiltParser.P_PKG, pkgName)
}

String writeMapToPackage(Map map, String prefix) {
Expand Down Expand Up @@ -291,16 +294,23 @@ ${nextflow}
}

String displayName() {
Object catalog = flags.getProperty(KEY_CATALOG)
Object catalog = flags.getProperty(QuiltParser.P_CAT)
return catalog ? pkg.toCatalogURL(catalog.toString()) : pkg.toUriString()
}

String compileMessage() {
String msg = flags.getProperty(KEY_MSG)
GStringTemplateEngine engine = new GStringTemplateEngine()
String output = engine.createTemplate(msg).make(getParams())
log.debug("compileMessage.output: ${output}")
return output
println("compileMessage: ${msg}")
try {
String output = engine.createTemplate(msg).make(getParams())
log.debug("compileMessage.output: ${output}")
return output
}
catch (Exception e) {
log.error("compileMessage failed: ${e.getMessage()}\n{$e}", flags)
}
return "compileMessage.FAILED\n$msg"
}

String compileReadme(String msg) {
Expand All @@ -320,10 +330,16 @@ ${nextflow}
nextflow: nextflow,
]
log.debug("compileReadme.params: ${params}")
GStringTemplateEngine engine = new GStringTemplateEngine()
String output = engine.createTemplate(raw_readme).make(params)
log.debug("compileReadme.output: ${output}")
return output
try {
GStringTemplateEngine engine = new GStringTemplateEngine()
String output = engine.createTemplate(raw_readme).make(params)
log.debug("compileReadme.output: ${output}")
return output
}
catch (Exception e) {
log.error("compileReadme failed: ${e.getMessage()}\n{$e}", flags)
}
return "compileReadme.FAILED\n$raw_readme"
}

String writeReadme(String message) {
Expand Down Expand Up @@ -373,12 +389,14 @@ ${nextflow}
List<Map> writeSummarize() {
List<Map> quilt_summarize = []
if (shouldSkip(KEY_SUMMARIZE)) {
log.info("SKIP: summarize for ${flags}")
return quilt_summarize
}
String summarize = flags.getProperty(KEY_SUMMARIZE)
String[] wildcards = summarize.split(',')
wildcards.each { wildcard ->
List<Path> paths = match(wildcard)
println("writeSummarize: ${paths.size()} matches for ${wildcard}")
paths.each { path ->
String filename = path.getFileName()
Map entry = ['path': path.toString(), 'title': filename]
Expand Down
3 changes: 0 additions & 3 deletions plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltID.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package nextflow.quilt.jep

/* groovylint-disable-next-line ImportFromSamePackage */
import nextflow.quilt.jep.QuiltParser

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j

Expand Down
34 changes: 11 additions & 23 deletions plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltPackage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.NoSuchFileException
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.SimpleFileVisitor
Expand All @@ -48,8 +49,8 @@ class QuiltPackage {
private static final String INSTALL_PREFIX = 'QuiltPackage'
static final Path INSTALL_ROOT = Files.createTempDirectory(INSTALL_PREFIX)

public final String packageName
private final String bucket
private final String packageName
private final QuiltParser parsed
private final String hash
private final Path folder
Expand Down Expand Up @@ -97,11 +98,6 @@ class QuiltPackage {
PKGS.clear()
}

static QuiltPackage forUriString(String uri) {
QuiltParser parsed = QuiltParser.forUriString(uri)
return forParsed(parsed)
}

static QuiltPackage forParsed(QuiltParser parsed) {
println("QuiltPackage.forParsed: $parsed")
boolean isNull = parsed.hasNullBucket()
Expand All @@ -123,13 +119,6 @@ class QuiltPackage {
return PKGS.containsKey(pkgKey)
}

static QuiltPackage forKey(String pkgKey) {
if (hasKey(pkgKey)) {
return PKGS.get(pkgKey)
}
return null
}

static List<Path> listDirectory(Path rootPath) {
return Files.walk(rootPath).sorted(Comparator.reverseOrder()).collect(Collectors.toList())
}
Expand All @@ -147,8 +136,8 @@ class QuiltPackage {
Files.deleteIfExists(path)
}
}
catch (java.nio.file.NoSuchFileException e) {
log.debug 'deleteDirectory: ignore non-existent files'
catch (NoSuchFileException e) {
log.debug "deleteDirectory: ignore non-existent files\n$e"
}
return true
}
Expand Down Expand Up @@ -205,7 +194,7 @@ class QuiltPackage {
}

boolean is_force() {
return parsed.options[QuiltParser.P_FORCE]
return parsed.getOptions(QuiltParser.P_FORCE)
}

boolean isNull() {
Expand All @@ -231,6 +220,10 @@ class QuiltPackage {
return folder
}

Map getMetadata() {
return this.meta
}

/*
* Package methods
*/
Expand Down Expand Up @@ -315,7 +308,7 @@ class QuiltPackage {
LocalPhysicalKey physicalKey = new LocalPhysicalKey(f)
long size = Files.size(f)
builder.addEntry(logicalKey, new Entry(physicalKey, size, null, null))
});
})

Map<String, Object> fullMeta = [
'version': Manifest.VERSION,
Expand All @@ -337,7 +330,7 @@ class QuiltPackage {
/* groovylint-disable-next-line ThrowRuntimeException */
throw new RuntimeException(e)
}
return m
// return m
}

@Override
Expand All @@ -357,9 +350,4 @@ class QuiltPackage {
return parsed.toPackageString(true)
}

String meta_overrides(String key, Serializable baseline = null) {
Object temp = meta[key] ? meta[key] : baseline
return temp.toString()
}

}
Loading

0 comments on commit 88b3f50

Please sign in to comment.