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

Config parser (and loader) #4744

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ed0a5c2
Add custom config parser
bentsherman Feb 14, 2024
f850005
Add grammar files
bentsherman Feb 29, 2024
b7976c9
Fix build issue
bentsherman Feb 29, 2024
67c93c7
Use ParserPluginFactory to inject custom parser
bentsherman Mar 29, 2024
325cf6a
Restore legacy parser, add environment var to enable new parser
bentsherman Mar 29, 2024
17f3b06
Update docs
bentsherman Mar 29, 2024
011d0e2
cleanup
bentsherman Mar 29, 2024
97c8b8c
Update grammar to Groovy 4
bentsherman Mar 29, 2024
3b56d76
Simplify grammar
bentsherman Apr 5, 2024
a4409e1
Cleanup, fix bug with unary ops
bentsherman Apr 5, 2024
5a2d900
Add error reporting
bentsherman Apr 5, 2024
2fd3208
Add more error messages
bentsherman Apr 5, 2024
0fb9386
Update config AstBuilder to match groovy AstBuilder
bentsherman Apr 5, 2024
2d79804
Make assignments statements
bentsherman Apr 6, 2024
7e525df
Add source info to ast nodes
bentsherman Apr 6, 2024
4984ee4
Fix rendering of closure source code
bentsherman Apr 6, 2024
e466aef
Add if/else statement
bentsherman Apr 6, 2024
a6d89cd
Support gstring values without curly braces
bentsherman Apr 7, 2024
9c90f24
Merge branch 'master' into ben-config-parser
bentsherman Nov 26, 2024
1907791
Replace config parser with shared library
bentsherman Nov 26, 2024
6b0436c
Reorganize classes
bentsherman Jan 22, 2025
2882b80
Add config-to-groovy ast transform
bentsherman Jan 22, 2025
5c3d639
Merge branch 'master' into ben-config-parser
bentsherman Jan 22, 2025
e64598d
Add temporary hack to load shared library
bentsherman Jan 22, 2025
0a2b6e0
Fix failing tests
bentsherman Jan 22, 2025
8f73cfc
Fix failing test
bentsherman Jan 22, 2025
3a73cd2
Add shared library hack to integration tests
bentsherman Jan 23, 2025
a4cbea4
Publish language server to mavenLocal, trying to publish via jitpack
bentsherman Jan 29, 2025
6925fe5
Fix jitpack includeGroup
bentsherman Jan 30, 2025
ecacc00
Revert unnecessary changes
bentsherman Jan 30, 2025
5819d95
Update compiler dependency
bentsherman Feb 1, 2025
3727141
Fix includeConfig, minor edits
bentsherman Feb 1, 2025
9bdad11
Merge branch 'master' into ben-config-parser
bentsherman Feb 1, 2025
c9e4c0a
Add config ast visitors
bentsherman Feb 1, 2025
6c2bdff
Update unit tests
bentsherman Feb 3, 2025
7778557
Add strict parser to CI matrix
bentsherman Feb 5, 2025
0ea1d3c
Fix e2e tests
bentsherman Feb 5, 2025
571cfb0
Merge branch 'master' into ben-config-parser
bentsherman Feb 14, 2025
228c8ea
Fix failing tests
bentsherman Feb 14, 2025
f9a892c
Update docs
bentsherman Feb 14, 2025
217144a
Fix failing tests
bentsherman Feb 14, 2025
196032e
Fix failing test
bentsherman Feb 15, 2025
8aa6eee
Update docs, add unit tests
bentsherman Feb 18, 2025
33ef506
Fix failing test
bentsherman Feb 18, 2025
b8bf7b6
Merge branch 'master' into ben-config-parser
bentsherman Feb 19, 2025
8fe07d4
Add class descriptions
bentsherman Feb 19, 2025
6c727cd
Adjust CI tests
bentsherman Feb 19, 2025
83b547c
Update docs/config.md
bentsherman Feb 20, 2025
09f1498
cleanup
bentsherman Feb 24, 2025
ca26e26
Merge branch 'master' into ben-config-parser
pditommaso Feb 24, 2025
5511f65
Refactor legacy/impl -> v1/v2
bentsherman Feb 25, 2025
df99b11
Separate ClosureToStringVisitor from xform
bentsherman Feb 25, 2025
53565bc
Rename NXF_ENABLE_STRICT_SYNTAX -> NXF_SYNTAX_PARSER(=v2)
bentsherman Feb 25, 2025
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
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ jobs:
matrix:
java_version: [17, 23]
test_mode: ["test_integration", "test_docs", "test_aws", "test_azure", "test_google", "test_wave"]
strict_syntax: [true, false]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -171,6 +172,7 @@ jobs:
env:
TEST_JDK: ${{ matrix.java_version }}
TEST_MODE: ${{ matrix.test_mode }}
NXF_ENABLE_STRICT_SYNTAX: ${{ matrix.strict_syntax }}
GRADLE_OPTS: '-Dorg.gradle.daemon=false'
TOWER_ACCESS_TOKEN: ${{ secrets.TOWER_ACCESS_TOKEN }}
AWS_DEFAULT_REGION: eu-west-1
Expand All @@ -196,7 +198,7 @@ jobs:
uses: actions/upload-artifact@v4
if: always()
with:
name: report-${{ matrix.test_mode }}-jdk-${{ matrix.java_version }}
name: report-${{ matrix.test_mode }}-jdk-${{ matrix.java_version }}-strict-${{ matrix.strict_syntax }}
path: |
validation-tests.tar.gz
integration-tests.tar.gz
Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ allprojects {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url = "https://s3-eu-west-1.amazonaws.com/maven.seqera.io/releases" }
maven { url = "https://s3-eu-west-1.amazonaws.com/maven.seqera.io/snapshots" }
maven {
url 'https://jitpack.io'
content { includeGroup 'com.github.nextflow-io.language-server' }
}
}

