Skip to content

Commit c3b02a8

Browse files
committed
add review comments and fix compilation and tests
Signed-off-by: jorgee <jorge.ejarque@seqera.io>
1 parent fc327c4 commit c3b02a8

File tree

12 files changed

+278
-539
lines changed

12 files changed

+278
-539
lines changed

modules/nextflow/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ dependencies {
5555
api 'io.seqera:lib-trace:0.1.0'
5656
api 'com.fasterxml.woodstox:woodstox-core:7.1.1'
5757
api 'org.apache.commons:commons-compress:1.27.1' // For tar.gz extraction
58-
api 'io.seqera:npr-api:0.20.1'
58+
api 'io.seqera:npr-api:0.21.4-SNAPSHOT'
5959

6060
testImplementation 'org.subethamail:subethasmtp:3.1.7'
6161
testImplementation (project(':nf-lineage'))

modules/nextflow/src/main/groovy/nextflow/cli/module/ModuleInfo.groovy

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class ModuleInfo extends CmdBase {
141141
println ""
142142
println "Usage Template:"
143143
println "-" * 80
144-
println generateUsageTemplate(reference, metadata)
144+
println generateUsageTemplate(reference, metadata).join(" \\\n ")
145145
println ""
146146
}
147147

@@ -195,28 +195,59 @@ class ModuleInfo extends CmdBase {
195195
}
196196
}
197197

