Skip to content

Commit

Permalink
Strengthen conda naming strategy
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Dec 12, 2024
1 parent b743c13 commit d72b69c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/groovy/io/seqera/wave/util/ContainerHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class ContainerHelper {
return null
}
catch (Exception e) {
log.warn "Unable to infer conda recipe name - cause: ${e.message}", e
log.warn "Unable to infer conda recipe name - offending content:\n---\n${condaFileContent}", e
return null
}
}
Expand Down
31 changes: 27 additions & 4 deletions src/main/groovy/io/seqera/wave/util/NameVersionPair.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,28 @@ class NameVersionPair {
private static final String SUFFIX = 'pruned'
private static final int MAX = 5

Collection<String> names
Collection<String> versions
private Collection<String> names

private Collection<String> versions

protected NameVersionPair() { }

NameVersionPair(Collection<String> names) {
this.names = names
if( names==null )
throw new IllegalArgumentException("Argument 'names' cannot be null")
if( !names )
throw new IllegalArgumentException("Argument 'names' cannot be empty")
}

NameVersionPair(Collection<String> names, Collection<String> versions) {
this(names)
this.versions = versions
}

Collection<String> getNames() { names }

Collection<String> getVersions() { versions }

private List<String> both() {
final result = new ArrayList()
Expand All @@ -46,8 +66,7 @@ class NameVersionPair {
}

String friendlyNames(String sep='_') {
if( !names )
return null
assert names
if( names.size()<=MAX )
return names.join(sep)
else
Expand All @@ -63,4 +82,8 @@ class NameVersionPair {
else
return new ArrayList<>(ret)[0..MAX-2].join(sep) + sep + SUFFIX
}

boolean asBoolean() {
return names
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ class NameVersionPairTest extends Specification {
['a','b','c','d','e','f'] | ['1','2','3','4','5'] | 'a_b_c_d_pruned'
}

def 'should validate truth' () {
expect:
new NameVersionPair(names:['foo'])
and:
!new NameVersionPair(names:null)
!new NameVersionPair(names:[])
}

}

0 comments on commit d72b69c

Please sign in to comment.