-
Notifications
You must be signed in to change notification settings - Fork 764
Add arity option for path inputs and outputs #3706
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
Closed
Closed
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c6d4950
Add arity option for path inputs and outputs
bentsherman 9a16f01
Change default arity to depend on file pattern
bentsherman 4738a97
Change arity "single"-ness to include optional single (`0..1`)
bentsherman 058474f
Remove default arity, use original behavior if arity not specified
bentsherman 2a015c7
Add ArityParam unit test
bentsherman 4e17c99
Add tests for ArityParam (currently failing)
bentsherman 80f944b
Merge branch 'master' into 2425-process-input-output-arity
pditommaso 8c5e93c
Add arity to params unit tests
bentsherman f59fc96
Merge branch 'master' into 2425-process-input-output-arity
pditommaso 04fbb86
Fix liftbot warning
bentsherman edc788d
Merge branch 'master' into 2425-process-input-output-arity
bentsherman 7ec397f
Add support for AWS SSE env variables
pditommaso cefc7cc
Merge branch 'master' into 2425-process-input-output-arity
bentsherman 49356e3
Merge branch 'master' into 2425-process-input-output-arity
bentsherman cf7b677
Merge branch 'master' into 2425-process-input-output-arity
pditommaso b2e6f78
Merge branch 'master' into 2425-process-input-output-arity
pditommaso bbdca3e
Update docs [ci skip]
pditommaso 88da8bb
Add nullable inputs/outputs and other improvements
bentsherman 356a70d
Add e2e test
bentsherman b63ec86
Add NullPath
bentsherman 76de197
Fail if nullable input receives a list
bentsherman 4be1236
Add `arity: true` to infer arity from file pattern
bentsherman b6a5fb3
Fix failing tests
bentsherman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
modules/nextflow/src/main/groovy/nextflow/script/params/ArityParam.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * Copyright 2023, Seqera Labs | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package nextflow.script.params | ||
|
|
||
| import groovy.transform.CompileStatic | ||
|
|
||
| /** | ||
| * Implements an arity option for process inputs and outputs. | ||
| * | ||
| * @author Ben Sherman <[email protected]> | ||
| */ | ||
| @CompileStatic | ||
| trait ArityParam { | ||
|
|
||
| Range arity | ||
|
|
||
| Range getArity() { arity } | ||
|
|
||
| def setArity(String value) { | ||
| if( value.isInteger() ) { | ||
| def n = value.toInteger() | ||
| this.arity = new Range(n, n) | ||
| return this | ||
| } | ||
|
|
||
| def tokens = value.tokenize('..') | ||
| if( tokens.size() == 2 ) { | ||
| def min = tokens[0] | ||
| def max = tokens[1] | ||
| if( min.isInteger() && (max == '*' || max.isInteger()) ) { | ||
| this.arity = new Range( | ||
| min.toInteger(), | ||
| max == '*' ? Integer.MAX_VALUE : max.toInteger() | ||
| ) | ||
| return this | ||
| } | ||
| } | ||
|
|
||
| throw new IllegalArgumentException("Path arity should be a number (e.g. '1') or a range (e.g. '1..*')") | ||
| } | ||
|
|
||
| static class Range { | ||
bentsherman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| int min | ||
| int max | ||
|
|
||
| Range(int min, int max) { | ||
| this.min = min | ||
| this.max = max | ||
| } | ||
|
|
||
| boolean contains(int value) { | ||
| min <= value && value <= max | ||
| } | ||
|
|
||
| boolean isSingle() { | ||
| max == 1 | ||
| } | ||
|
|
||
| @Override | ||
| boolean equals(Object obj) { | ||
| min == obj.min && max == obj.max | ||
| } | ||
|
|
||
| @Override | ||
| String toString() { | ||
| min == max | ||
| ? min.toString() | ||
| : "${min}..${max == Integer.MAX_VALUE ? '*' : max}".toString() | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
modules/nextflow/src/test/groovy/nextflow/script/params/ArityParamTest.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * Copyright 2023, Seqera Labs | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package nextflow.script.params | ||
|
|
||
| import spock.lang.Specification | ||
| import spock.lang.Unroll | ||
| /** | ||
| * | ||
| * @author Ben Sherman <[email protected]> | ||
| */ | ||
| class ArityParamTest extends Specification { | ||
|
|
||
| static class DefaultArityParam implements ArityParam { | ||
| DefaultArityParam() {} | ||
| } | ||
|
|
||
| @Unroll | ||
| def testArity () { | ||
|
|
||
| when: | ||
| def param = new DefaultArityParam() | ||
| param.setArity(VALUE) | ||
| then: | ||
| param.arity.min == MIN | ||
| param.arity.max == MAX | ||
|
|
||
| where: | ||
| VALUE | MIN | MAX | ||
| '1' | 1 | 1 | ||
| '0..1' | 0 | 1 | ||
| '1..*' | 1 | Integer.MAX_VALUE | ||
| } | ||
|
|
||
| @Unroll | ||
| def testArityRange () { | ||
|
|
||
| when: | ||
| def range = new ArityParam.Range(MIN, MAX) | ||
| then: | ||
| range.contains(2) == TWO | ||
| range.isSingle() == SINGLE | ||
| range.toString() == STRING | ||
|
|
||
| where: | ||
| MIN | MAX | TWO | SINGLE | STRING | ||
| 1 | 1 | false | true | '1' | ||
| 0 | 1 | false | true | '0..1' | ||
| 1 | Integer.MAX_VALUE | true | false | '1..*' | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.