198-
private String generateUsageTemplate(ModuleReference reference, ModuleMetadata metadata) {
199-
def template = new StringBuilder()
200-
template.append("nextflow module run ${reference.nameWithoutPrefix}")
198+
private List<String> generateUsageTemplate(ModuleReference reference, ModuleMetadata metadata) {
199+
def template = new ArrayList<String>()
200+
template.add("nextflow module run ${reference.nameWithoutPrefix}".toString())
201201
if( version )
202-
template.append(" -version $version")
202+
template.add(" -version $version".toString())
203203

204-
// Use metadata from registry if available, otherwise use spec from meta.yml
205204
def inputs = metadata?.input ?: []
205+
inputs.each { input ->
206+
input.items.each { ModuleChannelItem item ->
207+
template.add(reference.scope == 'nf-core'
208+
? inferNfCoreParam(item.name, item.type)
209+
: inferNormalParam(item.name, item.type))
206210

207-
if( inputs ) {
208-
inputs.each { input ->
209-
input.items.each { ModuleChannelItem item ->
210-
def placeholder = item.name.toUpperCase().replaceAll(/[^A-Z0-9_]/, '_')
211-
if( item.type.equalsIgnoreCase("map") ) {
212-
template.append(" --${item.name}.<key> <${placeholder}_KEY>")
213-
} else {
214-
template.append(" --${item.name} <${placeholder}>")
215-
}
216-
}
217211
}
218212
}
219-
return template.toString()
213+
if( reference.scope == 'nf-core' ) {
214+
template.add('--outdir <OUTPUT_DIRECTORY>')
215+
}
216+
return template
217+
}
218+
219+
private static String inferNfCoreParam(String paramName, String type) {
220+
if( type?.equalsIgnoreCase("map") && paramName.equalsIgnoreCase("meta") ) {
221+
return "--${paramName}.id <ID>"
222+
}
223+
if( type?.equalsIgnoreCase("file") || type?.equalsIgnoreCase("path") ) {
224+
return "--${paramName} ${inferBioFilePlaceholder(paramName)}"
225+
}
226+
return inferNormalParam(paramName, type)
227+
}
228+
229+
private static String inferBioFilePlaceholder(String paramName) {
230+
final String lower = paramName.toLowerCase()
231+
if( lower.contains("fasta") ) return "<FASTA_FILE>"
232+
if( lower.contains("bam") ) return "<BAM_FILE>"
233+
if( lower.contains("fastq") || lower.equals("reads") ) return "<FASTQ_FILE>"
234+
if( lower.contains("vcf") ) return "<VCF_FILE>"
235+
if( lower.contains("ref") ) return "<REFERENCE_FILE>"
236+
if( lower.contains("bed") ) return "<BED_FILE>"
237+
if( lower.contains("gff") || lower.contains("gtf") ) return "<ANNOTATION_FILE>"
238+
239+
return "<${paramName.toUpperCase().replaceAll(/[^A-Z0-9]/, '_')}_PATH>"
240+
}
241+
242+
private static String inferNormalParam(String paramName, String type) {
243+
final paramPlaceholder = paramName.toUpperCase().replaceAll(/[^A-Z0-9]/, '_')
244+
if( type?.equalsIgnoreCase("map") ) {
245+
return "--${paramName}.<KEY> <${paramPlaceholder}_KEY_VALUE>"
246+
}
247+
if( type?.equalsIgnoreCase("file") || type?.equalsIgnoreCase("path") ) {
248+
return "--${paramName} <${paramPlaceholder}_PATH>"
249+
}
250+
return "--${paramName} <${paramPlaceholder}>"
220251
}
221252

222253
private void printJsonInfo(ModuleReference reference, ModuleRelease release) {
@@ -276,7 +307,7 @@ class ModuleInfo extends CmdBase {
276307
}
277308
}
278309

279-
info.usageTemplate = generateUsageTemplate(reference, metadata)
310+
info.usageTemplate = generateUsageTemplate(reference, metadata).join(" ")
280311

281312
println JsonOutput.prettyPrint(JsonOutput.toJson(info))
282313
}

modules/nextflow/src/main/groovy/nextflow/cli/module/ModuleRun.groovy

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,17 @@ package nextflow.cli.module
1919
import com.beust.jcommander.Parameter
2020
import com.beust.jcommander.Parameters
2121
import groovy.transform.CompileStatic
22-
import groovy.util.logging.Slf4j
2322
import nextflow.cli.CmdRun
2423
import nextflow.config.ConfigBuilder
2524
import nextflow.config.ModulesConfig
2625
import nextflow.config.RegistryConfig
2726
import nextflow.exception.AbortOperationException
28-
import nextflow.file.FileHelper
2927
import nextflow.module.ModuleReference
3028
import nextflow.module.ModuleRegistryClient
3129
import nextflow.module.ModuleResolver
3230
import nextflow.pipeline.PipelineSpec
3331
import nextflow.util.TestOnly
3432

35-
import java.nio.file.Files
3633
import java.nio.file.Path
3734
import java.nio.file.Paths
3835

@@ -41,7 +38,6 @@ import java.nio.file.Paths
4138
*
4239
* @author Jorge Ejarque <jorge.ejarque@seqera.io>
4340
*/
44-
@Slf4j
4541
@CompileStatic
4642
@Parameters(commandDescription = "Run a module directly from the registry")
4743
class ModuleRun extends CmdRun {
@@ -90,20 +86,11 @@ class ModuleRun extends CmdRun {
9086
def modulesConfig = new ModulesConfig(specFile.getModules())
9187

9288
def resolver = new ModuleResolver(baseDir, client ?: new ModuleRegistryClient(registryConfig), modulesConfig)
93-
try{
94-
Path moduleFile = resolver.installModule(reference, version)
95-
if( moduleFile ) {
96-
println "Executing module..."
97-
args[0] = moduleFile.toAbsolutePath().toString()
98-
super.run()
99-
}
100-
}
101-
catch (AbortOperationException e) {
102-
throw e
103-
}
104-
catch (Exception e) {
105-
log.error("Failed to run module", e)
106-
throw new AbortOperationException("Module run failed: ${e.message}", e)
89+
Path moduleFile = resolver.installModule(reference, version)
90+
if( moduleFile ) {
91+
println "Executing module..."
92+
args[0] = moduleFile.toAbsolutePath().toString()
93+
super.run()
10794
}
10895
}
10996
}

modules/nextflow/src/main/groovy/nextflow/config/RegistryConfig.groovy

Lines changed: 0 additions & 132 deletions
This file was deleted.

modules/nextflow/src/main/groovy/nextflow/module/ModuleRegistryClient.groovy

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class ModuleRegistryClient {
101101

102102
// Add authentication if available
103103
log.debug "Getting auth from: ${registryUrl}"
104-
def token = config.getAuthTokenResolved(registryUrl)
104+
def token = config.getApiKey()
105105
if (token) {
106106
requestBuilder.header("Authorization", "Bearer ${token}")
107107
}
@@ -177,7 +177,7 @@ class ModuleRegistryClient {
177177
.uri(uri)
178178
.GET()
179179

180-
def token = config.getAuthTokenResolved(registryUrl)
180+
def token = config.getApiKey()
181181
if (token) {
182182
requestBuilder.header("Authorization", "Bearer ${token}")
183183
}
@@ -252,7 +252,7 @@ class ModuleRegistryClient {
252252
.uri(uri)
253253
.GET()
254254

255-
def token = config.getAuthTokenResolved(registryUrl)
255+
def token = config.getApiKey()
256256
if (token) {
257257
requestBuilder.header("Authorization", "Bearer ${token}")
258258
}
@@ -368,7 +368,7 @@ class ModuleRegistryClient {
368368
.uri(uri)
369369
.GET()
370370

371-
def token = config.getAuthTokenResolved(registryUrl)
371+
def token = config.getApiKey()
372372
if (token) {
373373
requestBuilder.header("Authorization", "Bearer ${token}")
374374
}
@@ -410,16 +410,14 @@ class ModuleRegistryClient {
410410
*/
411411
PublishModuleResponse publishModule(String name, def request, String registry = null) {
412412
final registryUrl = registry ?: config.url
413-
final authToken = config.getAuthTokenResolved(registryUrl)
413+
final authToken = config.apiKey
414414

415415
if (!authToken) {
416416
throw new AbortOperationException(
417417
"Authentication required to publish modules.\n" +
418-
"Please set NXF_REGISTRY_TOKEN environment variable or configure registry.auth in nextflow.config:\n\n" +
418+
"Please set 'NXF_REGISTRY_TOKEN' environment variable or configure 'registry.apiKey' in nextflow.config:\n\n" +
419419
" registry {\n" +
420-
" auth {\n" +
421-
" '${registryUrl}' = '\${NXF_REGISTRY_TOKEN}'\n" +
422-
" }\n" +
420+
" apiKey = '\${NXF_REGISTRY_TOKEN}'\n" +
423421
" }\n"
424422
)
425423
}

modules/nextflow/src/test/groovy/nextflow/cli/module/ModuleInfoTest.groovy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ class ModuleInfoTest extends Specification {
409409
then:
410410
output.contains('Usage Template:')
411411
output.contains('nextflow module run nf-core/fastqc')
412-
output.contains('--reads <READS>')
412+
output.contains('--reads <FASTQ_FILE>')
413413
output.contains('--sample-id <SAMPLE_ID>')
414414
}
415415

@@ -447,7 +447,8 @@ class ModuleInfoTest extends Specification {
447447

448448
then:
449449
output.contains('Usage Template:')
450-
output.contains('nextflow module run nf-core/fastqc -version 2.0.0')
450+
output.contains('nextflow module run nf-core/fastqc')
451+
output.contains('-version 2.0.0')
451452
}
452453

453454
def 'should generate usage template with map inputs'() {
@@ -498,7 +499,7 @@ class ModuleInfoTest extends Specification {
498499

499500
then:
500501
output.contains('Usage Template:')
501-
output.contains('--params.<key> <PARAMS_KEY>')
502+
output.contains('--params.<KEY> <PARAMS_KEY_VALUE>')
502503
}
503504

504505
def 'should fail with no arguments'() {

0 commit comments

Comments
 (0)