Skip to content

fix: include unit test templates in setup.py#3362

Merged
johanneskoester merged 5 commits intomainfrom
include-unit-test-templates-in-setup
Mar 11, 2025
Merged

fix: include unit test templates in setup.py#3362
johanneskoester merged 5 commits intomainfrom
include-unit-test-templates-in-setup

Conversation

@ezherman
Copy link
Copy Markdown
Contributor

@ezherman ezherman commented Mar 10, 2025

Fixes #3137

This PR forces inclusion of snakemake/snakemake/unit_tests/templates/ when building Snakemake.

/templates/`

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

  • Chores
    • Updated the package distribution by including additional unit test templates.
  • New Features
    • Introduced support for Xonsh scripts within Snakemake workflows.
    • Added a new YAML configuration for managing conda environments, specifying Xonsh as a dependency.
    • Created a new test workflow utilizing Xonsh scripts.
  • Bug Fixes
    • Enhanced error messaging to include support for Xonsh scripts.
  • Documentation
    • Added a new section in the Snakemake documentation for Xonsh integration.
  • Tests
    • Added a new test case for the Xonsh script functionality.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 10, 2025

📝 Walkthrough

Walkthrough

The pull request introduces several changes, including the addition of a new entry in the package_data dictionary in setup.py to include unit test templates. It also enhances the documentation for Snakemake by adding a section on Xonsh script integration. A new class XonshScript is introduced to execute Xonsh scripts, along with corresponding updates to the language recognition and error handling. Additionally, new test files and an environment configuration for Xonsh are created, and test coverage is expanded with new test cases.

Changes

File Change Summary
setup.py Added the "unit_tests/templates/*" entry to the package_data dictionary to include unit test template files in the package.
docs/snakefiles/rules.rst Added a new section detailing Xonsh script integration, including an example rule for specifying input/output files and Xonsh script paths.
snakemake/script/init.py Introduced XonshScript class, added execute_script method, updated get_language to recognize .xsh files, and modified error messages for unsupported scripts.
tests/test_script_xsh/Snakefile Created a new Snakefile defining all and test_xonsh rules, with test_xonsh executing a script and specifying a conda environment.
tests/test_script_xsh/envs/xonsh.yaml Added a new YAML configuration file specifying conda channels and xonsh as a dependency for the environment.
tests/test_script_xsh/scripts/test.xsh Added a line to test.xsh that outputs "Hello, world!" to the specified output file.
tests/tests_using_conda.py Added a new test function test_script_xsh, decorated to skip on Windows and run in a conda environment, enhancing conda-related test coverage.
test-environment.yml Added setuptools, cwltool, and cwl-utils to main dependencies, removed them from the pip section, altering dependency management.

Possibly related PRs


📜 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 ab11889 and cb641de.

⛔ Files ignored due to path filters (2)
  • tests/test_script_xsh/expected-results/test.out is excluded by !**/*.out
  • pyproject.toml is excluded by !pyproject.toml
📒 Files selected for processing (7)
  • 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)
  • tests/tests_using_conda.py (1 hunks)
  • test-environment.yml (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • tests/test_script_xsh/envs/xonsh.yaml
  • tests/test_script_xsh/scripts/test.xsh
🧰 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_using_conda.py
  • snakemake/script/__init__.py
⏰ Context from checks skipped due to timeout of 90000ms (40)
  • GitHub Check: testing (10, 3.12, dash)
  • GitHub Check: testing (10, 3.12, bash)
  • GitHub Check: testing (10, 3.11, bash)
  • GitHub Check: testing (9, 3.12, dash)
  • GitHub Check: testing (9, 3.12, bash)
  • GitHub Check: testing (9, 3.11, bash)
  • GitHub Check: testing (8, 3.12, dash)
  • GitHub Check: testing (8, 3.12, bash)
  • GitHub Check: testing (8, 3.11, bash)
  • GitHub Check: testing (7, 3.12, dash)
  • GitHub Check: testing (7, 3.12, bash)
  • GitHub Check: testing (7, 3.11, bash)
  • GitHub Check: testing (6, 3.12, dash)
  • GitHub Check: testing (6, 3.12, bash)
  • GitHub Check: testing (6, 3.11, bash)
  • GitHub Check: testing (5, 3.12, dash)
  • GitHub Check: testing (5, 3.12, bash)
  • GitHub Check: testing (5, 3.11, bash)
  • GitHub Check: testing (4, 3.12, dash)
  • GitHub Check: testing (4, 3.12, bash)
  • GitHub Check: testing (4, 3.11, bash)
  • GitHub Check: testing (3, 3.12, dash)
  • GitHub Check: testing-windows (10)
  • GitHub Check: testing (3, 3.12, bash)
  • GitHub Check: testing-windows (9)
  • GitHub Check: testing (3, 3.11, bash)
  • GitHub Check: testing-windows (8)
  • GitHub Check: testing (2, 3.12, dash)
  • GitHub Check: testing-windows (7)
  • GitHub Check: testing (2, 3.12, bash)
  • GitHub Check: testing-windows (6)
  • GitHub Check: testing (2, 3.11, bash)
  • GitHub Check: testing-windows (5)
  • GitHub Check: testing (1, 3.12, dash)
  • GitHub Check: testing-windows (4)
  • GitHub Check: testing (1, 3.12, bash)
  • GitHub Check: testing-windows (3)
  • GitHub Check: testing (1, 3.11, bash)
  • GitHub Check: testing-windows (2)
  • GitHub Check: testing-windows (1)
🔇 Additional comments (9)
tests/tests_using_conda.py (1)

309-315: Good addition of test for xonsh script functionality.

This test function appropriately uses the @skip_on_windows decorator since xonsh may have platform-specific behavior, and includes the @conda decorator to ensure the proper environment is used. The implementation follows the pattern of other similar test functions in this file.

tests/test_script_xsh/Snakefile (1)

1-13: Well-structured test Snakefile for xonsh script testing.

The Snakefile correctly defines a workflow with two rules: an all rule for the target output and a test_xonsh rule that uses a conda environment and executes a xonsh script. This follows Snakemake's standard structure and will ensure proper testing of xonsh script execution functionality.

docs/snakefiles/rules.rst (1)

1591-1610: Good documentation for Xonsh script integration.

This addition properly documents how to use Xonsh scripts in Snakemake workflows, clearly explaining that Xonsh is a superset of Python that provides additional shell primitives. The documentation includes a complete example showing the proper syntax for the script: directive with a .xsh file, maintaining consistency with the documentation style for other script types.

test-environment.yml (2)

7-7: Adding setuptools as a direct dependency is appropriate.

Including setuptools as a direct dependency ensures that the package is available during testing and for the PR's focus on including unit test templates in setup.py.


61-62: Moving cwltool and cwl-utils from pip to conda dependencies.

Moving these dependencies from pip to conda direct dependencies makes the environment more consistent and may improve compatibility. This change aligns with the goal of properly including templates in the build process.

snakemake/script/__init__.py (4)

1600-1603: Class implementation looks good.

The XonshScript class correctly inherits from PythonScript and overrides the execute_script method to use the Xonsh shell for execution.


1667-1668: Properly added Xonsh file detection.

The language detection for .xsh extension is correctly implemented in the get_language function.


1732-1732: Correctly registered the XonshScript executor.

The Xonsh script executor is properly mapped in the language-to-executor dictionary.


1736-1736: Updated error message to include Xonsh script support.

The error message for unsupported script types has been correctly updated to include Xonsh (.xsh) as a supported script type.

✨ 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.

@github-actions
Copy link
Copy Markdown
Contributor

Please format your code with black: black snakemake tests/*.py.

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 948e8fb and de74f34.

📒 Files selected for processing (1)
  • setup.py (1 hunks)
🧰 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.

  • setup.py
🪛 GitHub Actions: CI
setup.py

[error] 28-28: Black formatting check failed. 1 file would be reformatted. Please run 'black' to fix code style issues.

setup.py Outdated
"report/html_reporter/template/**/*",
"report/html_reporter/template/*",
"common/tests/testcases/**/*",
"snakemake/snakemake/unit_tests/templates/*"
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

The path structure seems duplicated - please verify it's correct.

The added line includes the path "snakemake/snakemake/unit_tests/templates/*", which contains a duplicated "snakemake" directory. Based on the existing entries, this should likely be either "unit_tests/templates/*" or just "snakemake/unit_tests/templates/*" depending on your project structure.

Additionally, the pipeline failure indicates a Black formatting issue. You'll need to run the Black formatter on this file before merging.


🏁 Script executed:

#!/bin/bash
# Check the actual directory structure to confirm if the path is correct
cd snakemake
ls -la
# See if there's a nested snakemake directory
if [ -d "snakemake" ]; then
  echo "There is indeed a nested snakemake directory"
  # Check if unit_tests exists in the nested directory
  if [ -d "snakemake/unit_tests" ]; then
    echo "And it contains unit_tests directory"
    if [ -d "snakemake/unit_tests/templates" ]; then
      echo "And it contains templates directory"
      ls -la snakemake/unit_tests/templates
    else
      echo "But templates directory was not found in snakemake/unit_tests"
    fi
  else
    echo "But unit_tests directory was not found in nested snakemake"
  fi
else
  echo "There is no nested snakemake directory"
  # Check if unit_tests exists directly
  if [ -d "unit_tests" ]; then
    echo "But unit_tests directory exists at root level"
    if [ -d "unit_tests/templates" ]; then
      echo "And it contains templates directory"
      ls -la unit_tests/templates
    else
      echo "But templates directory was not found in unit_tests"
    fi
  else
    echo "And unit_tests directory was not found at root level either"
  fi
fi

Length of output: 4043


Action Required: Correct the Duplicate Directory & Run Black Formatter

  • The verified directory structure confirms that the unit tests reside in snakemake/unit_tests/templates/. Please update the path in setup.py from
    "snakemake/snakemake/unit_tests/templates/*"
    to
    "snakemake/unit_tests/templates/*".
  • Additionally, re-run the Black formatter on setup.py to resolve the formatting issue causing the pipeline failure.

Copy link
Copy Markdown
Member

@dlaehnemann dlaehnemann left a comment

Choose a reason for hiding this comment

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

We also tested the file inclusion by running the build locally and checking the resulting .tar.gz file, so this seems to work as intended.

@ezherman ezherman changed the title fix: include unit test templates in fix: include unit test templates in setup.py Mar 11, 2025
@ezherman
Copy link
Copy Markdown
Contributor Author

@johanneskoester could you please review? This merge requires a review from a code owner.

@sonarqubecloud
Copy link
Copy Markdown

@johanneskoester johanneskoester merged commit b47252c into main Mar 11, 2025
20 of 50 checks passed
@johanneskoester johanneskoester deleted the include-unit-test-templates-in-setup branch March 11, 2025 11:56
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>
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
Fixes snakemake#3137

<!--Add a description of your PR here-->
This PR forces inclusion of `snakemake/snakemake/unit_tests/templates/`
when building Snakemake.

/templates/`

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

* [ ] 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

- **Chores**
- Updated the package distribution by including additional unit test
templates.
- **New Features**
  - Introduced support for Xonsh scripts within Snakemake workflows.
- Added a new YAML configuration for managing conda environments,
specifying Xonsh as a dependency.
  - Created a new test workflow utilizing Xonsh scripts.
- **Bug Fixes**
  - Enhanced error messaging to include support for Xonsh scripts.
- **Documentation**
- Added a new section in the Snakemake documentation for Xonsh
integration.
- **Tests**
  - Added a new test case for the Xonsh script functionality.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: David Laehnemann <david.laehnemann@hhu.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

None yet

Development

Successfully merging this pull request may close these issues.

--generate-unit-tests will raise error in 8.20.1 or newer version

3 participants