Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

35 audit one liners [pr] #36

Merged
merged 21 commits into from
Jan 23, 2023
16 changes: 4 additions & 12 deletions plugins/nf-quilt/src/main/nextflow/quilt/QuiltObserver.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,27 @@ class QuiltObserver implements TraceObserver {
public static void writeString(String text, QuiltPackage pkg, String filename) {
String dir = pkg.packageDest().toString()
def path = Paths.get(dir, filename)
//log.debug "QuiltObserver.writeString[$path]: $text"
Files.write(path, text.bytes)
}

private Session session
private Map config
private Map quilt_config
private Set<QuiltPackage> pkgs
private Set<QuiltPackage> pkgs = new HashSet<>()

static String now(){
def date = new Date()
def sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
return sdf.format(date)
}

Set<QuiltPackage> ensurePkgs() {
if ( !this.pkgs ) {
this.pkgs = new HashSet<>()
}
this.pkgs
}

@Override
void onFlowCreate(Session session) {
log.debug "`onFlowCreate` $this"
this.session = session
this.config = session.config
this.quilt_config = session.config.navigate('quilt') as Map
ensurePkgs()
this.pkgs
}

@Override
Expand All @@ -82,7 +74,7 @@ class QuiltObserver implements TraceObserver {
if( path instanceof QuiltPath ) {
QuiltPath qPath = (QuiltPath)path
QuiltPackage pkg = qPath.pkg()
ensurePkgs().add(pkg)
this.pkgs.add(pkg)
log.debug "onFilePublish.QuiltPath[$qPath]: pkgs=${pkgs}"
}
}
Expand Down Expand Up @@ -147,7 +139,7 @@ ${meta['workflow']['stats']['processes']}
static void printMap(Map map, String title) {
log.info "\n\n\n# $title"
map.each{
key, value -> print "\n## $key\n\n$value";
key, value -> log.info "\n## $key\n\n$value";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class QuiltObserverFactory implements TraceObserverFactory {
@Override
Collection<TraceObserver> create(Session session) {
log.debug "`create` ${this}"
final result = new ArrayList()
result.add( new QuiltObserver() )
return result
(Collection<TraceObserver>) [new QuiltObserver()]
}
}
3 changes: 1 addition & 2 deletions plugins/nf-quilt/src/main/nextflow/quilt/QuiltOpts.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class QuiltOpts {
//
// If not using the default, the profile needs to be set in the nextflow config file.

final config = fromSession(session)
return config
return fromSession(session)
}

}
27 changes: 13 additions & 14 deletions plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltID.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,40 @@ import groovy.util.logging.Slf4j
@CompileStatic
class QuiltID {
public static String[] DEFAULT_PACKAGE=["null","default"]

private static final Map<String,QuiltID> ids = [:]

private final String bucket
private final String pkgPrefix
private final String pkgSuffix

static public QuiltID Fetch(String bucket, String pkg_name) {
if (!bucket) {
log.error "null == QuiltID.Fetch($bucket, $pkg_name)"
return null
}
if (!pkg_name || pkg_name.size()<QuiltParser.MIN_SIZE) {
pkg_name = DEFAULT_PACKAGE.join(QuiltParser.SEP)
log.error "QuiltID.Fetch: setting missing package to $pkg_name"
log.warn "QuiltID.Fetch: setting missing package to $pkg_name"
}
String[] split = pkg_name.split(QuiltParser.SEP)
if (split.size()<QuiltParser.MIN_SIZE || split[1].size()<QuiltParser.MIN_SIZE) {
split += DEFAULT_PACKAGE[1] as String
log.error "QuiltID.Fetch: setting missing suffix to $split[1]"
log.warn "QuiltID.Fetch: setting missing suffix to $split[1]"
}
String key = "${bucket}/${split[0]}/${split[1]}"
def id = ids.get(key)
if (id) return id
ids[key] = new QuiltID(bucket, split[0], split[1])
if (!ids.containsKey(key)) {
ids[key] = new QuiltID(bucket, split[0], split[1])
}
ids[key]
}

private final String bucket
private final String pkg_prefix
private final String pkg_suffix

QuiltID(String bucket, String pkg_prefix, String pkg_suffix) {
QuiltID(String bucket, String pkgPrefix, String pkgSuffix) {
this.bucket = bucket
this.pkg_prefix = pkg_prefix
this.pkg_suffix = pkg_suffix
this.pkgPrefix = pkgPrefix
this.pkgSuffix = pkgSuffix
}

String toString() {
"${bucket}.${pkg_prefix}.${pkg_suffix}"
"${bucket}.${pkgPrefix}.${pkgSuffix}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import java.lang.ProcessBuilder
@CompileStatic
class QuiltPackage {
private static final Map<String,QuiltPackage> packages = [:]
private static final String installPrefix = "QuiltPackage"
public static final Path installRoot = Files.createTempDirectory(installPrefix)
private static final String INSTALL_PREFIX = "QuiltPackage"
public static final Path INSTALL_ROOT = Files.createTempDirectory(INSTALL_PREFIX)

private final String bucket
private final String pkg_name
Expand All @@ -56,7 +56,7 @@ class QuiltPackage {
pkg.install()
}
catch (Exception e) {
log.debug "Package `${parsed.toUriString()}` does not yet exist"
log.warn "Package `${parsed.toUriString()}` does not yet exist"
}
return pkg
}
Expand Down Expand Up @@ -87,7 +87,7 @@ class QuiltPackage {
this.bucket = parsed.bucket()
this.pkg_name = parsed.pkg_name()
this.hash = parsed.hash()
this.folder = Paths.get(installRoot.toString(), this.toString())
this.folder = Paths.get(INSTALL_ROOT.toString(), this.toString())
assert this.folder
this.setup()
}
Expand Down
14 changes: 7 additions & 7 deletions plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltParser.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class QuiltParser {
}

static private Map<String,Object> parseQuery(String query) {
if (!query) return [:]
final queryParams = query?.split('&') // safe operator for urls without query params
if (!query) return [:] // skip for urls without query params
final queryParams = query.split('&')
queryParams.collectEntries { param -> param.split('=').collect { URLDecoder.decode(it) }}
}

Expand Down Expand Up @@ -131,7 +131,7 @@ class QuiltParser {

QuiltParser normalized() {
boolean skip = false
def norm = { String x ->
String[] rnorms = paths.reverse().findAll { String x ->
if (x == "..") {
skip = true
false
Expand All @@ -142,7 +142,7 @@ class QuiltParser {
true
}
}
String[] rnorms = paths.reverse().findAll(norm)

log.debug("normalized: ${paths} -> ${rnorms}")
String path2 = rnorms.reverse().join(SEP)
log.debug("normalized: -> ${path2}")
Expand All @@ -158,7 +158,7 @@ class QuiltParser {
}

String bucket() {
bucket ? bucket.toLowerCase() : null
bucket?.toLowerCase()
}

String pkg_name() {
Expand All @@ -178,7 +178,7 @@ class QuiltParser {
}

String path(int beginIndex, int endIndex) {
String[] sub = paths[beginIndex..(endIndex-1)]
String[] sub = paths[beginIndex..<endIndex]
sub.join(SEP)
}

Expand All @@ -191,7 +191,7 @@ class QuiltParser {
}

String options(String key) {
options ? options.get(key) : null
options?.get(key)
}

String toPackageString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public final class QuiltFileSystem extends FileSystem {
BasicFileAttributes attrs = Files.readAttributes(installedPath, BasicFileAttributes)
return new QuiltFileAttributes(path,path.toString(),attrs)
}
catch (java.nio.file.NoSuchFileException e) {
catch (e) {
drernie marked this conversation as resolved.
Show resolved Hide resolved
log.debug "No attributes yet for: ${installedPath}"
}
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public final class QuiltPath implements Path {
@Override
boolean isAbsolute() {
log.debug "isAbsolute[${pkg_name()}] : ${parsed}"

filesystem && pkg_name() != "" && pkg_name() != null
filesystem && pkg_name()
}

boolean isJustPackage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class QuiltPackageTest extends QuiltSpecification {
pkg = qpath.pkg()
}

@Unroll
def 'should create unique Package for associated Paths' () {
given:
def pkgPath = qpath.getJustPackage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ class QuiltNioTest extends QuiltSpecification {
when:
def p = Paths.get(new URI(null_url))
def list = Files.newDirectoryStream(p).collect {
//log.debug "newDirectoryStream[$p]: $it"
it.getFileName().toString()
}
then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class QuiltPathFactoryTest extends QuiltSpecification {
static String pkg_url = 'quilt+s3://quilt-example#package=examples/hurdat@f8d1478d93'
static String url = pkg_url + '&path=scripts/build.py'

@Unroll
def 'should decompose Quilt URLs' () {
given:
def qpath = QuiltPathFactory.Parse(url)
Expand Down