Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

v2.6.10: 文件夹名称支持繁简转换,dir_rule增加normalize_zh配置#486

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
hect0x7 merged 12 commits intomasterfromdev
Oct 27, 2025

Conversation

@hect0x7
Copy link
Owner

@hect0x7hect0x7 commentedOct 27, 2025
edited by coderabbitaibot
Loading

简介

本次 PR 为dir_rule 增加了对中文变体规范化(简/繁)的支持,解决了因简繁差异导致的重复目录或不一致命名问题。

背景

在某些漫画源中,同一作品名称在简体/繁体之间存在差异(例如“漫画名” vs “漫畫名”),当目录规则未统一处理中文变体时,可能会生成重复或不一致的目录结构。该 PR 针对该问题在目录名生成流程中增加了可配置的中文规范化选项,以便统一命名。

解决方案

  • 新增dir_rule 下的配置项normalize_zh(可选),用于指示是否对目录/文件名中的中文进行规范化,以及规范化的目标变体(例如:simplified /traditional /off)。
  • 在构建目录名的逻辑中统一调用中文规范化函数(可配置的实现),将中文字符按配置转换为指定变体,避免因简繁差异产生重复目录。
  • 保持默认行为与历史一致:未开启或未配置时不会改变现有输出。

主要改动(概要)

  • 配置与解析:在配置定义处增加dir_rule.normalize_zh 的声明与说明,支持用户通过配置文件开启或关闭并选择目标变体。
  • 工具/实现:新增/使用中文规范化的实现(可复用的转换函数),并在目录规则处理处调用该函数。
  • 目录生成流程:在生成目录名时应用规范化逻辑,确保目录命名在同一配置下统一。

注:具体文件名与实现位置请参见对应提交改动(代码仓库中已包含相应实现)。

向后兼容性

  • 默认情况下该配置为关闭或保持原有行为(不会影响现有用户),除非用户显式开启normalize_zh 并选择目标变体。

验证建议

  1. 在存在简/繁名称差异的漫画资源上运行爬取,确认在开启normalize_zhsimplifiedtraditional 后,生成的目录名按配置统一且不会重复。
  2. 在未开启该配置时确认行为与之前一致。
  3. 尝试在不同目录规则下组合该配置,确认不存在副作用。

关联 Issue

Fixes#485


如果你希望我把正文再补充更具体的实现细节(例如列出具体修改的文件路径、函数名或示例配置片段),我可以基于 PR 的改动把这些信息加入到说明中。

Summary by CodeRabbit

  • New Features

    • Configurable Chinese-character normalization for directory names (None / zh-cn / zh-tw); applied during directory rule processing and preserved in exported options.
  • Chores

    • Conversion now safely falls back to original text if the conversion library is missing or conversion fails.
  • Documentation

    • README, docs and examples updated to document the new normalize_zh option.
  • Other

    • Package version bumped to 2.6.10.

@hect0x7hect0x7 linked an issueOct 27, 2025 that may beclosed by this pull request
3 tasks
@coderabbitai
Copy link

coderabbitaibot commentedOct 27, 2025
edited
Loading

Walkthrough

Adds an optional dir_rule settingnormalize_zh, threads it through option serialization, updates DirRule to optionally normalize non-base-dir path components via a new JmcomicText.to_zh helper with defensive fallback, updates docs and fixtures, and bumps package version to 2.6.10.

Changes

Cohort / File(s)Summary
Config & package version
src/jmcomic/jm_config.py,src/jmcomic/__init__.py
Addednormalize_zh: None toDEFAULT_OPTION_DICT['dir_rule']; bumped__version__ to2.6.10.
Dir rule & option handling
src/jmcomic/jm_option.py
DirRule.__init__ gainednormalize_zh param and stored it;apply_rule_to_path converts non-base-dir components withJmcomicText.to_zh(..., self.normalize_zh) beforefix_windir_name;copy_option() anddeconstruct() includenormalize_zh.
Text conversion utilities
src/jmcomic/jm_toolkit.py
AddedJmcomicText.to_zh(cls, s, target=None) with defensive import/fallback and error logging;to_zh_cn() delegates toto_zh(..., 'zh-cn').
Docs & examples
assets/docs/sources/option_file_syntax.md,assets/docs/sources/tutorial/4_module_custom.md,assets/docs/sources/tutorial/9_custom_download_dir_name.md,README.md
Documenteddir_rule.normalize_zh option, allowed values (None,zh-cn,zh-tw), fallback behavior whenzhconv is missing or conversion fails, and added examples.
Test/config asset
assets/option/option_test_api.yml
Addeddir_rule.normalize_zh: zh-cn to the test option fixture.