configurations {
Expand Down
41 changes: 23 additions & 18 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,12 @@ With the above configuration:

## Config profiles

Configuration files can contain the definition of one or more *profiles*. A profile is a set of configuration attributes that can be selected during pipeline execution by using the `-profile` command line option.
Configuration files can define one or more *profiles*. A profile is a set of configuration settings that can be selected during pipeline execution using the `-profile` command line option.

Configuration profiles are defined by using the special scope `profiles`, which group the attributes that belong to the same profile using a common prefix. For example:
Configuration profiles are defined in the `profiles` scope. For example:

```groovy
profiles {

standard {
process.executor = 'local'
}
Expand All @@ -281,41 +280,47 @@ profiles {
process.container = 'cbcrg/imagex'
docker.enabled = true
}

}
```

This configuration defines three different profiles: `standard`, `cluster`, and `cloud`, that each set different process
configuration strategies depending on the target runtime platform. The `standard` profile is used by default when no profile is specified.
This configuration defines three profiles: `standard`, `cluster`, and `cloud`. Each profile provides a different configuration for a given execution environment. The `standard` profile is used by default when no profile is specified.

:::{tip}
Multiple configuration profiles can be specified by separating the profile names with a comma, for example:
Configuration profiles can be specified at runtime as a comma-separated list:

```bash
nextflow run <your script> -profile standard,cloud
```

Config profiles are applied in the order in which they were defined in the config file, regardless of the order they are specified on the command line.

:::{versionadded} 25.02.0-edge
When using the {ref}`strict config syntax <updating-config-syntax>`, profiles are applied in the order in which they are specified on the command line.
:::

:::{danger}
When using the `profiles` feature in your config file, do NOT set attributes in the same scope both inside and outside a `profiles` context. For example:
When defining a profile in the config file, avoid using both the dot and block syntax for the same scope. For example:

```groovy
process.cpus = 1

profiles {
foo {
process.memory = '2 GB'
}
foo {
process.memory = '2 GB'
process {
cpus = 2
}
}
}
```

bar {
process.memory = '4 GB'
}
Due to a limitation of the legacy config parser, the first setting will be overwritten by the second:

```console
$ nextflow config -profile foo
process {
cpus = 2
}
```

In the above example, the `process.cpus` attribute is not correctly applied because the `process` scope is also used in the `foo` and `bar` profiles.
This limitation can be avoided by using the {ref}`strict config syntax <updating-config-syntax>`.
:::

## Workflow handlers
Expand Down
5 changes: 5 additions & 0 deletions docs/reference/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ The following environment variables control the configuration of the Nextflow ru
:::
: Enable Nextflow *strict* execution mode (default: `false`)

`NXF_ENABLE_STRICT_SYNTAX`
: :::{versionadded} 25.02.0-edge
:::
: Enable the {ref}`strict syntax <updating-syntax-page>` for Nextflow config files.

`NXF_ENABLE_VIRTUAL_THREADS`
: :::{versionadded} 23.05.0-edge
:::
Expand Down
6 changes: 6 additions & 0 deletions docs/updating-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,14 @@ The process `when` section is deprecated. Use conditional logic, such as an `if`

The process `shell` section is deprecated. Use the `script` block instead. The VS Code extension provides syntax highlighting and error checking to help distinguish between Nextflow variables and Bash variables.

(updating-config-syntax)=

### Configuration syntax

:::{versionadded} 25.02.0-edge
The strict config syntax can be enabled in Nextflow by setting `NXF_ENABLE_STRICT_SYNTAX=true`.
:::

See {ref}`Configuration <config-syntax>` for a comprehensive description of the configuration language.

Currently, Nextflow parses config files as Groovy scripts, allowing the use of scripting constructs like variables, helper functions, try-catch blocks, and conditional logic for dynamic configuration:
Expand Down
1 change: 1 addition & 0 deletions modules/nextflow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ compileGroovy {
dependencies {
api(project(':nf-commons'))
api(project(':nf-httpfs'))
api 'com.github.nextflow-io.language-server:compiler:main-SNAPSHOT'
api "org.apache.groovy:groovy:4.0.25"
api "org.apache.groovy:groovy-nio:4.0.25"
api "org.apache.groovy:groovy-xml:4.0.25"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ class ConfigBuilder {

List<Path> parsedConfigFiles = []

List<String> parsedProfileNames

boolean showClosures

boolean stripSecrets
Expand Down Expand Up @@ -347,7 +345,7 @@ class ConfigBuilder {
assert env != null

final ignoreIncludes = options ? options.ignoreConfigIncludes : false
final slurper = new ConfigParser()
final slurper = ConfigParserFactory.create()
.setRenderClosureAsString(showClosures)
.setStripSecrets(stripSecrets)
.setIgnoreIncludes(ignoreIncludes)
Expand Down Expand Up @@ -384,9 +382,8 @@ class ConfigBuilder {
}
}

this.parsedProfileNames = new ArrayList<>(slurper.getProfileNames())
if( validateProfile ) {
checkValidProfile(slurper.getConditionalBlockNames())
checkValidProfile(slurper.getProfiles())
}

}
Expand Down Expand Up @@ -421,7 +418,7 @@ class ConfigBuilder {

log.debug "Applying config profile: `${profile}`"
def allNames = profile.tokenize(',')
slurper.registerConditionalBlock('profiles', allNames)
slurper.setProfiles(allNames)

def config = parse0(slurper,entry)
validate(config,entry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package nextflow.config
import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
/**
* Placeholder class that replacing closure definitions in the nextflow configuration
* file in order to print the closure content itself
* Placeholder class that replaces closure definitions in the nextflow configuration
* file in order to print the closure source text
*
* @author Paolo Di Tommaso <[email protected]>
*/
Expand Down
Loading