Skip to content

Commit

Permalink
feat: Support for Global workflow dependencies [8.0.0] syntax
Browse files Browse the repository at this point in the history
 Closes: #555
  • Loading branch information
iromeo committed Oct 22, 2024
1 parent be21e25 commit af1ccb1
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Released on <not released>
- Code completion: For section keywords show 'since' version and deprecation notice in the completion list. Do not suggest already removed keywords (see [#535](https://github.com/JetBrains-Research/snakecharm/issues/535)
- Set default project Snakemake language level in Snakemake support settings to 8.24.0
- [8.3.0] Support for: lookup, evaluate, branch, collect, exists (see [#548](https://github.com/JetBrains-Research/snakecharm/issues/548)
- [8.0.0] Support for Global workflow dependencies [8.0.0] syntax (see [#555](https://github.com/JetBrains-Research/snakecharm/issues/555)
- [8.0.0-6.8.1] Support for: 'storage', 'github', 'gitfile', 'gitlab' (see [#550](https://github.com/JetBrains-Research/snakecharm/issues/550)
- [7.25.0] Support for localrule directive (see [#524](https://github.com/JetBrains-Research/snakecharm/issues/524)
- [7.11] Resource scopes support (see [#510](https://github.com/JetBrains-Research/snakecharm/issues/510)
Expand Down
7 changes: 7 additions & 0 deletions snakemake_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ changelog:

# ---------------------------------------
- version: "8.0.0"
introduced:
- name: "conda"
type: "top-level"
docs_url: https://snakemake.readthedocs.io/en/stable/snakefiles/deployment.html#global-workflow-dependencies
multiple_args_allowed: False
keyword_args_allowed: False

removed:
- name: "snakemake.io.dynamic"
type: "function"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.jetbrains.snakecharm.lang.SnakemakeNames.SMK_VARS_WILDCARDS
import com.jetbrains.snakecharm.lang.SnakemakeNames.SMK_WITH_KEYWORD
import com.jetbrains.snakecharm.lang.SnakemakeNames.USE_EXCLUDE_KEYWORD
import com.jetbrains.snakecharm.lang.SnakemakeNames.USE_KEYWORD
import com.jetbrains.snakecharm.lang.SnakemakeNames.WORKFLOW_CONDA_KEYWORD
import com.jetbrains.snakecharm.lang.SnakemakeNames.WORKFLOW_CONFIGFILE_KEYWORD
import com.jetbrains.snakecharm.lang.SnakemakeNames.WORKFLOW_CONTAINERIZED_KEYWORD
import com.jetbrains.snakecharm.lang.SnakemakeNames.WORKFLOW_CONTAINER_KEYWORD
Expand Down Expand Up @@ -108,7 +109,19 @@ object SnakemakeApi {
WORKFLOW_PEPSCHEMA_KEYWORD,
WORKFLOW_PEPFILE_KEYWORD,
WORKFLOW_RESOURCE_SCOPES_KEYWORD,
WORKFLOW_SCATTERGATHER_KEYWORD
WORKFLOW_SCATTERGATHER_KEYWORD,
WORKFLOW_CONDA_KEYWORD
)

// TODO Move to YAML
val WORKFLOW_SECTIONS_WITH_FILE_REFERENCES = setOf(
WORKFLOW_CONFIGFILE_KEYWORD,
WORKFLOW_PEPFILE_KEYWORD,
WORKFLOW_PEPSCHEMA_KEYWORD,
WORKFLOW_INCLUDE_KEYWORD,
WORKFLOW_REPORT_KEYWORD,
WORKFLOW_WORKDIR_KEYWORD,
WORKFLOW_CONDA_KEYWORD
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ object SnakemakeNames {
const val WORKFLOW_CONTAINERIZED_KEYWORD = "containerized" // => 6.0.0
const val WORKFLOW_RESOURCE_SCOPES_KEYWORD = "resource_scopes" // => 7.11
const val WORKFLOW_SCATTERGATHER_KEYWORD = "scattergather" // => 7.11
const val WORKFLOW_CONDA_KEYWORD = "conda" // => 8.0.0

const val SUBWORKFLOW_KEYWORD = "subworkflow"
const val SUBWORKFLOW_WORKDIR_KEYWORD = WORKFLOW_WORKDIR_KEYWORD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class SmkPepschemaReference(

/**
* The path must built from directory with current snakefile
* version 6.5.1
* version 6.5.1 (rule) + 8.0.0 (workfklow)
*/
class SmkCondaEnvReference(
element: SmkArgsSection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.util.ArrayUtil
import com.jetbrains.python.psi.PyElementVisitor
import com.jetbrains.python.psi.PyStringLiteralExpression
import com.jetbrains.python.psi.impl.PyElementImpl
import com.jetbrains.snakecharm.codeInsight.SnakemakeApi.WORKFLOW_SECTIONS_WITH_FILE_REFERENCES
import com.jetbrains.snakecharm.lang.SnakemakeNames
import com.jetbrains.snakecharm.lang.parser.SmkTokenTypes
import com.jetbrains.snakecharm.lang.psi.*
Expand All @@ -15,16 +16,6 @@ import com.jetbrains.snakecharm.lang.psi.*
* @date 2019-02-03
*/
class SmkWorkflowArgsSectionImpl(node: ASTNode) : PyElementImpl(node), SmkWorkflowArgsSection {
companion object {
val WORKFLOWS_WITH_FILE_REFERENCES = setOf(
SnakemakeNames.WORKFLOW_CONFIGFILE_KEYWORD,
SnakemakeNames.WORKFLOW_PEPFILE_KEYWORD,
SnakemakeNames.WORKFLOW_PEPSCHEMA_KEYWORD,
SnakemakeNames.WORKFLOW_INCLUDE_KEYWORD,
SnakemakeNames.WORKFLOW_REPORT_KEYWORD,
SnakemakeNames.WORKFLOW_WORKDIR_KEYWORD
)
}

override fun acceptPyVisitor(pyVisitor: PyElementVisitor) = when (pyVisitor) {
is SmkElementVisitor -> pyVisitor.visitSmkWorkflowArgsSection(this)
Expand Down Expand Up @@ -58,6 +49,9 @@ class SmkWorkflowArgsSectionImpl(node: ASTNode) : PyElementImpl(node), SmkWorkfl
SnakemakeNames.WORKFLOW_WORKDIR_KEYWORD -> SmkWorkDirReference(
this, textRange, strExpr, path
)
SnakemakeNames.WORKFLOW_CONDA_KEYWORD -> SmkCondaEnvReference(
this, textRange, strExpr, path
)
else -> SmkIncludeReference(
this, textRange, strExpr, path
)
Expand All @@ -67,7 +61,7 @@ class SmkWorkflowArgsSectionImpl(node: ASTNode) : PyElementImpl(node), SmkWorkfl
override fun getReference(): PsiReference? = ArrayUtil.getFirstElement(this.references)

override fun getReferences(): Array<PsiReference> {
if (keywordName !in WORKFLOWS_WITH_FILE_REFERENCES) {
if (keywordName !in WORKFLOW_SECTIONS_WITH_FILE_REFERENCES) {
return emptyArray()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Feature: Completion for snakemake keyword-like things
| pepfile |
| pepschema |
| resource_scopes |
| conda |

Scenario Outline: Complete at top-level with respect to deprecations
Given a snakemake project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Feature: Complete file names in workflow sections
| report | html |
| pepfile | yaml |
| pepschema | yaml |
| conda | yaml |

Scenario: Completion list for directories in 'workdir' section
Given a snakemake project
Expand Down Expand Up @@ -96,7 +97,8 @@ Feature: Complete file names in workflow sections
| configfile | yml |
| report | html |
| pepfile | yaml |
| pepschema | yml |
| pepschema | yml |
| config | yaml |

Scenario: Completion list in 'workdir' section when there are no appropriate directories
Given a snakemake project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Feature: Rename files in workflow sections
| section | file_type |
| include | smk |
| configfile | yaml |
| conda | yaml |
| configfile | yml |
| report | html |

Expand All @@ -63,20 +64,25 @@ Feature: Rename files in workflow sections
"""
And reference should resolve to "Folder" directory

Scenario: Rename for directories in 'workdir' section
Scenario Outline: Rename for directories in 'workdir/conda' section
Given a snakemake project
Given a directory "Dir"
Given I open a file "foo.smk" with text
"""
workdir: "Dir"
<section>: "Dir"
"""
When I put the caret after Dir
When I invoke rename with name "Folder"
Then the file "foo.smk" should have text
"""
workdir: "Folder"
<section>: "Folder"
"""
And reference should resolve to "Folder" directory
Examples:
| section |
| workdir |
| conda |


Scenario Outline: Rename in conda/scripts/etc section
Given a snakemake project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Feature: Resolve workflow file names to their corresponding files
| report | html |
| pepfile | yaml |
| pepschema | yml |
| conda | yaml |

Scenario Outline: Reference doesn't resolve to inappropriate file
Given a snakemake project
Expand All @@ -37,7 +38,8 @@ Feature: Resolve workflow file names to their corresponding files
| configfile | yaml |
| report | html |
| pepfile | yaml |
| pepschema | yml |
| pepschema | yml |
| conda | yaml |

Scenario: Reference doesn't resolve to inappropriate Directory
Given a snakemake project
Expand Down Expand Up @@ -67,7 +69,8 @@ Feature: Resolve workflow file names to their corresponding files
| configfile | yaml |
| report | html |
| pepfile | yaml |
| pepschema | yml |
| pepschema | yml |
| conda | yaml |

Scenario Outline: Resolve for multiple files
Given a snakemake project
Expand Down

0 comments on commit af1ccb1

Please sign in to comment.