Sequence Diagram(s)

sequenceDiagram    participant User as User Config    participant Config as JmModuleConfig    participant DirRule as DirRule    participant Text as JmcomicText    User->>Config: load options (may include dir_rule.normalize_zh)    Config->>DirRule: initialize(rule, base_dir, normalize_zh)    DirRule->>DirRule: parse path components    Note over DirRule,Text: For non-base-dir components, optionally normalize Chinese text    DirRule->>Text: to_zh(component, normalize_zh)    alt conversion succeeds        Text-->>DirRule: converted component    else conversion unavailable or fails        Text-->>DirRule: original component (fallback)    end    DirRule->>DirRule: apply Windows name fixes (fix_windir_name)    DirRule-->>User: final path
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect JmcomicText.to_zh() for correct defensive import, exception handling, and logging.
  • Verify DirRule.apply_rule_to_path only normalizes intended (non-base-dir) components and preserves existing filename/path sanitization.
  • Confirmcopy_option() anddeconstruct() consistently includenormalize_zh and that fixtures/docs match behavior.

Possibly related PRs

Poem

🐇
我是小兔巡仓库,繁简轻声和,
文件夹名归一处,下载不再多过。
一键新配置入,悄悄帮你忙活。

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 25.00% which is insufficient. The required threshold is 80.00%.You can run@coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title Check✅ PassedThe PR title "v2.6.10: 文件夹名称支持繁简转换,dir_rule增加normalize_zh配置" (Add support for simplified/traditional Chinese conversion in folder names, add normalize_zh config to dir_rule) clearly and specifically describes the primary change in the changeset. The title accurately captures the main objective of introducing Chinese character normalization functionality through a new configurable parameter, and it is concise and informative without vague or generic terms. A developer scanning the history would understand that this release adds Chinese text variant conversion capability to directory naming rules.
Linked Issues Check✅ PassedThe PR successfully implements all core requirements from linked issue#485. The changes add a configurablenormalize_zh parameter todir_rule that supports Chinese character normalization (zh-cn for simplified, zh-tw for traditional, or None to disable), which directly addresses the duplicate folder problem caused by simplified/traditional Chinese inconsistencies. The implementation includes the newto_zh method injm_toolkit.py for character conversion, integration into theDirRule processing logic [jm_option.py], configuration management [jm_config.py], and comprehensive documentation. The version is appropriately bumped to 2.6.10, and backward compatibility is maintained by defaulting to None (no conversion).
Out of Scope Changes Check✅ PassedAll changes in the PR are directly aligned with the stated objective of adding Chinese character normalization support to directory naming. The core implementation changes [jm_config.py, jm_option.py, jm_toolkit.py] add the new feature, configuration updates [option_test_api.yml] test it, documentation changes [README.md, option_file_syntax.md, tutorial files] explain the feature, and the version bump [init.py] appropriately reflects the release. No unrelated or scope-creeping changes are present; every modification contributes to the primary goal of resolving the duplicate folder issue through configurable Chinese text normalization.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branchdev

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and betweenac131f2 and85be7fd.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • assets/docs/sources/tutorial/9_custom_download_dir_name.md (1 hunks)
  • src/jmcomic/jm_option.py (4 hunks)
  • src/jmcomic/jm_toolkit.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • README.md
  • assets/docs/sources/tutorial/9_custom_download_dir_name.md
🧰 Additional context used
🧬 Code graph analysis (2)
src/jmcomic/jm_option.py (1)
src/jmcomic/jm_toolkit.py (2)
  • parse_to_abspath (239-240)
  • to_zh (336-359)
src/jmcomic/jm_toolkit.py (1)
src/jmcomic/jm_config.py (1)
  • jm_log (383-385)
🪛 Ruff (0.14.1)
src/jmcomic/jm_option.py

67-67: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF002)


69-69:JmcomicText may be undefined, or defined from star imports

(F405)


