Skip to content

fix(galgame): 让 RapidOCR 模型配置实际生效#1194

Merged
wehos merged 4 commits into
Project-N-E-K-O:mainfrom
MomiJiSan:fix/galgame-rapidocr-config-not-applied
May 6, 2026
Merged

fix(galgame): 让 RapidOCR 模型配置实际生效#1194
wehos merged 4 commits into
Project-N-E-K-O:mainfrom
MomiJiSan:fix/galgame-rapidocr-config-not-applied

Conversation

@MomiJiSan
Copy link
Copy Markdown
Contributor

@MomiJiSan MomiJiSan commented May 6, 2026

  • 从用户模型缓存优先、包内 models 目录兜底解析 det/cls/rec ONNX 路径
  • 对支持 **kwargs 的 RapidOCR 构造器传入已解析的模型路径
  • 将默认 RapidOCR OCR 版本对齐到内置模型 PP-OCRv4
  • 更新 OCR pipeline 验证脚本,复用 RapidOCR 默认版本
  • 新增模型路径选择和缺失模型回退的回归测试

Summary by CodeRabbit

发布说明

  • 改进

    • 默认 OCR 模型版本更新为 PP-OCRv4。
    • 优化模型路径解析与运行时初始化,支持在包内与缓存中动态定位模型文件并在多种场景下选择合适模型,以提升兼容性与稳健性。
  • 测试

    • 新增单元测试,覆盖模型路径解析、优先级选择、缺失模型回退以及运行时加载与元数据验证,确保行为一致性。

  本次更改为 RapidOCR 运行时补充模型路径解析逻辑,按用户模型缓存优先、包内 models 目录兜底的顺序查找 det/cls/rec ONNX 模型,并在构造 RapidOCR 实例时传入解析后的模型路径,使 lang_type、ocr_version、
  model_type 配置能够实际影响模型加载。同时将默认 OCR 版本从 PP-OCRv5 调整为与当前内置模型一致的 PP-OCRv4,并更新手动 OCR pipeline 验证脚本以复用统一默认值。

  新增单元测试覆盖模型路径解析、用户缓存优先级、缺失模型回退以及从实际导入包定位 models 目录等场景,防止配置再次失效。
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 73035c35-5053-4b03-86e4-6e1516d4273e

📥 Commits

Reviewing files that changed from the base of the PR and between 432318d and 81c8062.

📒 Files selected for processing (3)
  • plugin/plugins/galgame_plugin/models.py
  • plugin/plugins/galgame_plugin/rapidocr_support.py
  • plugin/plugins/galgame_plugin/test_ocr_pipeline.py

Walkthrough

将默认 RapidOCR OCR 版本从 "PP-OCRv5" 改为 "PP-OCRv4",并在 galgame 插件中添加包内与用户模型缓存的动态模型路径解析与注入逻辑,调整运行时构造参数传递与加载调用,新增单元测试覆盖模型优先级与加载行为喵。

Changes

OCR 版本与动态模型路径解析

