Skip to content

fix: if requested, properly encode Path types as base64 #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

johanneskoester
Copy link
Contributor

@johanneskoester johanneskoester commented Mar 26, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced command-line value processing: file path values now support optional Base64 encoding when enabled, while maintaining the original behavior otherwise. This update improves how path inputs are handled during command execution.

Copy link
Contributor

coderabbitai bot commented Mar 26, 2025

📝 Walkthrough

Walkthrough

The pull request updates the maybe_encode function within format_cli_value in the snakemake_interface_executor_plugins/utils.py module. The function now conditionally processes Path objects based on the base64_encode flag: if True, it encodes the string representation of the Path using encode_as_base64; if False, it falls back to quoting the string with shlex.quote. No changes have been made to public or exported entities.

Changes

File Change Summary
snakemake_interface_executor_plugins/utils.py Modified maybe_encode in format_cli_value to conditionally base64 encode Path objects based on base64_encode flag.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant FormatCLIValue
    participant MaybeEncode
    participant Base64Encoder as encode_as_base64
    participant ShlexQuote as shlex.quote

    Caller->>FormatCLIValue: Call format_cli_value(value, base64_encode)
    FormatCLIValue->>MaybeEncode: Invoke maybe_encode(value, base64_encode)
    alt base64_encode == True
        MaybeEncode->>Base64Encoder: Call encode_as_base64(str(value))
        Base64Encoder-->>MaybeEncode: Return encoded string
    else base64_encode == False
        MaybeEncode->>ShlexQuote: Call shlex.quote(str(value))
        ShlexQuote-->>MaybeEncode: Return quoted string
    end
    MaybeEncode-->>FormatCLIValue: Return processed string
    FormatCLIValue-->>Caller: Return final value
Loading

Possibly related PRs

✨ 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.
    • 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 plan to trigger planning for file edits and PR creation.
  • @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: 0

🧹 Nitpick comments (2)
snakemake_interface_executor_plugins/utils.py (2)

55-58: Consider updating the docstring to mention Path objects.

The current docstring only mentions that str values are encoded when base64_encode is True, but the function now also handles Path objects in the same way. Consider updating the docstring to explicitly mention that both string and Path objects are encoded.

"""Format a given value for passing it to CLI.

-If base64_encode is True, str values are encoded and flagged as being base64 encoded.
+If base64_encode is True, str and Path values are encoded and flagged as being base64 encoded.
"""

66-69: Consider reusing the maybe_encode helper function for consistency.

For consistency with how strings are handled in this function, consider reusing the maybe_encode helper for Path objects. This would make the implementation more consistent across different value types.

if base64_encode:
-    return encode_as_base64(str(value))
+    return maybe_encode(str(value))
else:
    return shlex.quote(str(value))

Alternatively, for a cleaner approach:

-if base64_encode:
-    return encode_as_base64(str(value))
-else:
-    return shlex.quote(str(value))
+path_str = str(value)
+return maybe_encode(path_str) if base64_encode else shlex.quote(path_str)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b1aff28 and 7b294a1.

📒 Files selected for processing (1)
  • snakemake_interface_executor_plugins/utils.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.

  • snakemake_interface_executor_plugins/utils.py
🔇 Additional comments (1)
snakemake_interface_executor_plugins/utils.py (1)

66-69: LGTM: Path objects now correctly support base64 encoding.

The changes correctly extend the base64 encoding functionality to Path objects when the base64_encode flag is set to True. This implementation aligns with the PR title's objective of properly encoding Path types as base64 when requested.

@johanneskoester johanneskoester merged commit 8518425 into main Mar 26, 2025
5 checks passed
@johanneskoester johanneskoester deleted the fix/base64-encode branch March 26, 2025 20:02
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