Skip to content

支持dir_rule使用python格式字符串语法 (#415)#420

Merged
hect0x7 merged 3 commits intomasterfrom
dev
Apr 16, 2025
Merged

支持dir_rule使用python格式字符串语法 (#415)#420
hect0x7 merged 3 commits intomasterfrom
dev

Conversation

@hect0x7
Copy link
Owner

@hect0x7 hect0x7 commented Apr 16, 2025

Summary by CodeRabbit

  • New Features

    • Added a method to retrieve all properties and computed fields of an entity as a dictionary with a consistent naming convention.
  • Improvements

    • Enhanced rule handling to support dynamic formatting with both album and photo properties.
    • Updated configuration to use a different default client type for improved compatibility.
    • Improved URL handling to safely process image links by removing query parameters before validation.
    • Expanded documentation on directory naming rules, including dynamic property discovery and Python f-string support.
  • Bug Fixes

    • Fixed potential issues in image URL processing to ensure consistent behavior when query parameters are present.

@coderabbitai
Copy link

coderabbitai bot commented Apr 16, 2025

Walkthrough

This update introduces several changes across configuration and entity-handling modules. The default client postman type in the configuration is updated from 'cffi' to 'curl_cffi'. A new method, get_properties_dict, is added to the DetailEntity class to generate a prefixed dictionary of its attributes and properties, including computed fields. In the directory rule logic, support for rules with Python-style format placeholders is added, enabling dynamic path formatting using both album and photo properties. Related type annotations and method signatures are adjusted to accommodate these enhancements.

Changes

File(s) Change Summary
src/jmcomic/jm_config.py Changed default 'postman' type in DEFAULT_OPTION_DICT from 'cffi' to 'curl_cffi'.
src/jmcomic/jm_entity.py Added get_properties_dict method to DetailEntity for prefixed attribute/property dictionary generation.
src/jmcomic/jm_option.py Updated RuleFunc type annotation; added support for {}-formatted rules; adjusted rule solver logic and calls.
assets/docs/sources/option_file_syntax.md Expanded documentation on dir_rule placeholders Pxxx and Ayyy; added info on f-string syntax support for rules.
src/jmcomic/init.py Updated module version string from '2.5.35' to '2.5.36'.
src/jmcomic/jm_client_interface.py Modified transfer_to method to safely remove URL query parameters before suffix comparison.
tests/test_jmcomic/test_jm_api.py Added do_filter method in test's TestDownloader class to selectively filter details in partial exception test.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DirRule
    participant Album
    participant Photo

    User->>DirRule: get_rule_solver(rule)
    alt Rule contains '{}'
        DirRule->>User: Returns ('F', format_func)
        User->>DirRule: apply_rule_solver(album, photo, rule_solver)
        DirRule->>Album: Access album properties
        DirRule->>Photo: Access photo properties
        DirRule->>User: Returns formatted string
    else Rule starts with 'A' or 'P'
        DirRule->>User: Returns corresponding solver
        User->>DirRule: apply_rule_solver(album, photo, rule_solver)
        DirRule->>Album/Photo: Access properties
        DirRule->>User: Returns result
    end
Loading

Possibly related PRs

Poem

In the warren where configs dwell,
A curl_cffi breeze now starts to swell.
Entities gather their traits with delight,
Prefixes in tow, all bundled tight.
Paths now dance with curly brace flair—
Album and photo, a dynamic pair!
🐰✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ 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

@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

🧹 Nitpick comments (2)
src/jmcomic/jm_option.py (1)

157-162: Good implementation of Python format string support for directory rules

The implementation elegantly handles Python format strings in the directory rules, using the newly added get_properties_dict method to source the formatting values.

I recommend adding a code comment or docstring explaining that this supports Python format syntax with property keys from both album and photo objects, along with examples of valid format strings for better developer experience.

🧰 Tools
🪛 Ruff (0.8.2)

159-159: fix_windir_name may be undefined, or defined from star imports

(F405)

src/jmcomic/jm_config.py (1)

417-418: Client postman type updated to curl_cffi

This change updates the default client postman type from 'cffi' to 'curl_cffi', which is likely a more modern or feature-rich implementation.

Consider documenting why this change was made and what benefits it brings, especially if there are performance improvements or compatibility implications.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ebf0ea6 and 5cd0104.

📒 Files selected for processing (3)
  • src/jmcomic/jm_config.py (1 hunks)
  • src/jmcomic/jm_entity.py (1 hunks)
  • src/jmcomic/jm_option.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/jmcomic/jm_option.py (1)
src/jmcomic/jm_entity.py (1)
  • get_properties_dict (167-191)
🪛 Ruff (0.8.2)
src/jmcomic/jm_entity.py

186-186: JmModuleConfig may be undefined, or defined from star imports

(F405)


186-186: JmModuleConfig may be undefined, or defined from star imports

(F405)

src/jmcomic/jm_option.py

74-74: Callable may be undefined, or defined from star imports

(F405)


159-159: fix_windir_name may be undefined, or defined from star imports

(F405)

🔇 Additional comments (2)
src/jmcomic/jm_option.py (2)

184-192: Appropriate update of the choose_detail function

The function has been correctly updated to return tuples and handle the new format string case ('F'). This change aligns with the updated function signature requirements.


195-195: Smooth integration with the rest of the codebase

The call to the solver function has been updated to unpack tuple arguments with *detail, ensuring compatibility with both existing and new rule types.

Copy link

@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

♻️ Duplicate comments (1)
src/jmcomic/jm_entity.py (1)

186-189: Great job fixing the advice dictionary iteration.

The implementation correctly uses advice_dict.items() to iterate over the key-value pairs in the dictionary, addressing the issue mentioned in the previous review comment.

🧰 Tools
🪛 Ruff (0.8.2)

186-186: JmModuleConfig may be undefined, or defined from star imports

(F405)


186-186: JmModuleConfig may be undefined, or defined from star imports

(F405)

🧹 Nitpick comments (1)
src/jmcomic/jm_entity.py (1)

167-191: Method implementation looks good, with one minor suggestion.

The implementation of get_properties_dict() correctly constructs a dictionary with prefixed keys from instance attributes, class properties, and advice functions. This supports the Python-style format string usage in directory rules as mentioned in the PR objectives.

Consider moving the import inspect statement to the top of the file with other imports rather than inside the method:

-def get_properties_dict(self):
-    import inspect
+def get_properties_dict(self):

And add the import at the top of the file:

from functools import lru_cache

+import inspect
from common import *

from .jm_config import *
🧰 Tools
🪛 Ruff (0.8.2)

186-186: JmModuleConfig may be undefined, or defined from star imports

(F405)


186-186: JmModuleConfig may be undefined, or defined from star imports

(F405)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5cd0104 and 521b500.

📒 Files selected for processing (1)
  • src/jmcomic/jm_entity.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/jmcomic/jm_entity.py (1)
src/jmcomic/jm_config.py (1)
  • JmModuleConfig (83-493)
🪛 Ruff (0.8.2)
src/jmcomic/jm_entity.py

186-186: JmModuleConfig may be undefined, or defined from star imports

(F405)


186-186: JmModuleConfig may be undefined, or defined from star imports

(F405)

@hect0x7
Copy link
Owner Author

hect0x7 commented Apr 16, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Apr 16, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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)
tests/test_jmcomic/test_jm_api.py (1)

82-87: Good implementation of the do_filter method.

The method effectively filters both photo and album entities to return only the first two elements, while delegating to the parent class for other entity types. This approach aligns well with the PR objective to support Python format string syntax by leveraging Python's slicing notation.

I noticed the static analysis warning about DetailEntity potentially being undefined. While this appears to be a false positive due to star imports, consider explicitly importing DetailEntity to improve code clarity.

-def do_filter(self, detail: DetailEntity):
+from jmcomic.jm_entity import DetailEntity
+
+def do_filter(self, detail: DetailEntity):
🧰 Tools
🪛 Ruff (0.8.2)

82-82: DetailEntity may be undefined, or defined from star imports

(F405)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 521b500 and 89419f8.

📒 Files selected for processing (4)
  • assets/docs/sources/option_file_syntax.md (2 hunks)
  • src/jmcomic/__init__.py (1 hunks)
  • src/jmcomic/jm_client_interface.py (1 hunks)
  • tests/test_jmcomic/test_jm_api.py (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • assets/docs/sources/option_file_syntax.md
  • src/jmcomic/init.py
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests/test_jmcomic/test_jm_api.py (3)
src/jmcomic/jm_downloader.py (1)
  • do_filter (177-187)
src/jmcomic/jm_plugin.py (1)
  • do_filter (261-266)
src/jmcomic/jm_entity.py (5)
  • DetailEntity (64-191)
  • is_photo (27-28)
  • is_photo (450-451)
  • is_album (31-32)
  • is_album (565-566)
src/jmcomic/jm_client_interface.py (1)
src/jmcomic/jm_toolkit.py (2)
  • JmImageTool (718-851)
  • save_resp_img (721-734)
🪛 Ruff (0.8.2)
tests/test_jmcomic/test_jm_api.py

82-82: DetailEntity may be undefined, or defined from star imports

(F405)

src/jmcomic/jm_client_interface.py

71-71: JmImageTool may be undefined, or defined from star imports

(F405)


74-74: suffix_not_equal may be undefined, or defined from star imports

(F405)

🪛 GitHub Actions: Run Test (API)
tests/test_jmcomic/test_jm_api.py

[error] 96-96: Exception raised in thread during download_by_photo_detail: 'test_partial_exception'

🔇 Additional comments (2)
src/jmcomic/jm_client_interface.py (2)

65-67: Good improvement for URL sanitization.

This code properly handles URL query parameters by checking for their presence before truncating, fixing a potential issue if the "?" character isn't found (which would result in a -1 index that could cause unexpected behavior).


74-74: URL sanitization consistency with line 65-67.

The sanitized img_url is now correctly passed to suffix_not_equal, which ensures consistent file extension checking without query parameters interfering. This enhances the robustness of image format conversion decisions.

🧰 Tools
🪛 Ruff (0.8.2)

74-74: suffix_not_equal may be undefined, or defined from star imports

(F405)

@hect0x7 hect0x7 merged commit 398e1ea into master Apr 16, 2025
4 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Apr 22, 2025
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