Skip to content

fix: typo in CondaEnvDirSpec.__eq__ (issue #3192)#3613

Merged
johanneskoester merged 3 commits into
snakemake:mainfrom
mmmaat:fix_issue_3192
Jun 13, 2025
Merged

fix: typo in CondaEnvDirSpec.__eq__ (issue #3192)#3613
johanneskoester merged 3 commits into
snakemake:mainfrom
mmmaat:fix_issue_3192

Conversation

@mmmaat

@mmmaat mmmaat commented Jun 5, 2025

Copy link
Copy Markdown
Contributor

Issue #3192 is related to a typo in CondaEnvDirSpec.__eq__. This PR fixes this issue and add a test case.
Fixes #3192

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

Summary by CodeRabbit

  • Bug Fixes

    • Improved the handling of conda environment directory comparisons to ensure correct behavior when matching environment paths.
  • Tests

    • Added a new test workflow to verify conda environment handling, including sample input, expected output, and supporting scripts.
    • Introduced a dedicated test to validate the new conda environment behavior.

@mmmaat mmmaat requested a review from johanneskoester as a code owner June 5, 2025 09:09
@coderabbitai

coderabbitai Bot commented Jun 5, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes correct the equality comparison in the CondaEnvDirSpec class and introduce a new test workflow (test_issue3192) that verifies conda environment usage in Snakemake. The test includes a Snakefile, input and expected output files, a script for file copying, and a new test function to automate the process.

Changes

File(s) Change Summary
src/snakemake/deployment/conda.py Fixed CondaEnvDirSpec.__eq__ to compare self.path with other.path instead of other.file.
tests/test_issue3192/Snakefile Added workflow defining rules using a shared conda environment and a script for file processing.
tests/test_issue3192/a.txt Added input file containing "some text".
tests/test_issue3192/expected-results/c.txt Added expected output file containing "some text".
tests/test_issue3192/script.py Added script to copy input file to output file using shutil.copyfile.
tests/tests_using_conda.py Added test_issue_3192 to create a conda env and run the new test workflow.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant Shell
    participant Conda
    participant Snakemake
    participant Script

    TestRunner->>Shell: Execute "conda create -y -n test_issue3192 python"
    Shell->>Conda: Create environment
    Conda-->>Shell: Environment ready
    TestRunner->>Snakemake: Run workflow "test_issue3192" with CONDA deployment
    Snakemake->>Conda: Activate environment at conda_env
    Snakemake->>Script: Run script.py for a2b (a.txt -> b.txt)
    Script->>Script: Copy a.txt to b.txt
    Snakemake->>Script: Run script.py for b2c (b.txt -> c.txt)
    Script->>Script: Copy b.txt to c.txt
    Snakemake-->>TestRunner: Workflow complete, verify c.txt
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix AttributeError caused by CondaEnvDirSpec comparing self.path with other.file (#3192)
Ensure conda environment equality comparison uses correct attribute to avoid runtime errors
Provide a test case that reproduces the issue with conda environments and checkpoints

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Suggested reviewers

  • johanneskoester

📜 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 4805c0a and c1aa2df.

📒 Files selected for processing (1)
  • tests/tests_using_conda.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/tests_using_conda.py
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@mmmaat mmmaat changed the title Fixing issue #3192 fix: typo in CondaEnvDirSpec.__eq__ (issue #3192) Jun 5, 2025

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/tests_using_conda.py (1)

324-333: Consider adding error handling and cleanup for the conda environment.

The test follows the established pattern in this file, but consider these improvements:

  1. Add error handling for the conda environment creation
  2. Clean up the created environment after the test to prevent accumulation

Apply this diff to improve robustness:

 @conda
 def test_issue_3192():
-    sp.run(
-        "conda create -n test_issue3192 python",
-        shell=True,
-    )
-    run(
-        dpath("test_issue3192"),
-        deployment_method={DeploymentMethod.CONDA}
-    )
+    try:
+        sp.run(
+            "conda create -n test_issue3192 python",
+            shell=True,
+            check=True,
+        )
+        run(
+            dpath("test_issue3192"),
+            deployment_method={DeploymentMethod.CONDA}
+        )
+    finally:
+        # Cleanup the test environment
+        sp.run(
+            "conda env remove -n test_issue3192",
+            shell=True,
+            check=False,  # Don't fail if environment doesn't exist
+        )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 960f6a8 and 4805c0a.

📒 Files selected for processing (6)
  • src/snakemake/deployment/conda.py (1 hunks)
  • tests/test_issue3192/Snakefile (1 hunks)
  • tests/test_issue3192/a.txt (1 hunks)
  • tests/test_issue3192/expected-results/c.txt (1 hunks)
  • tests/test_issue3192/script.py (1 hunks)
  • tests/tests_using_conda.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.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 `s...

**/*.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/test_issue3192/script.py
  • src/snakemake/deployment/conda.py
  • tests/tests_using_conda.py
🧬 Code Graph Analysis (1)
tests/tests_using_conda.py (1)
tests/common.py (1)
  • dpath (32-35)
🪛 Ruff (0.11.9)
tests/test_issue3192/script.py

4-4: Undefined name snakemake

(F821)


5-5: Undefined name snakemake

(F821)

🪛 Pylint (3.3.7)
tests/test_issue3192/script.py

[error] 4-4: Undefined variable 'snakemake'

(E0602)


[error] 5-5: Undefined variable 'snakemake'

(E0602)

🔇 Additional comments (5)
tests/test_issue3192/a.txt (1)

1-1: LGTM! Simple test input file.

The content is appropriate for a test data file.

src/snakemake/deployment/conda.py (1)

970-970: Correctly fixes the equality comparison bug.

The change aligns with the consistent pattern used in similar classes (CondaEnvFileSpec compares file attributes, CondaEnvNameSpec compares name attributes), and CondaEnvDirSpec should indeed compare path attributes since that's what this class stores in its path field.

tests/test_issue3192/expected-results/c.txt (1)

1-1: LGTM! Appropriate expected test result.

The content matches the expected output for the test workflow.

tests/test_issue3192/script.py (1)

1-6: LGTM! Script correctly implements file copying for Snakemake workflow.

The script is functionally correct. The static analysis tools are flagging snakemake as undefined, but this is a false positive - the snakemake object is automatically injected by the Snakemake runtime when executing scripts, providing access to input/output paths and other workflow context.

🧰 Tools
🪛 Ruff (0.11.9)

4-4: Undefined name snakemake

(F821)


5-5: Undefined name snakemake

(F821)

🪛 Pylint (3.3.7)

[error] 4-4: Undefined variable 'snakemake'

(E0602)


[error] 5-5: Undefined variable 'snakemake'

(E0602)

tests/test_issue3192/Snakefile (1)

3-25: Well-structured test workflow for conda environment verification.

The workflow correctly defines a simple pipeline that processes files through intermediate steps using a shared conda environment. This structure effectively tests the conda environment integration that the PR aims to fix.

Comment thread tests/test_issue3192/Snakefile
@johanneskoester johanneskoester enabled auto-merge (squash) June 12, 2025 11:01
auto-merge was automatically disabled June 12, 2025 11:39

Head branch was pushed to by a user without write access

@mmmaat mmmaat requested a review from johanneskoester June 12, 2025 11:46
@johanneskoester johanneskoester enabled auto-merge (squash) June 13, 2025 10:42
@johanneskoester johanneskoester merged commit f4c107f into snakemake:main Jun 13, 2025
49 checks passed
@mmmaat mmmaat deleted the fix_issue_3192 branch June 13, 2025 11:05
johanneskoester pushed a commit that referenced this pull request Jun 16, 2025
🤖 I have created a release *beep* *boop*
---


##
[9.6.0](v9.5.1...v9.6.0)
(2025-06-16)


### Features

* Prefer papermill to nbconvert
([#2857](#2857))
([4263b03](4263b03))


### Bug Fixes

* DeprecationWarning when using snakemake.utils.validate
([#3420](#3420))
([cf72427](cf72427))
* display group jobs on dryrun
([#3435](#3435))
([3bebef4](3bebef4))
* expandvars for special profile keys
([#3597](#3597))
([4020188](4020188))
* fix bug causing --precommand to not being executed before each remote
job ([#3625](#3625))
([e59d125](e59d125))
* improved toggle switch behavior in reports
([#3623](#3623))
([0c4bd23](0c4bd23))
* pass envvars defined via the envvars directive to remote jobs
([#3626](#3626))
([d4890b4](d4890b4))
* remove wms arg, update logging cli docs
([#3622](#3622))
([3a9a5ac](3a9a5ac))
* typo in CondaEnvDirSpec.__eq__ (issue
[#3192](#3192))
([#3613](#3613))
([f4c107f](f4c107f))
* Unclear handling of params overriding with inheritance
([#3624](#3624))
([077ac4a](077ac4a))


### Documentation

* Added snakemake command to execute the rule plot_with_python
([#3608](#3608))
([bd99c11](bd99c11))
* Updated Reporting Section of The Tutorial(Interaction, Visualization,
and Reporting with Snakemake)
([#3606](#3606))
([91e90ba](91e90ba))
* Updated Requirement Section of The Tutorial With Warning of Not
Installing The Tools Manually
([#3607](#3607))
([3bd114b](3bd114b))
* Updated Wrapper Version in Tutorial and Used Simple Rule For
Consistency & Ease
([#3605](#3605))
([b3bcc21](b3bcc21))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
…#3613)

Issue snakemake#3192 is related to a typo in `CondaEnvDirSpec.__eq__`. This PR
fixes this issue and add a test case.
Fixes snakemake#3192

### 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

- **Bug Fixes**
- Improved the handling of conda environment directory comparisons to
ensure correct behavior when matching environment paths.

- **Tests**
- Added a new test workflow to verify conda environment handling,
including sample input, expected output, and supporting scripts.
- Introduced a dedicated test to validate the new conda environment
behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
kjohnsen pushed a commit to kjohnsen/snakemake that referenced this pull request Dec 15, 2025
🤖 I have created a release *beep* *boop*
---


##
[9.6.0](snakemake/snakemake@v9.5.1...v9.6.0)
(2025-06-16)


### Features

* Prefer papermill to nbconvert
([snakemake#2857](snakemake#2857))
([4263b03](snakemake@4263b03))


### Bug Fixes

* DeprecationWarning when using snakemake.utils.validate
([snakemake#3420](snakemake#3420))
([cf72427](snakemake@cf72427))
* display group jobs on dryrun
([snakemake#3435](snakemake#3435))
([3bebef4](snakemake@3bebef4))
* expandvars for special profile keys
([snakemake#3597](snakemake#3597))
([4020188](snakemake@4020188))
* fix bug causing --precommand to not being executed before each remote
job ([snakemake#3625](snakemake#3625))
([e59d125](snakemake@e59d125))
* improved toggle switch behavior in reports
([snakemake#3623](snakemake#3623))
([0c4bd23](snakemake@0c4bd23))
* pass envvars defined via the envvars directive to remote jobs
([snakemake#3626](snakemake#3626))
([d4890b4](snakemake@d4890b4))
* remove wms arg, update logging cli docs
([snakemake#3622](snakemake#3622))
([3a9a5ac](snakemake@3a9a5ac))
* typo in CondaEnvDirSpec.__eq__ (issue
[snakemake#3192](snakemake#3192))
([snakemake#3613](snakemake#3613))
([f4c107f](snakemake@f4c107f))
* Unclear handling of params overriding with inheritance
([snakemake#3624](snakemake#3624))
([077ac4a](snakemake@077ac4a))


### Documentation

* Added snakemake command to execute the rule plot_with_python
([snakemake#3608](snakemake#3608))
([bd99c11](snakemake@bd99c11))
* Updated Reporting Section of The Tutorial(Interaction, Visualization,
and Reporting with Snakemake)
([snakemake#3606](snakemake#3606))
([91e90ba](snakemake@91e90ba))
* Updated Requirement Section of The Tutorial With Warning of Not
Installing The Tools Manually
([snakemake#3607](snakemake#3607))
([3bd114b](snakemake@3bd114b))
* Updated Wrapper Version in Tutorial and Used Simple Rule For
Consistency & Ease
([snakemake#3605](snakemake#3605))
([b3bcc21](snakemake@b3bcc21))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

AttributeError when using existing conda environment with checkpoint

2 participants