Skip to content

fix: fixed check for remote conda env pinning and post-deploy files; fixed conda env cleanup#3103

Merged
johanneskoester merged 2 commits intomainfrom
fix/conda-env-handling
Sep 25, 2024
Merged

fix: fixed check for remote conda env pinning and post-deploy files; fixed conda env cleanup#3103
johanneskoester merged 2 commits intomainfrom
fix/conda-env-handling

Conversation

@johanneskoester
Copy link
Copy Markdown
Contributor

@johanneskoester johanneskoester commented Sep 25, 2024

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

    • Enhanced cleanup process for conda environments, focusing on environment addresses.
    • Improved error handling and logging for removed environments and corresponding YAML files.
  • Bug Fixes

    • Corrected comments regarding post-deploy script execution.
  • Documentation

    • Updated logging for removed conda environments to provide clearer information.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 25, 2024

Walkthrough

The changes modify the conda_cleanup_envs method in the snakemake/persistence.py file to improve the cleanup process for conda environments. The logic now targets the address of each environment rather than their hash values, enhancing error handling and logging. The method checks for the existence of environment directories and corresponding YAML files, removing them if present and logging the actions taken. The cleanup of environment archives remains unchanged, continuing to utilize the content hash of the environments in use.

Changes

File Path Change Summary
snakemake/persistence.py Modified conda_cleanup_envs to focus on the address of environments for cleanup instead of hash values; enhanced logging for removed environments.

Possibly related PRs


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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 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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 151216a and 154eb19.

📒 Files selected for processing (3)
  • snakemake/deployment/conda.py (3 hunks)
  • snakemake/persistence.py (1 hunks)
  • snakemake/sourcecache.py (4 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
snakemake/deployment/conda.py (1)

Pattern **/*.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/persistence.py (1)

Pattern **/*.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/sourcecache.py (1)

Pattern **/*.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.

🔇 Additional comments not posted (15)
snakemake/persistence.py (1)

Line range hint 1-1023: Overall assessment of changes to conda environment cleanup

The modifications to the conda_cleanup_envs method represent a positive step towards more efficient management of conda environments in Snakemake. The focus on cleaning up non-named environments and their associated YAML files is a good approach.

However, as noted in the previous comment, there's room for improvement in terms of error handling, logging specificity, and potentially adding a dry-run option. These enhancements would make the cleanup process more robust and informative for users.

The changes align well with the PR objectives of fixing the conda environment cleanup process. They should contribute to better management of conda environments within the Snakemake framework.

snakemake/sourcecache.py (8)

28-28: Importing logger for logging retry attempts

The addition of from snakemake.logging import logger is necessary for logging retry attempts, which enhances debugging and monitoring capabilities.


374-374: Setting retries=1 in exists method

By setting retries=1 when calling _cache in the exists method, the code ensures that the existence check is quick and avoids unnecessary delays from multiple retries. This seems appropriate for a rapid existence check.


395-395: Adding retries parameter to _cache method

Introducing the retries parameter with a default value of 3 in the _cache method allows for flexibility in controlling the number of retry attempts during caching operations, enhancing robustness against transient errors.


398-398: Propagating retries to _do_cache method

Passing the retries parameter to _do_cache ensures consistent retry behavior throughout the caching process, maintaining alignment with the specified number of retries.


401-401: Including retries in _do_cache method signature

Adding the retries parameter to the _do_cache method allows it to control the retry logic when opening the source file, which enhances error handling during caching.


403-403: Passing retries to _open_local_or_remote

By passing retries to _open_local_or_remote, the code ensures that the retry logic is applied when opening the source file, which is critical for handling transient I/O errors.


428-430: Modifying _open_local_or_remote to accept retries

Including the retries parameter in the _open_local_or_remote method signature provides control over the number of retry attempts when opening files, enhancing the method's flexibility and robustness.


437-442: Utilizing retry_call with logging for retries

Using retry_call with the logger parameter enables logging of retry attempts, which aids in debugging and monitoring. The specified tries, delay, and backoff parameters provide a balanced retry strategy.

snakemake/deployment/conda.py (6)

98-105: Implemented _path_or_uri_prefix method to extract file prefix

The new method _path_or_uri_prefix correctly extracts the prefix from the conda environment file path, handling files that end with .yaml or .yml. It returns the prefix without the extension or None if the file has a different extension. This enhances code modularity and reusability.


108-112: Refactored pin_file property to use _get_aux_file

The pin_file property now utilizes the _get_aux_file method, centralizing the logic for locating auxiliary files related to the conda environment. This refactoring improves maintainability by reducing code duplication.


117-122: Refactored post_deploy_file property to use _get_aux_file

Similarly, the post_deploy_file property has been refactored to use _get_aux_file. This change further centralizes auxiliary file retrieval, enhancing code consistency and reusability.


124-140: Added _get_aux_file method to centralize auxiliary file retrieval

The new _get_aux_file method encapsulates the logic for retrieving auxiliary files based on a given suffix and a custom omission message. It checks if the environment file exists, extracts the prefix, and constructs the auxiliary file path. It also logs a warning if the environment file does not have the expected .yaml or .yml extension. This addition improves code modularity and simplifies future maintenance.


Line range hint 602-606: Ensured execution of post-deploy script after environment creation

The code now executes the post-deployment script if it is present after the conda environment is created. This change ensures that any necessary post-deployment steps are performed, enhancing the functionality of the deployment process.


628-629: Added cleanup of temporary pin files

Temporary pin files are now properly removed after the environment creation process. This cleanup prevents leftover temporary files, reducing potential clutter and conflicts in the environment directory.

@sonarqubecloud
Copy link
Copy Markdown

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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 154eb19 and 55fbf8d.

📒 Files selected for processing (1)
  • snakemake/persistence.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
snakemake/persistence.py (1)

Pattern **/*.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.

Ruff
snakemake/persistence.py

266-266: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


273-275: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

@johanneskoester johanneskoester merged commit 4d0a7e9 into main Sep 25, 2024
@johanneskoester johanneskoester deleted the fix/conda-env-handling branch September 25, 2024 11:01
johanneskoester pushed a commit that referenced this pull request Sep 25, 2024
🤖 I have created a release *beep* *boop*
---


##
[8.20.5](v8.20.4...v8.20.5)
(2024-09-25)


### Bug Fixes

* fixed check for remote conda env pinning and post-deploy files; fixed
conda env cleanup
([#3103](#3103))
([4d0a7e9](4d0a7e9))
* omit storage downloads during dryrun in workflows with checkpoints
([#3100](#3100))
([151216a](151216a))

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

1 participant