98-98:JmcomicText may be undefined, or defined from star imports

(F405)


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

(F405)

src/jmcomic/jm_toolkit.py

332-332: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF003)


341-341: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean( (LEFT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean) (RIGHT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean( (LEFT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean) (RIGHT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF002)


342-342: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean( (LEFT PARENTHESIS)?

(RUF002)


342-342: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF002)


342-342: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean) (RIGHT PARENTHESIS)?

(RUF002)


353-353: Local variablee is assigned to but never used

Remove assignment to unused variablee

(F841)


354-354:jm_log may be undefined, or defined from star imports

(F405)


354-354: String contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF001)


354-354: String contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF001)


356-356: Do not catch blind exception:Exception

(BLE001)


357-357: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF003)


358-358:jm_log may be undefined, or defined from star imports

(F405)

🔇 Additional comments (6)
src/jmcomic/jm_toolkit.py (2)

331-333:LGTM! Clean backward compatibility wrapper.

The refactoring to delegateto_zh_cn to the new generalizedto_zh method maintains the existing API while consolidating the implementation logic.


335-359:LGTM! Robust implementation with graceful fallback.

Theto_zh method correctly implements optional Chinese normalization with defensive error handling:

  • Early returns for None/falsy inputs prevent unnecessary processing
  • ImportError is caught separately with a clear user-facing message directing them to install zhconv
  • General exception catch ensures any conversion failure falls back to the original string
  • Aligns with PR objectives to avoid breaking existing functionality when zhconv is unavailable
src/jmcomic/jm_option.py (4)

63-73:LGTM! Clean parameter addition with proper documentation.

Thenormalize_zh parameter is well-integrated intoDirRule.__init__:

  • Documented with valid values ('zh-cn', 'zh-tw', None)
  • Defaults to None for backward compatibility
  • Properly stored for later use in path normalization

96-100:LGTM! Normalization correctly applied to path components.

The implementation correctly:

  • Applies normalization only to non-base-dir path components (manga metadata), preserving the filesystem base path
  • Converts to string before normalization for robustness
  • Chains normalization → Windows path fixes → whitespace trimming in the proper order
  • Uses the configurednormalize_zh target, respecting user settings

This aligns with the PR objectives to unify directory naming and prevent duplicate folders due to simplified/traditional character differences.


207-219:LGTM! Configuration properly propagated in copy operation.

Thenormalize_zh field is correctly included in thecopy_option method, ensuring that copiedJmOption instances preserve the Chinese normalization settings.


331-343:LGTM! Configuration properly serialized in deconstruct.

Thenormalize_zh field is correctly included in thedeconstruct method, ensuring that option configurations can be properly saved to and loaded from files while preserving the Chinese normalization settings.


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

❤️ Share

Comment@coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitaicoderabbitaibot 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)
src/jmcomic/jm_option.py (1)

98-109:Simplify defensive coding and narrow exception handling.

Thegetattr(self, 'normalize_zh', None) pattern appears redundant since__init__ already setsself.normalize_zh with a default value. This defensive pattern is only necessary if you need to support legacyDirRule instances created before this change. If backward compatibility with pickled/cached instances is not required, simplify totarget = self.normalize_zh.

Additionally, the bareexcept Exception on line 106 suppresses all errors, making debugging difficult if issues arise.

If backward compatibility with old instances is not needed:

-                # 根据配置 normalize_zh 进行繁简体统一或跳过-                try:-                    target = getattr(self, 'normalize_zh', None)-                    if target is None:-                        # 默认为不转换-                        conv_path = str(path)-                    else:-                        conv_path = JmcomicText.to_zh(str(path), target)-                except Exception:-                    conv_path = str(path)--                path = fix_windir_name(conv_path).strip()+                # 根据配置 normalize_zh 进行繁简体统一或跳过+                conv_path = JmcomicText.to_zh(str(path), self.normalize_zh)+                path = fix_windir_name(conv_path).strip()

Note:JmcomicText.to_zh already handlesNone targets and exceptions internally, so the defensive code here is redundant.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and betweenf2adb33 and3fbcd31.

📒 Files selected for processing (3)
  • src/jmcomic/jm_config.py (1 hunks)
  • src/jmcomic/jm_option.py (5 hunks)
  • src/jmcomic/jm_toolkit.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/jmcomic/jm_option.py (1)
