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

Add manifest.contributors config option #5322

Merged
merged 8 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -1229,8 +1229,22 @@ The `manifest` scope allows you to define some meta-data information needed when
The following settings are available:

`manifest.author`
: :::{deprecated} 24.09.0-edge
Use `manifest.contributors` instead.
:::
: Project author name (use a comma to separate multiple names).

`manifest.contributors`
: :::{versionadded} 24.09.0-edge
:::
: List of project contributors. Should be a list of maps. The following fields are supported in the contributor map:
- `name`: the contributor's name
- `affiliation`: the contributor's affiliated organization
- `email`: the contributor's email address
- `github`: the contributor's GitHub URL
- `contribution`: list of contributions, can be any of `'author'`, `'maintainer'`
bentsherman marked this conversation as resolved.
Show resolved Hide resolved
- `orcid`: the contributor's [ORCID](https://orcid.org/)
bentsherman marked this conversation as resolved.
Show resolved Hide resolved

`manifest.defaultBranch`
: Git repository default branch (default: `master`).

Expand All @@ -1255,9 +1269,6 @@ The following settings are available:
`manifest.mainScript`
: Project main script (default: `main.nf`).

`manifest.maintainer`
: Project maintainer name (use a comma to separate multiple names).

`manifest.name`
: Project short name.

Expand Down
57 changes: 49 additions & 8 deletions modules/nextflow/src/main/groovy/nextflow/config/Manifest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

package nextflow.config

import java.util.stream.Collectors

import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.util.logging.Slf4j
import nextflow.exception.AbortOperationException

import static nextflow.Const.DEFAULT_BRANCH
import static nextflow.Const.DEFAULT_MAIN_FILE_NAME
/**
Expand Down Expand Up @@ -102,22 +106,33 @@ class Manifest {
target.docsUrl
}

String getIcon(){
String getIcon() {
target.icon
}

String getMaintainer(){
target.maintainer
}

String getOrganisation(){
String getOrganisation() {
target.organisation
}

String getLicense(){
String getLicense() {
target.license
}

List<Contributor> getContributors() {
if( !target.contributors )
return Collections.emptyList()

try {
final contributors = target.contributors as List<Map>
return contributors.stream()
.map(opts -> new Contributor(opts))
.collect(Collectors.toList())
}
catch( ClassCastException | IllegalArgumentException e ){
throw new AbortOperationException("Invalid config option `manifest.contributors` -- should be a list of maps")
}
}

Map toMap() {
final result = new HashMap(15)
result.author = getAuthor()
Expand All @@ -131,9 +146,35 @@ class Manifest {
result.doi = getDoi()
result.docsUrl = getDocsUrl()
result.icon = getIcon()
result.maintainer = getMaintainer()
result.organisation = getOrganisation()
result.license = getLicense()
result.contributors = getContributors()
return result
}

@EqualsAndHashCode
static class Contributor {
String name
String affiliation
String email
String github
Set<Contribution> contribution
String orcid

Contributor(Map opts) {
name = opts.name as String
affiliation = opts.affiliation as String
email = opts.email as String
github = opts.github as String
contribution = (opts.contribution as List<String>).stream()
.map(c -> Contribution.valueOf(c.toUpperCase()))
.collect(Collectors.toSet())
orcid = opts.orcid as String
}
}

static enum Contribution {
AUTHOR,
MAINTAINER
}
}
120 changes: 90 additions & 30 deletions modules/nextflow/src/test/groovy/nextflow/config/ManifestTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package nextflow.config

import nextflow.exception.AbortOperationException
import spock.lang.Specification
/**
*
Expand All @@ -26,49 +27,108 @@ class ManifestTest extends Specification {
def 'should check manifest object' () {

given:
def MAN = [author: 'pablo', nextflowVersion: '1.2.3', name: 'foo',
maintainer: 'john', organisation: 'My Organisation', icon: 'icon.png',
docsUrl: 'https://docs.io', license: 'Apache v2']
def MAN = [
author: 'pablo',
contributors: [
[
name: 'Alice',
affiliation: 'University',
email: '[email protected]',
contribution: ['author', 'maintainer'],
],
[
name: 'Bob',
affiliation: 'Company',
email: '[email protected]',
contribution: ['maintainer'],
]
],
nextflowVersion: '1.2.3',
name: 'foo',
organisation: 'My Organisation',
icon: 'icon.png',
docsUrl: 'https://docs.io',
license: 'Apache v2'
]
when:
def manifest = new Manifest(MAN)
then:
manifest.with {
author == 'pablo'
nextflowVersion == '1.2.3'
name == 'foo'
maintainer == 'john'
organisation == 'My Organisation'
icon == 'icon.png'
docsUrl == 'https://docs.io'
license == 'Apache v2'
}
manifest.author == 'pablo'
manifest.contributors == [
new Manifest.Contributor([
name: 'Alice',
affiliation: 'University',
email: '[email protected]',
contribution: ['author', 'maintainer'],
]),
new Manifest.Contributor([
name: 'Bob',
affiliation: 'Company',
email: '[email protected]',
contribution: ['maintainer'],
])
]
manifest.nextflowVersion == '1.2.3'
manifest.name == 'foo'
manifest.organisation == 'My Organisation'
manifest.icon == 'icon.png'
manifest.docsUrl == 'https://docs.io'
manifest.license == 'Apache v2'

}

def 'should check empty manifest' () {

// check empty manifest
when:
def manifest = new Manifest(new ConfigObject())
then:
manifest.with {
homePage == null
defaultBranch == 'master'
description == null
author == null
mainScript == 'main.nf'
gitmodules == null
nextflowVersion == null
version == null
name == null
maintainer == null
docsUrl == null
organisation == null
icon == null
license == null
}
manifest.homePage == null
manifest.defaultBranch == 'master'
manifest.description == null
manifest.author == null
manifest.contributors == []
manifest.mainScript == 'main.nf'
manifest.gitmodules == null
manifest.nextflowVersion == null
manifest.version == null
manifest.name == null
manifest.docsUrl == null
manifest.organisation == null
manifest.icon == null
manifest.license == null

}

def 'should throw error on invalid manifest' () {
when:
def manifest = new Manifest([
contributors: [ 'Alice' ]
])
manifest.contributors
then:
thrown(AbortOperationException)

when:
manifest = new Manifest([
contributors: [[
name: 'Alice',
contribution: 'author'
]]
])
manifest.contributors
then:
thrown(AbortOperationException)

when:
manifest = new Manifest([
contributors: [[
name: 'Alice',
contribution: [ 'owner' ]
]]
])
manifest.contributors
then:
thrown(AbortOperationException)
}

}
Loading