Layer / File(s) Summary
配置与默认值
plugin/plugins/galgame_plugin/models.py, plugin/plugins/galgame_plugin/plugin.toml, plugin/plugins/galgame_plugin/rapidocr_support.py
rapidocr_ocr_version 默认值从 "PP-OCRv5" 更新为 DEFAULT_RAPIDOCR_OCR_VERSION(对应 "PP-OCRv4")并同步常量变更喵。
模型路径解析核心
plugin/plugins/galgame_plugin/rapidocr_support.py
新增 _resolve_rapidocr_model_paths(...):基于语言、OCR 版本和模型类型构造候选 ONNX 文件名,并在用户模型缓存与包内 models 目录中查找 det/cls/rec 路径,返回三元路径喵。
运行时构造参数扩展
plugin/plugins/galgame_plugin/rapidocr_support.py
_build_runtime_constructor_kwargs(...) 增加 `package_models_dir: Path
运行时加载集成
plugin/plugins/galgame_plugin/rapidocr_support.py
load_rapidocr_runtime() 从已导入 RapidOCR 模块推断 package_models_dir(module 文件位置的 parent / "models"),并将其传入 kwargs 构建器以启用包内模型发现喵。
测试与使用点
plugin/plugins/galgame_plugin/test_ocr_pipeline.py, plugin/tests/unit/plugins/test_galgame_rapidocr_support.py
测试改为使用 DEFAULT_RAPIDOCR_OCR_VERSION,新增单元测试验证模型路径解析逻辑、用户缓存优先级、服务器变体选择及通过包导入加载运行时时的 kwargs 与 metadata 行为喵。

Sequence Diagram(s)

sequenceDiagram
    participant Config as 配置层
    participant Loader as 运行时加载
    participant Resolver as 路径解析
    participant FS as 文件系统
    participant RapidOCR as RapidOCR包

    Config->>Loader: load_rapidocr_runtime(config)
    Loader->>Loader: 派生 package_models_dir(module.parent / "models")
    Loader->>Resolver: _build_runtime_constructor_kwargs(..., package_models_dir)
    Resolver->>Resolver: _resolve_rapidocr_model_paths(lang, ocr_version, ...)
    loop 对每种模型类型 det/cls/rec
        Resolver->>FS: 检查 user_cache 中候选文件
        FS-->>Resolver: 存在/不存在
        alt 存在
            Resolver->>Resolver: 选用 user_cache 中的模型路径
        else
            Resolver->>FS: 检查 package_models_dir 中候选文件
            FS-->>Resolver: 存在/不存在
            Resolver->>Resolver: 如存在则选用 package 中的路径
        end
    end
    Resolver-->>Loader: 返回 det/cls/rec 路径与 engine_type
    Loader->>RapidOCR: 构造 runtime(模型路径, engine_type, ...)
    RapidOCR-->>Loader: 返回 runtime 实例与 metadata
    Loader-->>Config: 返回 runtime 与元信息
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Project-N-E-K-O/N.E.K.O#1191: 也修改了 rapidocr 支持与配置(load_rapidocr_runtime 与 rapidocr 配置字段/默认值相关),可能存在实现重叠喵。

Poem

小改一行换版本喵,
包里本地来回看喵,
优先用户稳如山喵,
测试护航把路判喵,
加载顺利元数据现喵。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 标题准确概括了核心变更:使 RapidOCR 模型配置实际生效,这正是本次提交从模型路径解析、参数传递到默认版本对齐的主要目标喵。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

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

@chatgpt-codex-connector
Copy link
Copy Markdown

💡 Codex Review

del model_type
lang = str(lang_type or DEFAULT_RAPIDOCR_LANG_TYPE).strip() or DEFAULT_RAPIDOCR_LANG_TYPE
version = str(ocr_version or DEFAULT_RAPIDOCR_OCR_VERSION).strip() or DEFAULT_RAPIDOCR_OCR_VERSION
det_name = f"{lang}_{version}_det_infer.onnx"
rec_name = f"{lang}_{version}_rec_infer.onnx"

P2 Badge Use model_type when composing RapidOCR model filenames

The new resolver explicitly discards model_type and hardcodes filename patterns that do not vary by model size, so selecting a non-default model variant can never be resolved from disk. In that case _build_runtime_constructor_kwargs omits model paths and silently falls back to runtime defaults, which means rapidocr_model_type is no longer actually honored for affected configurations (for example when model artifacts are named differently by variant).

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
plugin/plugins/galgame_plugin/rapidocr_support.py (2)

222-253: 💤 Low value

model_search_dirs 这个 API 有点别扭,可以再瘦一瘦身喵~

第 221-222 行:model_cache_dir 已经作为命名参数传进来了,调用方又把同一个对象塞到 model_search_dirs[0],然后这里又靠 search_dirs[1] if len(search_dirs) > 1 else Path() 这种魔术索引把 package 目录抠出来——顺序约定全靠默契,谁多塞一个或者顺序换了都会爆出奇奇怪怪的 bug 喵。要么直接收一个具名的 package_models_dir,要么彻底用 model_search_dirs 单一来源(去掉 model_cache_dir 重复传入),二选一就好啦~

顺带 244-250 行那几个 if use_resolved_model_paths and det_path:det_path / rec_path 的判空在 use_resolved_model_paths = bool(det_path and rec_path) 之后已经是冗余的,可以顺手清掉喵。

♻️ 建议的简化喵~
 def _build_runtime_constructor_kwargs(
     runtime_class: type[Any],
     *,
     engine_type: str,
     lang_type: str,
     model_type: str,
     ocr_version: str,
     model_cache_dir: Path,
-    model_search_dirs: list[Path] | None = None,
+    package_models_dir: Path | None = None,
 ) -> dict[str, Any]:
     ...
     if has_var_kwargs:
-        search_dirs = list(model_search_dirs or [])
-        package_models_dir = search_dirs[1] if len(search_dirs) > 1 else Path()
         det_path, cls_path, rec_path = _resolve_rapidocr_model_paths(
             model_cache_dir=model_cache_dir,
-            package_models_dir=package_models_dir,
+            package_models_dir=package_models_dir or Path(),
             lang_type=lang_type,
             ocr_version=ocr_version,
             model_type=model_type,
         )
         kwargs: dict[str, Any] = {}
-        use_resolved_model_paths = bool(det_path and rec_path)
-        if use_resolved_model_paths and det_path:
-            kwargs["det_model_path"] = det_path
-        if use_resolved_model_paths and cls_path:
-            kwargs["cls_model_path"] = cls_path
-        if use_resolved_model_paths and rec_path:
-            kwargs["rec_model_path"] = rec_path
+        if det_path and rec_path:
+            kwargs["det_model_path"] = det_path
+            kwargs["rec_model_path"] = rec_path
+            if cls_path:
+                kwargs["cls_model_path"] = cls_path
         if engine_type:
             kwargs["engine_type"] = engine_type
         return kwargs

调用点(load_rapidocr_runtime 里)相应改成 package_models_dir=package_models_dir 就行啦喵~

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugin/plugins/galgame_plugin/rapidocr_support.py` around lines 222 - 253,
The code is fragile because load_rapidocr_runtime mixes model_cache_dir and a
positional model_search_dirs list and extracts package_models_dir via
search_dirs[1]; change the API to accept an explicit package_models_dir named
parameter (e.g., add package_models_dir: Path | None to load_rapidocr_runtime
signature) and stop relying on model_search_dirs indexing — pass that
package_models_dir into _resolve_rapidocr_model_paths instead of reading
search_dirs[1]; also remove redundant per-path emptiness checks after computing
use_resolved_model_paths = bool(det_path and rec_path) (i.e., drop "and
det_path"/"and rec_path" guards in the blocks that set
det_model_path/cls_model_path/rec_model_path) so only the
use_resolved_model_paths flag controls adding those kwargs.

