Skip to content

feat: xonsh support#3310

Merged
johanneskoester merged 11 commits intosnakemake:mainfrom
jsquaredosquared:xonsh-support
Mar 10, 2025
Merged

feat: xonsh support#3310
johanneskoester merged 11 commits intosnakemake:mainfrom
jsquaredosquared:xonsh-support

Conversation

@jsquaredosquared
Copy link
Copy Markdown
Contributor

@jsquaredosquared jsquaredosquared commented Feb 23, 2025

This pull request adds the ability to use Xonsh scripts (relevant issue).

Because Xonsh is a superset of Python, I just inherited the PythonScript class but overrode the execute_script method.

QC

  • The PR contains a test case for the changes or the changes are already covered by an existing test case.
  • The documentation (docs/) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake).

Summary by CodeRabbit

  • New Features
    • Introduced support for executing Xonsh scripts, allowing users to leverage additional shell functionalities within workflows.
  • Documentation
    • Expanded the documentation with a dedicated section on integrating and using Xonsh scripts in workflows.
  • Tests
    • Added test workflows and environment configurations to verify and demonstrate the new Xonsh script support.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 23, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This pull request integrates support for Xonsh scripts into Snakemake. The documentation now includes a section on using Xonsh scripts along with an example rule. In the core code, a new XonshScript class is added with an execute_script method, the language detection is updated to handle .xsh files, and appropriate mappings and error messages are revised. Additionally, new test files have been added—a workflow Snakefile, a Conda environment YAML, a test script, and a test function—ensuring that the Xonsh integration is validated.

Changes

File(s) Change Summary
docs/snakefiles/rules.rst Added a new documentation section for integrating Xonsh scripts, including an example rule with input, output, and script execution details.
snakemake/script/__init__.py Introduced the XonshScript class (inheriting from PythonScript) with an execute_script method; updated the get_language function to recognize .xsh extensions; amended the language mapping and error messages to support Xonsh.
tests/test_script_xsh/Snakefile, .../envs/xonsh.yaml, .../scripts/test.xsh Added a new test workflow: a Snakefile defining rules to execute a Xonsh script, a Conda environment YAML for dependencies (including xonsh), and a test script that outputs a simple message.
tests/tests_using_conda.py Added a new test function test_script_xsh (decorated to skip on Windows and run in Conda) to validate the execution of the Xonsh-based workflow.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SnakemakeEngine
    participant XonshScript
    participant Shell

    User->>SnakemakeEngine: Start workflow execution
    SnakemakeEngine->>XonshScript: Invoke execute_script with .xsh file
    XonshScript->>Shell: Execute "xonsh {fname:q}" command
    Shell-->>XonshScript: Return execution result
    XonshScript-->>SnakemakeEngine: Return script output
    SnakemakeEngine-->>User: Complete workflow execution
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ab5be4 and c2e9c52.