src/jmcomic/jm_toolkit.py (2)
  • parse_to_abspath (239-240)
  • to_zh (336-359)
🪛 Ruff (0.14.1)
src/jmcomic/jm_option.py

68-68: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF002)


106-106: Do not catch blind exception:Exception

(BLE001)


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

(F405)

src/jmcomic/jm_toolkit.py

332-332: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF003)


341-341: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean( (LEFT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean) (RIGHT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean( (LEFT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean) (RIGHT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF002)


342-342: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean( (LEFT PARENTHESIS)?

(RUF002)


342-342: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF002)


342-342: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean) (RIGHT PARENTHESIS)?

(RUF002)


357-357: Do not catch blind exception:Exception

(BLE001)


358-358: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF003)

🔇 Additional comments (6)
src/jmcomic/jm_option.py (3)

64-74:LGTM with minor style note.

Thenormalize_zh parameter is well-documented and properly stored. The default value'zh-cn' aligns with the configuration injm_config.py.

Note: Static analysis flagged the full-width comma (,) in the docstring at line 68. This is acceptable for Chinese documentation, though you may want to standardize on half-width punctuation for consistency with Python conventions.


217-229:LGTM!

Thecopy_option method correctly propagates thenormalize_zh setting when creating a copy of the option.


341-353:LGTM!

Thedeconstruct method correctly includesnormalize_zh to ensure the setting is persisted when saving options to a file.

src/jmcomic/jm_toolkit.py (2)

330-333:LGTM!

Good refactoring to delegate to the new genericto_zh method while preserving the existingto_zh_cn API for backward compatibility.


335-359: Based on my verification, I found that:

  1. zhconv dependency status: zhconv is inrequirements-dev.txt (development-only) and is NOT in the maininstall_requires ordependencies sections of setup.py/pyproject.toml. This is intentional design—zhconv is already treated as an optional dependency.

  2. Exception handling appropriateness: For an optional dependency, the broadexcept Exception with silent fallback to the original string is a reasonable and safe pattern. The method correctly handles both missing library and conversion errors by returning the original string.

  3. jm_log existence: The function exists and is used throughout the codebase for logging, confirming the suggested improvement is feasible.

The implementation already follows good defensive patterns for optional dependencies. The current code safely handles the case when zhconv is unavailable.


No actionable issues found—current implementation appropriately handles zhconv as optional.

Theto_zh method correctly manages zhconv as an optional dependency. While zhconv is listed inrequirements-dev.txt, it's appropriately excluded from the main dependency list in setup.py/pyproject.toml, meaning users who don't need Chinese text conversion normalization won't be forced to install it. The defensive exception handling with silent fallback is acceptable for this optional feature—users get the original string if the library isn't available or conversion fails.

The implementation is sound. No changes are required.

src/jmcomic/jm_config.py (1)

414-414:Verify backward compatibility claim - inconclusive without git history.

The PR claims "default behavior remains unchanged," but verification is inconclusive:

  • DirRule.__init__ has parameter defaultnormalize_zh='zh-cn' (line 64, jm_option.py)
  • Code defensively checksif normalize_zh is None to apply "no conversion" (lines 100-102)
  • Line 414 now explicitly sets'normalize_zh': 'zh-cn' inDEFAULT_OPTION_DICT
  • No git history, tests, or changelog available to confirm previous state

The key question: Wasnormalize_zh previouslyabsent fromDEFAULT_OPTION_DICT (relying on parameter default 'zh-cn'), or was it explicitly set toNone/'none' (enabling no conversion by default)?

Manually verify the previous version of this configuration dictionary to confirm whether this change affects existing behavior.

Copy link

@coderabbitaicoderabbitaibot 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)
src/jmcomic/jm_option.py (1)

64-69:Consider replacing fullwidth punctuation in docstring.

The docstring contains fullwidth commas and parentheses which Ruff flags as potentially ambiguous. For consistency with Python conventions, consider using ASCII punctuation.

Apply this diff to use ASCII punctuation:

-        :param normalize_zh: 'zh-cn'|'zh-tw'| or None. 控制是否以及如何进行繁简体归一化,默认 None+        :param normalize_zh: 'zh-cn'|'zh-tw'| or None. 控制是否以及如何进行繁简体归一化, 默认 None

Based on static analysis.

src/jmcomic/jm_toolkit.py (2)

331-333:LGTM!

The refactoring ofto_zh_cn to delegate to the new genericto_zh method maintains backward compatibility while reducing code duplication.

Optionally, replace the fullwidth comma in the comment with ASCII for consistency:

-        # 兼容旧接口,默认转换为简体+        # 兼容旧接口, 默认转换为简体

Based on static analysis.


337-343:Consider replacing fullwidth punctuation in docstring.

The docstring contains fullwidth parentheses and commas which Ruff flags as potentially ambiguous. For consistency with Python conventions, consider using ASCII punctuation.

Apply this diff to use ASCII punctuation:

-        :param target: 目标编码: 'zh-cn'(简体), 'zh-tw'(繁体),或 None/'none' 表示不转换-        :return: 转换后的字符串(若转换失败或未安装 zhconv,返回原始字符串)+        :param target: 目标编码: 'zh-cn'(简体), 'zh-tw'(繁体), 或 None/'none' 表示不转换+        :return: 转换后的字符串(若转换失败或未安装 zhconv, 返回原始字符串)

Based on static analysis.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between3fbcd31 and012a8cf.

📒 Files selected for processing (4)
  • assets/option/option_test_api.yml (1 hunks)
  • src/jmcomic/jm_config.py (1 hunks)
  • src/jmcomic/jm_option.py (5 hunks)
  • src/jmcomic/jm_toolkit.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/jmcomic/jm_config.py
🧰 Additional context used
🧬 Code graph analysis (2)
src/jmcomic/jm_option.py (1)
src/jmcomic/jm_toolkit.py (2)
  • parse_to_abspath (239-240)
  • to_zh (336-356)
src/jmcomic/jm_toolkit.py (1)
src/jmcomic/jm_config.py (1)
  • jm_log (383-385)
🪛 Ruff (0.14.1)
src/jmcomic/jm_option.py

68-68: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF002)


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

(F405)

src/jmcomic/jm_toolkit.py

332-332: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF003)


341-341: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean( (LEFT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean) (RIGHT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean( (LEFT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean) (RIGHT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF002)


342-342: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean( (LEFT PARENTHESIS)?

(RUF002)


342-342: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF002)


342-342: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean) (RIGHT PARENTHESIS)?

(RUF002)


353-353: Do not catch blind exception:Exception

(BLE001)


354-354: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF003)


355-355:jm_log may be undefined, or defined from star imports

(F405)

🔇 Additional comments (6)
assets/option/option_test_api.yml (1)

4-4:LGTM!

The configuration addition correctly enables Simplified Chinese normalization for directory names, aligning with the PR's objective to prevent duplicate directories caused by Chinese variant differences.

src/jmcomic/jm_option.py (4)

2-2:LGTM!

The import ofJmcomicText is necessary for the Chinese normalization functionality added in this PR.


98-100:LGTM!

The normalization logic is correctly placed after rule parsing but before Windows path normalization. The implementation properly:

  • Skips base directory paths
  • Converts to string before normalization
  • Falls back gracefully if zhconv is unavailable or normalization fails

213-213:LGTM!

The defensive use ofgetattr with a default value ensures backward compatibility with existingDirRule instances that may not have thenormalize_zh attribute.


339-339:LGTM!

The propagation indeconstruct mirrors the approach incopy_option, ensuring the configuration is properly serialized. The defensivegetattr maintains backward compatibility.

src/jmcomic/jm_toolkit.py (1)

335-356:LGTM! Robust error handling with appropriate fallback behavior.

The implementation correctly:

  • Handles None inputs gracefully
  • Uses zhconv for conversion when available
  • Falls back to the original string on any error (missing library, invalid target, conversion failure)
  • Logs errors for debugging without breaking functionality

This defensive approach aligns with the PR's goal of avoiding disruption when normalization cannot be performed.

The broadException catch is appropriate here despite the static analysis warning, as it ensures graceful degradation when zhconv is unavailable or encounters unexpected issues.

Based on static analysis.

Copy link

@coderabbitaicoderabbitaibot 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 (1)
src/jmcomic/jm_option.py (1)

64-73:Minor: Use ASCII comma in docstring parameter description.

Thenormalize_zh parameter is correctly added and stored. However, the docstring uses a fullwidth comma (Chinese punctuation) which should be an ASCII comma for consistency.

Apply this diff to fix the punctuation:

     def __init__(self, rule: str, base_dir=None, normalize_zh=None):         """         :param rule: DSL rule         :param base_dir: base directory-        :param normalize_zh: 'zh-cn'|'zh-tw'| or None. 控制是否以及如何进行繁简体归一化,默认 None+        :param normalize_zh: 'zh-cn'|'zh-tw'| or None. 控制是否以及如何进行繁简体归一化, 默认 None         """
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between012a8cf andbf42f56.

📒 Files selected for processing (3)
  • src/jmcomic/jm_config.py (1 hunks)
  • src/jmcomic/jm_option.py (5 hunks)
  • src/jmcomic/jm_toolkit.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/jmcomic/jm_config.py
🧰 Additional context used
🧬 Code graph analysis (2)
src/jmcomic/jm_option.py (1)
src/jmcomic/jm_toolkit.py (3)
  • JmcomicText (6-355)
  • parse_to_abspath (239-240)
  • to_zh (336-351)
src/jmcomic/jm_toolkit.py (1)
src/jmcomic/jm_config.py (1)
  • jm_log (383-385)
🪛 Ruff (0.14.1)
src/jmcomic/jm_option.py

68-68: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF002)


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

(F405)

src/jmcomic/jm_toolkit.py

332-332: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF003)


352-352: Expectedexcept orfinally aftertry block

(invalid-syntax)


352-352: Expected a statement

(invalid-syntax)


352-352: Expected a statement

(invalid-syntax)


352-352: Expected a statement

(invalid-syntax)


353-353: Unexpected indentation

(invalid-syntax)


354-354: unindent does not match any outer indentation level

(invalid-syntax)


354-354: Expected a statement

(invalid-syntax)


354-354: Expected a statement

(invalid-syntax)


354-355: Expected an expression

(invalid-syntax)


355-355: Unexpected indentation

(invalid-syntax)


355-356: Expected an indented block afterif statement

(invalid-syntax)


356-356: Expected a statement

(invalid-syntax)


356-356: Expected a statement

(invalid-syntax)


356-356: Expected a statement

(invalid-syntax)


356-356: Expected a statement

(invalid-syntax)


356-357: Expected a statement

(invalid-syntax)


357-357: Unexpected indentation

(invalid-syntax)


358-358: Unexpected indentation

(invalid-syntax)


365-365: Expectedexcept orfinally aftertry block

(invalid-syntax)


366-366: unindent does not match any outer indentation level

(invalid-syntax)


366-366: Expected a statement

(invalid-syntax)


366-366: Expected a statement

(invalid-syntax)


366-367: Expected an expression

(invalid-syntax)


367-367: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF003)


368-368: Expected a statement

(invalid-syntax)


368-368: Expected a statement

(invalid-syntax)


368-368: Expected a statement

(invalid-syntax)


368-368: Expected a statement

(invalid-syntax)


368-368: Expected ',', found float

(invalid-syntax)


368-368: Expected ',', found ':'

(invalid-syntax)


368-368: Expected ',', found name

(invalid-syntax)


368-368: Expected ',', found name

(invalid-syntax)


368-368: Expected ',', found name

(invalid-syntax)


368-368: Got unexpected token ,

(invalid-syntax)


368-368: Expected ',', found name

(invalid-syntax)


368-368: Expected ',', found name

(invalid-syntax)


369-369: Unexpected indentation

(invalid-syntax)

🔇 Additional comments (5)
src/jmcomic/jm_toolkit.py (1)

331-333:LGTM: Clean refactoring to delegate to the new generic method.

The refactoring ofto_zh_cn to delegate toto_zh(s, 'zh-cn') is correct and maintains backward compatibility while reducing code duplication.

src/jmcomic/jm_option.py (4)

2-2:LGTM: Import added for Chinese normalization support.

The import ofJmcomicText is correctly added to support the new Chinese normalization functionality.


98-100:LGTM: Chinese normalization correctly applied before Windows path sanitization.

The Chinese normalization is applied at the right point in the flow:

  1. After parsing the rule to get the path component
  2. Before Windows path name sanitization
  3. Only for non-base-dir paths

This ensures consistent directory naming regardless of simplified/traditional Chinese variants in the source data.


208-220:LGTM: normalize_zh properly propagated in copy_option.

Thenormalize_zh field is correctly included when creating a copy of the option, ensuring the configuration is preserved.


332-344:LGTM: normalize_zh included in option serialization.

Thenormalize_zh field is correctly included in thedeconstruct method, ensuring it's properly serialized when saving the option to a file.

@hect0x7hect0x7 changed the titleFix #485: 支持 dir_rule 的 normalize_zh 配置并规范化中文变体v2.6.10: 文件夹名称支持繁简转换,dir_rule增加normalize_zh配置Oct 27, 2025
Copy link

@coderabbitaicoderabbitaibot 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)
src/jmcomic/jm_toolkit.py (1)

335-359:Merge conflict resolved correctly with improved error handling.

The implementation successfully resolves the previously flagged merge conflict and improves upon the suggested fix by separating ImportError (with a user-friendly installation message) from general exceptions (with debug information).

However, there's a minor improvement opportunity: theImportError exception on Line 353 is assigned toe but not used in the log message on Line 354. While the friendly message is helpful, including the exception details would aid debugging.

Consider logging the exception in the ImportError block for better debugging:

     except ImportError as e:-        jm_log('zhconv.error', '繁简转换失败,未安装zhconv,请先使用命令安装: [pip install zhconv]')+        jm_log('zhconv.error', f'繁简转换失败,未安装zhconv,请先使用命令安装: [pip install zhconv]. Error: {e}')         return s

Note: The fullwidth commas (,) in the Chinese strings are flagged by static analysis but are likely intentional for proper Chinese punctuation. The blindException catch on Line 356 is acceptable here as a graceful fallback mechanism.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and betweenbf42f56 and8755330.

📒 Files selected for processing (3)
  • src/jmcomic/__init__.py (1 hunks)
  • src/jmcomic/jm_config.py (1 hunks)
  • src/jmcomic/jm_toolkit.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/jmcomic/jm_toolkit.py (1)
src/jmcomic/jm_config.py (1)
  • jm_log (383-385)
🪛 Ruff (0.14.1)
src/jmcomic/jm_toolkit.py

332-332: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF003)


341-341: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean( (LEFT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean) (RIGHT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean( (LEFT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean) (RIGHT PARENTHESIS)?

(RUF002)


341-341: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF002)


342-342: Docstring contains ambiguous (FULLWIDTH LEFT PARENTHESIS). Did you mean( (LEFT PARENTHESIS)?

(RUF002)


342-342: Docstring contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF002)


342-342: Docstring contains ambiguous (FULLWIDTH RIGHT PARENTHESIS). Did you mean) (RIGHT PARENTHESIS)?

(RUF002)


353-353: Local variablee is assigned to but never used

Remove assignment to unused variablee

(F841)


354-354:jm_log may be undefined, or defined from star imports

(F405)


354-354: String contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF001)


354-354: String contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF001)


356-356: Do not catch blind exception:Exception

(BLE001)


357-357: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean, (COMMA)?

(RUF003)


358-358:jm_log may be undefined, or defined from star imports

(F405)

🔇 Additional comments (3)
src/jmcomic/jm_config.py (1)

414-414:LGTM! Configuration addition is clean.

Thenormalize_zh: None addition todir_rule maintains backward compatibility by defaulting to off. This aligns with the PR objective to provide optional Chinese text normalization without changing existing behavior.

src/jmcomic/__init__.py (1)

5-5:Version bump looks good.

Standard version increment to reflect the newnormalize_zh feature.

src/jmcomic/jm_toolkit.py (1)

331-333:Good backward compatibility approach.

Theto_zh_cn wrapper correctly delegates to the newto_zh method, maintaining compatibility with existing callers.

@hect0x7hect0x7 merged commit92f8b26 intomasterOct 27, 2025
4 checks passed
@hect0x7hect0x7 deleted the dev branchOctober 27, 2025 08:36
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@coderabbitaicoderabbitai[bot]coderabbitai[bot] left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Bug] 下载本子的文件夹名,会出现繁体、简体重复的问题

1 participant

@hect0x7

[8]ページ先頭

©2009-2025 Movatter.jp