349-360: 💤 Low value

包内 models 目录的兜底路径已有保护喵,但还可以更完善~

代码在第 121-122 行有对 search_dir 的验证逻辑:if not search_dir or not search_dir.is_dir(): continue,所以即使 package_models_dir 不存在也会被安全跳过。但从可观测性角度,当包内 models 目录找不到而被跳过时,缺少日志记录。建议在 _resolve_rapidocr_model_paths 函数中增加一条 debug 级日志,记录搜索路径的查找失败或跳过情况,方便后续排错的时候有线索可循喵~这样即使用户遇到模型加载问题,也能从日志里看出是否命中了兜底路径。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugin/plugins/galgame_plugin/rapidocr_support.py` around lines 349 - 360,
The function _resolve_rapidocr_model_paths should log when a candidate
search_dir is skipped; update the logic that iterates search_dir (used via
model_search_dirs including package_models_dir constructed in
rapidocr_support.py) to emit a debug-level message whenever "if not search_dir
or not search_dir.is_dir(): continue" evaluates true, including the path value
and reason (empty vs not a directory) so package_models_dir misses are
observable; add this debug log next to that check (use the module's logger or
existing logging facility) without changing control flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@plugin/plugins/galgame_plugin/rapidocr_support.py`:
- Around line 102-135: The function _resolve_rapidocr_model_paths currently
deletes model_type and hardcodes mobile class filename, so server/mobile config
is ignored; restore and use the model_type value when building det_name,
rec_name and cls_name (e.g. include "_server" vs "_infer" variants or the
correct naming convention for server vs mobile), and add a simple
validation/clamp for model_type (accept only "mobile" or "server" and emit a
warning/log if unsupported) so users who set rapidocr_model_type="server" will
have the correct filenames searched (update references to det_name, rec_name,
cls_name and the initial del model_type usage).