📒 Files selected for processing (1)
  • tests/tests_using_conda.py (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/snakefiles/rules.rst (1)

1609-1628: Clarify and Enhance Xonsh Integration Documentation

The new Xonsh section is a clear and concise addition that demonstrates how to use a Xonsh script (with the .xsh extension) via the script: directive. It properly provides the reference link (https://xon.sh) and follows the style of other language integrations in this document.

A few suggestions:

  • Consider adding a brief note advising users to ensure that the Xonsh interpreter is installed in their environment. For example, you could mention “Ensure that Xonsh is available (e.g. via pip install xonsh) to run these scripts.”
  • For consistency and clarity, you might use a specific rule name (e.g. rule my_xonsh_rule:) in the sample code instead of the placeholder “NAME.” This may help users immediately recognize the example’s intent.

Overall, the integration instructions are clear and align well with the PR objectives.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04f89d3 and 9fec622.

⛔ Files ignored due to path filters (1)
  • tests/test_script_xsh/expected-results/test.out is excluded by !**/*.out
📒 Files selected for processing (5)
  • docs/snakefiles/rules.rst (1 hunks)
  • snakemake/script/__init__.py (3 hunks)
  • tests/test_script_xsh/Snakefile (1 hunks)
  • tests/test_script_xsh/envs/xonsh.yaml (1 hunks)
  • tests/test_script_xsh/scripts/test.xsh (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • tests/test_script_xsh/scripts/test.xsh
  • tests/test_script_xsh/envs/xonsh.yaml
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.py`: Do not try to improve formatting. Do not suggest ...

**/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

  • snakemake/script/__init__.py
🔇 Additional comments (3)
tests/test_script_xsh/Snakefile (1)

1-13: LGTM! Well-structured test workflow.

The Snakefile is well-organized with proper rule definitions, relative paths for conda environment and script files, and clear output specification.

snakemake/script/__init__.py (2)

1600-1603: LGTM! Clean and focused implementation.

The XonshScript class follows the single responsibility principle by only overriding the necessary method to support Xonsh execution.


1667-1668: LGTM! Consistent language support integration.

The changes follow the established patterns for:

  • File extension recognition (.xsh)
  • Executor class mapping
  • Error message updates

Also applies to: 1732-1732, 1736-1736

@jsquaredosquared jsquaredosquared changed the title Xonsh support feat: xonsh support Feb 23, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9fec622 and d8a4757.

📒 Files selected for processing (2)
  • tests/test_script_xsh/Snakefile (1 hunks)
  • tests/tests.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_script_xsh/Snakefile
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.py`: Do not try to improve formatting. Do not suggest ...

**/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

  • tests/tests.py
🔇 Additional comments (1)
tests/tests.py (1)

425-429: LGTM! The test function follows the established pattern.

The new test function test_script_xsh() is well-placed between similar script-related tests and follows the same pattern as test_script_python() and test_script_rs(). The decorators @skip_on_windows and @conda are appropriately used, consistent with other script tests.

@fgvieira
Copy link
Copy Markdown
Contributor

Thanks for your contribution. Can you fix the conflicts?

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d8a4757 and 51204a9.

📒 Files selected for processing (2)
  • docs/snakefiles/rules.rst (1 hunks)
  • tests/tests.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/snakefiles/rules.rst
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.py`: Do not try to improve formatting. Do not suggest ...

**/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

  • tests/tests.py
🪛 Ruff (0.8.2)
tests/tests.py

416-416: Undefined name conda

(F821)


422-422: Undefined name conda

(F821)

🔇 Additional comments (2)
tests/tests.py (2)

415-428: Enhance Xonsh script test coverage

While adding basic support for Xonsh scripts is good, the test coverage could be expanded as suggested in previous reviews.

Currently, the basic test in tests/tests.py runs the valid Xonsh script in tests/test_script_xsh/scripts/test.xsh via the Snakefile in tests/test_script_xsh/. While this confirms that the script executes correctly under normal conditions, further tests are required to ensure robust functionality. Specifically, please consider:

  • Error Handling: Add tests that deliberately invoke invalid Xonsh scripts to verify graceful error handling.
  • Xonsh-Specific Behavior: Incorporate tests to assess and validate unique Xonsh syntax or features.
  • Workflow Integration: Expand integration tests in the Snakefile to cover edge cases and the interplay with Snakemake's workflow system.
🧰 Tools
🪛 Ruff (0.8.2)

416-416: Undefined name conda

(F821)


422-422: Undefined name conda

(F821)


421-428:

Details

❓ Verification inconclusive

New test function for Rust script support

This test is similar to the previous one but includes additional parameters for deployment method and disables MD5 checks. Like the Xonsh test, it also has the same potential issue with the conda decorator.


🏁 Script executed:

#!/bin/bash
# Examine the test directory structure to understand test requirements
echo "Checking test_script_rs directory contents:"
find tests/test_script_rs -type f | sort

# Check if there are any other tests that use the conda decorator
grep -r "@conda" --include="*.py" .

Length of output: 1849


Rust Test Function: Verify @conda Decorator Behavior

The new test (test_script_rs) in tests/tests.py correctly mirrors the existing pattern seen in similar tests (e.g., the Xonsh test) by setting the deployment method to DeploymentMethod.CONDA and disabling MD5 checks. Our directory inspection confirms that the tests/test_script_rs structure is intact, and a repository-wide search shows that the @conda decorator is used consistently across several test files.

However, as with the Xonsh test, please manually verify that the behavior of the @conda decorator (especially under conditions where it might be problematic) meets expected requirements.

  • Test Directory Structure: tests/test_script_rs contains all expected scripts, configuration, and expected result files.
  • Decorator Consistency: The @conda decorator is also present in other tests (e.g., in tests/tests_using_conda.py and elsewhere in tests/tests.py), indicating its widespread use.

Please review the decorator’s behavior in your test environment to ensure no unintended side effects occur.

🧰 Tools
🪛 Ruff (0.8.2)

422-422: Undefined name conda

(F821)

tests/tests.py Outdated
Comment on lines +415 to +419
@skip_on_windows
@conda
def test_script_xsh():
run(dpath("test_script_xsh"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

New test function for Xonsh script support

The test function appropriately uses the @skip_on_windows decorator since Xonsh may have platform-specific behaviors. However, the static analyzer indicates that conda might be undefined in this context.


🏁 Script executed:

#!/bin/bash
# Check if conda decorator is properly defined in the codebase
grep -r "def conda" --include="*.py" .

Length of output: 846


Action Required: Properly Define or Import the 'conda' Decorator

The new test function uses the @conda decorator, but after verification, there’s no standalone decorator definition for conda in the codebase. The only mentions of def conda appear as methods within class implementations (such as in snakemake/deployment/conda.py), and thus don’t provide the expected decorator functionality.

  • Confirm whether a dedicated, top-level conda decorator should be defined or imported.
  • If it should be imported (e.g., from snakemake/deployment/conda.py), update the imports in tests/tests.py accordingly.
  • Otherwise, implement a proper decorator to handle the intended behavior in the test context.
🧰 Tools
🪛 Ruff (0.8.2)

416-416: Undefined name conda

(F821)

@jsquaredosquared
Copy link
Copy Markdown
Contributor Author

Thanks for your contribution. Can you fix the conflicts?

Hi, I think they are resolved now :)

@fgvieira
Copy link
Copy Markdown
Contributor

I think you need to add xonsh to the dependencies:
/usr/bin/bash: line 1: xonsh: command not found

@jsquaredosquared
Copy link
Copy Markdown
Contributor Author

I think you need to add xonsh to the dependencies: /usr/bin/bash: line 1: xonsh: command not found

I have updated the test to create a conda environment with xonsh in it. This should allow the test to pass.

Copy link
Copy Markdown
Contributor

@johanneskoester johanneskoester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks a lot!

@johanneskoester johanneskoester enabled auto-merge (squash) March 10, 2025 17:16
@johanneskoester johanneskoester enabled auto-merge (squash) March 10, 2025 17:17
@sonarqubecloud
Copy link
Copy Markdown

@johanneskoester johanneskoester merged commit d1c369b into snakemake:main Mar 10, 2025
9 of 10 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in Snakemake Hackathon March 2025 Mar 10, 2025
johanneskoester pushed a commit that referenced this pull request Mar 11, 2025
🤖 I have created a release *beep* *boop*
---


##
[8.30.0](v8.29.3...v8.30.0)
(2025-03-11)


### Features

* Add extra input size properties
([#2424](#2424))
([359ae2e](359ae2e))
* shell function calls inside of the 'run' directive now use conda,
container, or envmodules specifications
([#2289](#2289))
([0193e34](0193e34))
* xonsh support for script directive
([#3310](#3310))
([d1c369b](d1c369b))


### Bug Fixes

* include unit test templates in `setup.py`
([#3362](#3362))
([b47252c](b47252c))


### Documentation

* clearly explain report rendering to ZIP archive
([#3357](#3357))
([948e8fb](948e8fb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Mar 29, 2025
2 tasks
@jsquaredosquared jsquaredosquared deleted the xonsh-support branch April 26, 2025 08:07
@coderabbitai coderabbitai bot mentioned this pull request Nov 3, 2025
2 tasks
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
<!--Add a description of your PR here-->
This pull request adds the ability to use Xonsh scripts ([relevant
issue](snakemake#1433)).

Because Xonsh is a superset of Python, I just inherited the
`PythonScript` class but overrode the `execute_script` method.

### QC
<!-- Make sure that you can tick the boxes below. -->

* [x] The PR contains a test case for the changes or the changes are
already covered by an existing test case.
* [x] The documentation (`docs/`) is updated to reflect the changes or
this is not necessary (e.g. if the change does neither modify the
language nor the behavior or functionalities of Snakemake).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Introduced support for using Xonsh scripts in workflows, including
automatic recognition of Xonsh files and improved script execution.
- **Documentation**
- Extended the user guide with a new section detailing how to leverage
Xonsh scripting, complete with an illustrative example.
- **Tests**
- Added tests with new workflow rules, environment setups, and a sample
script to verify the Xonsh integration.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Filipe G. Vieira <1151762+fgvieira@users.noreply.github.com>
Co-authored-by: Johannes Koester <johannes.koester@uni-due.de>
Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de>
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
🤖 I have created a release *beep* *boop*
---


##
[8.30.0](snakemake/snakemake@v8.29.3...v8.30.0)
(2025-03-11)


### Features

* Add extra input size properties
([snakemake#2424](snakemake#2424))
([359ae2e](snakemake@359ae2e))
* shell function calls inside of the 'run' directive now use conda,
container, or envmodules specifications
([snakemake#2289](snakemake#2289))
([0193e34](snakemake@0193e34))
* xonsh support for script directive
([snakemake#3310](snakemake#3310))
([d1c369b](snakemake@d1c369b))


### Bug Fixes

* include unit test templates in `setup.py`
([snakemake#3362](snakemake#3362))
([b47252c](snakemake@b47252c))


### Documentation

* clearly explain report rendering to ZIP archive
([snakemake#3357](snakemake#3357))
([948e8fb](snakemake@948e8fb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants