Skip to content

Conversation

@johanneskoester
Copy link
Contributor

@johanneskoester johanneskoester commented Mar 18, 2025

Summary by CodeRabbit

  • Documentation
    • Enhanced the README.md with detailed explanations regarding logging capabilities and provider access.
  • New Features
    • Introduced a new function to check available disk space.
    • Added asynchronous methods for improved size management and disk space handling in storage objects.
    • Enhanced logging support across the application for better monitoring and diagnostics.
  • Bug Fixes
    • Improved error handling related to disk space availability during object retrieval.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

📝 Walkthrough

Walkthrough

The changes update documentation and integrate logging into the storage system. The README now explains how the StorageProvider and StorageObject classes use logging, clarifying the roles of attributes such as self.logger and self.provider. In the implementation, the StorageProviderBase constructor now accepts a Logger parameter that is stored as an instance variable. The tests file has been updated to create and pass a logger instance to the provider. Additionally, new methods for managing disk space and logging have been introduced in the StorageObjectRead class.

Changes

File(s) Change Summary
README.md Enhanced documentation to clarify the logging capabilities in StorageProvider and the provider access in StorageObject.
snakemake_interface_storage_plugins/.../storage_provider.py Updated the StorageProviderBase constructor to accept a new logger parameter, added instance variable assignments for self.logger and self.wait_for_free_local_storage, and imported Logger from logging.
snakemake_interface_storage_plugins/.../tests.py Added a logger import and instance creation; updated the _get_provider method signature to include the logger argument for logging during tests.
snakemake_interface_storage_plugins/.../common.py Added a new function get_disk_free to return the amount of free disk space available on the partition containing the specified path.
snakemake_interface_storage_plugins/.../storage_object.py Introduced new asynchronous methods and modified existing method signatures in StorageObjectRead for size management and disk space handling. Added methods for local_footprint, managed_local_footprint, and wait_for_free_space.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Suite
    participant TP as _get_provider
    participant SP as StorageProviderBase
    participant LG as Logger

    T->>T: Create logger instance
    T->>TP: Call _get_provider(tmp_path, logger)
    TP->>SP: Instantiate StorageProviderBase with logger
    SP->>SP: Assign logger to self.logger
    SP-->>TP: Return provider instance
    TP-->>T: Provider instance returned
Loading
✨ 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
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

🧹 Nitpick comments (3)
snakemake_interface_storage_plugins/common.py (1)

24-25: Extra blank lines detected.

Consider removing these additional blank lines if they are not intentional for visual clarity.

-
-
snakemake_interface_storage_plugins/storage_object.py (2)

139-139: Trailing whitespace found.

Remove trailing whitespace to fix pipeline failure (W291). For instance:

🧰 Tools
🪛 GitHub Actions: CI

[warning] 139-139: W291 trailing whitespace


221-223: Line too long.

Wrap the lines to address pipeline failures (E501):

+                wait_time_step is not None
+                and waited < wait_time
+                and size > disk_free
+            ):
+                    f"Waiting {format_timespan(wait_time_step)} for enough free space "
+                    f"to "
+                )
🧰 Tools
🪛 GitHub Actions: CI

[error] 221-221: E501 line too long (89 > 88 characters)


[error] 223-223: E501 line too long (90 > 88 characters)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3117213 and bff2c1f.

⛔ Files ignored due to path filters (1)
  • pyproject.toml is excluded by !pyproject.toml
📒 Files selected for processing (3)
  • snakemake_interface_storage_plugins/common.py (2 hunks)
  • snakemake_interface_storage_plugins/storage_object.py (5 hunks)
  • snakemake_interface_storage_plugins/storage_provider.py (2 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.

  • snakemake_interface_storage_plugins/common.py
  • snakemake_interface_storage_plugins/storage_provider.py
  • snakemake_interface_storage_plugins/storage_object.py
🧬 Code Definitions (2)
snakemake_interface_storage_plugins/storage_provider.py (1)
snakemake_interface_storage_plugins/settings.py (1) (1)
  • StorageProviderSettingsBase (14:30)
snakemake_interface_storage_plugins/storage_object.py (2)
snakemake_interface_storage_plugins/common.py (2) (2)
  • Operation (16:23)
  • get_disk_free (26:31)
snakemake_interface_storage_plugins/io.py (1) (1)
  • size (93:93)
🪛 GitHub Actions: CI
snakemake_interface_storage_plugins/common.py

[warning] 31-31: W292 no newline at end of file

snakemake_interface_storage_plugins/storage_provider.py

[error] 191-191: TypeError: Can't instantiate abstract class StorageObject with abstract method local_footprint

snakemake_interface_storage_plugins/storage_object.py

[warning] 139-139: W291 trailing whitespace


[error] 221-221: E501 line too long (89 > 88 characters)


[error] 223-223: E501 line too long (90 > 88 characters)

🪛 Ruff (0.8.2)
snakemake_interface_storage_plugins/storage_object.py

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

(B904)

🔇 Additional comments (5)
snakemake_interface_storage_plugins/common.py (2)

8-9: Imports look good.


26-31: Functionality is straightforward and efficient.

The logic of climbing up the directory hierarchy before calling shutil.disk_usage accurately ensures correct partition usage.

🧰 Tools
🪛 GitHub Actions: CI

[warning] 31-31: W292 no newline at end of file

snakemake_interface_storage_plugins/storage_provider.py (1)

61-69: New logger and wait parameter look good.

Please verify existing tests are updated to include these constructor parameters. If not, consider adding a test ensuring logger is properly utilized and wait_for_free_local_storage is handled.

snakemake_interface_storage_plugins/storage_object.py (2)

140-142: Well-documented method signature.

The docstring clarifies behavior for directories. This is helpful for consumer code to understand return values.


143-149: Local footprint fallback is logically sound.

Using self.size() as a default respects older implementations. Good backward compatibility approach.

# this ensures that the disk usage is calculated for the correct partition
while not local_path.exists():
local_path = local_path.parent
return shutil.disk_usage(local_path).free No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing newline at end of file.

Add a newline to address pipeline failure (W292):

+    return shutil.disk_usage(local_path).free

+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return shutil.disk_usage(local_path).free
return shutil.disk_usage(local_path).free
🧰 Tools
🪛 GitHub Actions: CI

[warning] 31-31: W292 no newline at end of file

@johanneskoester johanneskoester changed the title feat: require passing the logger to the storage provider feat: introduce waiting for enough free space on local storage; require passing the logger to the storage provider Mar 18, 2025
Copy link
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 (3)
snakemake_interface_storage_plugins/storage_object.py (3)

212-216: Validate wait_time early to prevent unnecessary operations.

The validation of wait_time happens after retrieving the object size and checking free disk space. Consider moving this validation to the beginning of the method to fail fast if the configuration is invalid.

async def wait_for_free_space(self):
    """Wait for free space on the disk."""
+    wait_time = self.provider.wait_for_free_local_storage
+    if wait_time is not None and wait_time < 1:
+        raise WorkflowError(
+            "Wait time for free space on local storage has to be at least "
+            "1 second or unset."
+        )
+
    size = await self.managed_local_footprint()
    disk_free = get_disk_free(self.local_path())

-    wait_time = self.provider.wait_for_free_local_storage
-
-    if wait_time is not None:
-        if wait_time < 1:
-            raise WorkflowError(
-                "Wait time for free space on local storage has to be at least "
-                "1 second or unset."
-            )
+    if wait_time is not None:
        wait_time_step = 60 if wait_time > 60 else 1

219-220: Incorrect loop condition logic.

The loop condition wait_time_step is not None is redundant since wait_time_step is always assigned a value right before the loop. Additionally, the condition might be clearer with just the time and space checks.

-            while wait_time_step is not None and waited < wait_time and size > disk_free:
+            while waited < wait_time and size > disk_free:

230-236: Provide more actionable error message when disk space is insufficient.

The error message could be more helpful by suggesting actions the user could take when disk space is insufficient.

        if size > disk_free:
            raise WorkflowError(
                f"Cannot store {self.local_path()} "
                f"({format_size(size)} > {format_size(disk_free)}), "
                f"waited {format_timespan(self.provider.wait_for_free_local_storage)} "
-                "for more space."
+                "for more space. Consider freeing up disk space or increasing the "
+                "wait_for_free_local_storage setting if the space will become "
+                "available later."
            )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bff2c1f and 61bfd3a.

📒 Files selected for processing (1)
  • snakemake_interface_storage_plugins/storage_object.py (5 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.

  • snakemake_interface_storage_plugins/storage_object.py
🧬 Code Definitions (1)
snakemake_interface_storage_plugins/storage_object.py (2)
snakemake_interface_storage_plugins/common.py (2) (2)
  • Operation (16:23)
  • get_disk_free (26:31)
snakemake_interface_storage_plugins/io.py (1) (1)
  • size (93:93)
🪛 Ruff (0.8.2)
snakemake_interface_storage_plugins/storage_object.py

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

(B904)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: testing
🔇 Additional comments (8)
snakemake_interface_storage_plugins/storage_object.py (8)

6-6: Good addition of asyncio for async methods.

The addition of asyncio is appropriate for the new async methods, particularly for the sleep functionality used in the wait_for_free_space method.


15-15: Appropriate import for human-friendly formatting.

The humanfriendly library is well-suited for formatting sizes and time spans in log messages, making them more readable for users.


20-20: Good import of the get_disk_free function.

Correctly importing the get_disk_free function from common.py, which is used in the wait_for_free_space method.


139-141: Clear documentation for the size method.

Good addition of a docstring that clarifies the method should return size in bytes and specifies behavior for directories.


143-148: Good implementation of the local_footprint method with backward compatibility.

The method provides a clear API for determining the local disk footprint of objects, while maintaining backward compatibility by defaulting to self.size().


177-177: Good addition of disk space check before retrieval.

Adding a call to wait_for_free_space ensures there's sufficient disk space before attempting to retrieve an object, which helps prevent failed retrievals due to disk space constraints.


194-203: Use exception chaining while raising.

To distinguish this failure from errors in exception handling, apply the exception chaining pattern:

-            raise WorkflowError(
-                f"Failed to get expected local footprint (i.e. size) "
-                f"of {self.print_query}", e
-            )
+            raise WorkflowError(
+                f"Failed to get expected local footprint (i.e. size) "
+                f"of {self.print_query}"
+            ) from e
🧰 Tools
🪛 Ruff (0.8.2)

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

(B904)


204-237: Good implementation of the wait_for_free_space method.

The method properly:

  1. Checks available disk space against required size
  2. Implements a configurable wait mechanism
  3. Provides clear log messages with human-readable sizes and time spans
  4. Raises appropriate errors with informative messages

This approach to handling disk space constraints is robust and user-friendly.

Copy link
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)
snakemake_interface_storage_plugins/storage_object.py (1)

203-238: Fix line length in the logging statement.

The implementation of waiting for free space is well-structured and provides good user feedback through logging. The wait time parameters are validated, and appropriate error messages are provided.

Line 223 exceeds the character limit (90 > 88 characters). Please shorten it:

-                self.provider.logger.info(
-                    f"Waiting {format_timespan(wait_time_step)} for enough free space to "
-                    f"store {self.local_path()} "
-                    f"({format_size(size)} > {format_size(disk_free)})"
-                )
+                self.provider.logger.info(
+                    f"Waiting {format_timespan(wait_time_step)} for enough free space to"
+                    f" store {self.local_path()} "
+                    f"({format_size(size)} > {format_size(disk_free)})"
+                )
🧰 Tools
🪛 GitHub Actions: CI

[error] 223-223: E501 line too long (90 > 88 characters)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 61bfd3a and 0ff34d0.

📒 Files selected for processing (1)
  • snakemake_interface_storage_plugins/storage_object.py (6 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.

  • snakemake_interface_storage_plugins/storage_object.py
🧠 Learnings (1)
snakemake_interface_storage_plugins/storage_object.py (1)
Learnt from: johanneskoester
PR: snakemake/snakemake-interface-storage-plugins#68
File: snakemake_interface_storage_plugins/storage_object.py:194-203
Timestamp: 2025-03-18T14:04:45.477Z
Learning: The project prefers passing exceptions as a second argument to WorkflowError constructor (e.g., `raise WorkflowError("message", e)`) rather than using Python's exception chaining syntax (`raise WorkflowError("message") from e`). Do not suggest changing to the `from e` pattern even if linters like Ruff flag it with B904.
🧬 Code Definitions (1)
snakemake_interface_storage_plugins/storage_object.py (2)
snakemake_interface_storage_plugins/common.py (2) (2)
  • Operation (16:23)
  • get_disk_free (26:31)
snakemake_interface_storage_plugins/io.py (1) (1)
  • size (93:93)
🪛 Ruff (0.8.2)
snakemake_interface_storage_plugins/storage_object.py

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

(B904)


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

(B904)


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

(B904)

🪛 GitHub Actions: CI
snakemake_interface_storage_plugins/storage_object.py

[error] 223-223: E501 line too long (90 > 88 characters)

🔇 Additional comments (6)
snakemake_interface_storage_plugins/storage_object.py (6)

139-141: Enhanced documentation with clear return expectation.

The added docstring clearly describes that the method should return the size in bytes and specifies the expectation for directories (return 0). This improves code readability and maintainability.


143-148: Good addition of the local_footprint method.

This method provides a clear distinction between the logical size of an object and its actual footprint on disk. The default implementation maintains backward compatibility by returning self.size(), which is a good practice for API evolution.


175-175: LGTM: Disk space verification before retrieval.

Adding a call to wait_for_free_space before attempting to retrieve an object is a sensible enhancement that prevents failures due to insufficient disk space.


192-201: LGTM: Good error handling for local footprint operations.

The managed method for local footprint follows the established pattern in the codebase for other operations. The error message is clear and helpful for debugging.

🧰 Tools
🪛 Ruff (0.8.2)

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

(B904)


197-201: Note about exception handling pattern.

The project's preferred exception handling style is correctly implemented here. Keeping it consistent with the rest of the codebase.

🧰 Tools
🪛 Ruff (0.8.2)

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

(B904)


209-217: LGTM: Good validation of wait time parameter.

The code properly validates that the wait time is at least 1 second, providing a clear error message if the condition is not met. The step calculation is sensible, using smaller steps for short waits and larger steps for longer waits.

Copy link
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 (3)
snakemake_interface_storage_plugins/storage_object.py (3)

203-238: Consider adding buffer for free space requirement.

The implementation correctly waits for free space based on the provider's configuration. However, it only checks if size > disk_free without any buffer, which could lead to issues if other processes are also writing to disk.

Consider modifying to add a small buffer (e.g., 5-10%) to ensure there's enough headroom:

-        if size > disk_free:
+        # Add a 10% buffer to ensure we have enough space
+        required_space = int(size * 1.1)
+        if required_space > disk_free:
             raise WorkflowError(
-                f"Cannot store {self.local_path()} "
-                f"({format_size(size)} > {format_size(disk_free)}), "
+                f"Cannot store {self.local_path()} "
+                f"({format_size(size)}, need {format_size(required_space)} with buffer > {format_size(disk_free)}), "
                 f"waited {format_timespan(self.provider.wait_for_free_local_storage)} "
                 "for more space."
             )

217-217: Consider a more gradual waiting strategy.

The current implementation jumps from a 1-second wait to a 60-second wait depending on the total wait time. A more gradual approach might provide a better user experience.

-            wait_time_step = 60 if wait_time > 60 else 1
+            # More gradual wait time steps based on total wait time
+            if wait_time <= 10:
+                wait_time_step = 1
+            elif wait_time <= 120:
+                wait_time_step = 10
+            else:
+                wait_time_step = 60

235-235: Clarify actual wait time in error message.

The error message states the configured wait time, but the actual time waited might be less if the loop exited early. Using the waited variable would be more accurate.

-                f"waited {format_timespan(self.provider.wait_for_free_local_storage)} "
+                f"waited up to {format_timespan(waited)} "
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3eb410c and dbafc2a.

📒 Files selected for processing (1)
  • snakemake_interface_storage_plugins/storage_object.py (6 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.

  • snakemake_interface_storage_plugins/storage_object.py
🧠 Learnings (1)
snakemake_interface_storage_plugins/storage_object.py (1)
Learnt from: johanneskoester
PR: snakemake/snakemake-interface-storage-plugins#68
File: snakemake_interface_storage_plugins/storage_object.py:194-203
Timestamp: 2025-03-18T14:04:45.477Z
Learning: The project prefers passing exceptions as a second argument to WorkflowError constructor (e.g., `raise WorkflowError("message", e)`) rather than using Python's exception chaining syntax (`raise WorkflowError("message") from e`). Do not suggest changing to the `from e` pattern even if linters like Ruff flag it with B904.
🪛 Ruff (0.8.2)
snakemake_interface_storage_plugins/storage_object.py

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

(B904)


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

(B904)


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

(B904)

🔇 Additional comments (5)
snakemake_interface_storage_plugins/storage_object.py (5)

139-141: Good enhancement with added docstring.

Adding a clear docstring to the size() method helps clarify its expected behavior, especially the note about directories returning 0.


143-148: Well-designed addition of local_footprint method.

This method nicely extends the API to differentiate between remote object size and actual local disk footprint, which is crucial for disk space management. The backward compatibility approach through defaulting to self.size() is a good practice.


175-175: Good addition to check for space before retrieval.

Adding the wait_for_free_space() call ensures we don't attempt to retrieve files when there's insufficient disk space, which could prevent partial downloads and subsequent cleanup operations.


192-201: Properly implemented managed method for local_footprint.

This follows the established pattern for managed methods, correctly implementing rate limiting and error handling consistent with other methods in the class.

🧰 Tools
🪛 Ruff (0.8.2)

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

(B904)


197-201: Maintain consistent exception handling style.

The project's preferred exception handling style is correctly used here (raise WorkflowError("message", e)), consistent with the team's preference noted in the learnings.

🧰 Tools
🪛 Ruff (0.8.2)

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

(B904)

Copy link
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)
snakemake_interface_storage_plugins/storage_object.py (1)

203-236: Consider handling edge cases in wait_for_free_space

The implementation handles waiting for free space well, with good logging and error messages. Consider two small improvements:

  1. The error message when wait_time is None might be confusing as it mentions waiting for a specific time that wasn't actually set.
  2. Consider adding a special case when size is 0 to skip the waiting logic entirely.
async def wait_for_free_space(self):
    """Wait for free space on the disk."""
    size = await self.managed_local_footprint()
    disk_free = get_disk_free(self.local_path())

+   # Skip waiting if no space is needed
+   if size == 0:
+       return
+
    wait_time = self.provider.wait_for_free_local_storage

    if wait_time is not None:
        if wait_time < 1:
            raise WorkflowError(
                "Wait time for free space on local storage has to be at least "
                "1 second or unset."
            )
        wait_time_step = 60 if wait_time > 60 else 1

        waited = 0
        while waited < wait_time and size > disk_free:
            self.provider.logger.info(
                f"Waiting {format_timespan(wait_time_step)} for enough free "
                f"space to store {self.local_path()} "
                f"({format_size(size)} > {format_size(disk_free)})"
            )
            await asyncio.sleep(wait_time_step)
            waited += wait_time_step
            disk_free = get_disk_free(self.local_path())

    if size > disk_free:
        raise WorkflowError(
            f"Cannot store {self.local_path()} "
            f"({format_size(size)} > {format_size(disk_free)})"
-           f", waited {format_timespan(self.provider.wait_for_free_local_storage)} "
-           "for more space."
+           f"{', waited ' + format_timespan(waited) + ' for more space' if wait_time is not None else '.'}"
        )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dbafc2a and 8821784.

📒 Files selected for processing (1)
  • snakemake_interface_storage_plugins/storage_object.py (6 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.

  • snakemake_interface_storage_plugins/storage_object.py
🧠 Learnings (1)
snakemake_interface_storage_plugins/storage_object.py (1)
Learnt from: johanneskoester
PR: snakemake/snakemake-interface-storage-plugins#68
File: snakemake_interface_storage_plugins/storage_object.py:194-203
Timestamp: 2025-03-18T14:04:45.477Z
Learning: The project prefers passing exceptions as a second argument to WorkflowError constructor (e.g., `raise WorkflowError("message", e)`) rather than using Python's exception chaining syntax (`raise WorkflowError("message") from e`). Do not suggest changing to the `from e` pattern even if linters like Ruff flag it with B904.
🪛 Ruff (0.8.2)
snakemake_interface_storage_plugins/storage_object.py

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

(B904)


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

(B904)


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

(B904)

🔇 Additional comments (5)
snakemake_interface_storage_plugins/storage_object.py (5)

139-141: Good documentation addition

The docstring clarifies that the method should return the object's size in bytes and explicitly states that directories should return 0, which helps implementers understand the expected behavior.


143-148: Good implementation of local footprint method

The local_footprint method is a well-designed addition with clear documentation explaining the difference between object size and local footprint. The default implementation maintains backward compatibility by falling back to self.size().


174-175: Good integration of space checking before retrieval

Adding the wait for free space check before retrieval is a good practice to prevent failed retrievals due to disk space limitations.


192-201: Well-implemented managed method for local footprint

This method follows the established pattern of other managed methods in the class, providing consistent error handling and rate limiting.

🧰 Tools
🪛 Ruff (0.8.2)

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

(B904)


197-201: Exception handling follows project conventions

The code correctly uses the project's preferred exception handling pattern (passing the original exception as a second argument) instead of Python's exception chaining syntax.

🧰 Tools
🪛 Ruff (0.8.2)

197-201: 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 cb80c6b into main Mar 18, 2025
5 checks passed
@johanneskoester johanneskoester deleted the feat/logger branch March 18, 2025 14:33
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.

2 participants