---

Nitpick comments:
In `@plugin/plugins/galgame_plugin/rapidocr_support.py`:
- Around line 222-253: The code is fragile because load_rapidocr_runtime mixes
model_cache_dir and a positional model_search_dirs list and extracts
package_models_dir via search_dirs[1]; change the API to accept an explicit
package_models_dir named parameter (e.g., add package_models_dir: Path | None to
load_rapidocr_runtime signature) and stop relying on model_search_dirs indexing
— pass that package_models_dir into _resolve_rapidocr_model_paths instead of
reading search_dirs[1]; also remove redundant per-path emptiness checks after
computing use_resolved_model_paths = bool(det_path and rec_path) (i.e., drop
"and det_path"/"and rec_path" guards in the blocks that set
det_model_path/cls_model_path/rec_model_path) so only the
use_resolved_model_paths flag controls adding those kwargs.
- Around line 349-360: The function _resolve_rapidocr_model_paths should log
when a candidate search_dir is skipped; update the logic that iterates
search_dir (used via model_search_dirs including package_models_dir constructed
in rapidocr_support.py) to emit a debug-level message whenever "if not
search_dir or not search_dir.is_dir(): continue" evaluates true, including the
path value and reason (empty vs not a directory) so package_models_dir misses
are observable; add this debug log next to that check (use the module's logger
or existing logging facility) without changing control flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 621e055f-edc1-4054-914c-58a08c3392b0

📥 Commits

Reviewing files that changed from the base of the PR and between da5a9db and e14d2a9.

📒 Files selected for processing (5)
  • plugin/plugins/galgame_plugin/models.py
  • plugin/plugins/galgame_plugin/plugin.toml
  • plugin/plugins/galgame_plugin/rapidocr_support.py
  • plugin/plugins/galgame_plugin/test_ocr_pipeline.py
  • plugin/tests/unit/plugins/test_galgame_rapidocr_support.py

Comment thread plugin/plugins/galgame_plugin/rapidocr_support.py
- _resolve_rapidocr_model_paths 真正使用 model_type,server 变体走 PaddleOCR
  的 `_server_infer` 命名(cls 跨变体共享 mobile)
- _build_runtime_constructor_kwargs 把 model_search_dirs 列表换成具名
  package_models_dir 参数,去掉魔术索引和冗余的 per-path 判空
- 新增 server 变体回归测试,更新现有测试切到新参数名

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@wehos
Copy link
Copy Markdown
Contributor

wehos commented May 6, 2026

@coderabbitai @codex 综合回一下 review 反馈(at 5fd9684):

Major / P2:model_type 被吞 — 已修。按 PaddleOCR 命名约定,server 变体在 _infer 前插 _server infix;cls 跨变体共享 mobile 模型;无效值静默回退到 mobile(runtime 默认模型仍会兜底,警告反而是噪音)。新增 server 变体回归测试。

Nitpick (222-253):model_search_dirs 列表参数 + 冗余判空 — 已采纳,重构为具名 package_models_dir: Path | None,去掉魔术索引和重复的 if use_resolved_model_paths and det_path 判空。

Nitpick (349-360):包内 models 目录 miss 时加 debug 日志 — 不采纳。_resolve_rapidocr_model_paths 现在是纯函数,调用方已经能从返回值里看出有没有命中(命中就把路径塞进 kwargs,没命中就 fall back 到 RapidOCR runtime 默认)。再加一层 debug log 价值不大,且 model_cache_dir 在用户首次安装前必然不存在,每次正常调用都会刷一行 "skip empty dir" 反而干扰。

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Tip

For best results, initiate chat on the files or code changes.

@wehos 收到喵~让本喵来逐条确认一下~

Major / P2 model_type 被吞 ✅ — 修复方案很合理喵!_server infix 符合 PaddleOCR 的命名约定,cls 共用 mobile 模型也是正确的,无效值静默回退到 mobile 而不是抛警告的设计也很干净喵~新增 server 变体回归测试也是应该的~

Nitpick (222-253) model_search_dirs 重构 ✅ — 把魔术索引换成具名参数 package_models_dir: Path | None 确实更清晰喵!去掉冗余的 if use_resolved_model_paths and det_path 判空也让代码更紧凑了,采纳得很好喵~

Nitpick (349-360) debug 日志 🚫 — 不采纳的理由本喵能接受喵~_resolve_rapidocr_model_paths 作为纯函数,返回值本身就能表达"命中 / 未命中"的状态;而且 model_cache_dir 在首次安装前必然不存在,硬要加日志的话每次正常调用都会刷噪音,反而干扰排查喵。这个设计决策没问题的~

总体来看这次修改把主要的问题都解决掉了,设计也变得更整洁了喵~辛苦了,做得不错嘛……才、才不是在夸你呢喵!(`・ω・´)

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5fd96846a8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +117 to +118
det_name = f"{lang}_{version}{server_infix}_det_infer.onnx"
rec_name = f"{lang}_{version}{server_infix}_rec_infer.onnx"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Build server model filenames using RapidOCR naming

When model_type == "server", this now constructs ..._server_det_infer.onnx/..._server_rec_infer.onnx, but RapidOCR 1.4.4 (the version pinned in this repo) uses ..._det_server_infer.onnx and ..._rec_server_infer.onnx. In that configuration the resolver never finds server models, so model_type=server silently falls back to non-server behavior and the new regression test passes only because it encodes the same wrong pattern.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

你说得对,我把 infix 位置放错了。查 SWHL/RapidOCR HuggingFace repo 确认实际命名是 ch_PP-OCRv4_det_server_infer.onnx / ch_PP-OCRv4_rec_server_infer.onnx_server_det/_rec 之后、_infer 之前),不是我之前写的 ..._server_det_infer。已修:infix 移到正确位置,回归测试同步更新。

at 432318d

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
plugin/plugins/galgame_plugin/rapidocr_support.py (1)

350-351: 💤 Low value

小喵唠叨:module_file 为空时回退到 Path() 会变成 CWD 搜索喵。

Path() 等于 Path("."),然后 _resolve_rapidocr_model_paths 里的 search_dir.is_dir() 在当前工作目录下会判 True,理论上会去 CWD 翻 *_det_infer.onnx。虽然 rapidocr_onnxruntime 是常规包,__file__ 缺失的几率几乎为零,但留个空哨兵会更明确喵~

♻️ 一种更显式的写法(可选)喵~
-        module_file = getattr(module, "__file__", "") or ""
-        package_models_dir = Path(module_file).resolve().parent / "models" if module_file else Path()
+        module_file = getattr(module, "__file__", "") or ""
+        package_models_dir: Path | None = (
+            Path(module_file).resolve().parent / "models" if module_file else None
+        )

_build_runtime_constructor_kwargs(... package_models_dir=package_models_dir) 已经能接 None 了,所以不用动调用点喵。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugin/plugins/galgame_plugin/rapidocr_support.py` around lines 350 - 351,
The code falls back to Path() when module.__file__ is missing which equals the
CWD and can cause _resolve_rapidocr_model_paths to inadvertently search the
working directory for ONNX files; change the sentinel to None instead: set
package_models_dir to Path(module_file).resolve().parent / "models" if
module_file else None so callers like _resolve_rapidocr_model_paths and
_build_runtime_constructor_kwargs receive None (the latter already accepts None)
and will skip CWD scanning.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@plugin/plugins/galgame_plugin/rapidocr_support.py`:
- Around line 350-351: The code falls back to Path() when module.__file__ is
missing which equals the CWD and can cause _resolve_rapidocr_model_paths to
inadvertently search the working directory for ONNX files; change the sentinel
to None instead: set package_models_dir to Path(module_file).resolve().parent /
"models" if module_file else None so callers like _resolve_rapidocr_model_paths
and _build_runtime_constructor_kwargs receive None (the latter already accepts
None) and will skip CWD scanning.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 96fea7d2-75b6-4bb5-ac8a-586d2de4e793

📥 Commits

Reviewing files that changed from the base of the PR and between e14d2a9 and 5fd9684.

📒 Files selected for processing (2)
  • plugin/plugins/galgame_plugin/rapidocr_support.py
  • plugin/tests/unit/plugins/test_galgame_rapidocr_support.py

…odule-file fallback

- 修正 server 变体文件名:infix 应在 `_det`/`_rec` 之后(PaddleOCR 实际命名是
  `ch_PP-OCRv4_det_server_infer.onnx`,参见 SWHL/RapidOCR HuggingFace repo),
  上一版误把 infix 放到了 lang/version 后面
- module_file 缺失时 package_models_dir 从 Path()(= CWD)改为 None,
  避免 _resolve_rapidocr_model_paths 误扫工作目录
- 同步修正 server 变体回归测试的文件名

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@wehos
Copy link
Copy Markdown
Contributor

wehos commented May 6, 2026

@coderabbitai @codex 跟进 review(at 432318d):

Codex P2 — server filename infix 位置错 ✅ 修了。我和 CodeRabbit 上一轮的建议都把 _server infix 放到了 {lang}_{version} 之后、_det 之前,但查 SWHL/RapidOCR HuggingFace repo 确认 RapidOCR 1.4.4 实际用的是 ch_PP-OCRv4_det_server_infer.onnx(infix 夹在 _det/_rec_infer 之间)。已纠正 + 测试同步。

CodeRabbit nitpick (350-351) — Path() 兜底会变 CWD ✅ 采纳了。module_file 缺空时用 None sentinel 比 Path() 干净(Path() 等于 Path('.')is_dir() 在 CWD 必判 True 会让 _resolve_rapidocr_model_paths 误扫工作目录翻 onnx)。_resolve_rapidocr_model_paths 签名一并改成 Path | None_build_runtime_constructor_kwargs 不再用 or Path() 把 None 转回去。

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Tip

For best results, initiate chat on the files or code changes.

@wehos 两条都确认啦,本喵来逐条 check 喵~

Codex P2 — server filename infix 位置 ✅ — 已在 SWHL/RapidOCR HuggingFace repo 里亲自核实过喵!PP-OCRv4 目录下确实是 ch_PP-OCRv4_det_server_infer.onnxch_PP-OCRv4_rec_server_infer.onnx,即 _server 夹在 _det/_rec_infer 之间,上一轮的建议放错位置了喵……这里要道歉一下,感谢去源头核实的喵!纠正后测试同步更新,处理得很稳~

CodeRabbit nitpick (350-351) — Path()None sentinel ✅ — 采纳得非常对喵!Path() 等于 Path('.') 指向 CWD,is_dir() 必然为 True_resolve_rapidocr_model_paths 就会误扫工作目录乱翻 onnx,这是个真实的 bug 隐患喵。改成 None sentinel、签名同步改为 Path | None、调用方也不再用 or Path() 转换,整条链路都干净了喵~

两条修复都很漂亮,辛苦了喵!(。•́ωก̀。) 才不是真的在夸你呢喵!

(っ˘ω˘ς )
  ∧_∧ ✨
 (◕ᴗ◕✿)

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…config-not-applied

# Conflicts:
#	plugin/plugins/galgame_plugin/rapidocr_support.py
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 81c80625aa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plugin/plugins/galgame_plugin/rapidocr_support.py
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