-
Notifications
You must be signed in to change notification settings - Fork 883
Add retry support and exception tolerance for url parser #7734
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
Add retry support and exception tolerance for url parser #7734
Conversation
|
感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-7734.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
该 PR 修改了模型转换文档工具链中的 API URL 解析器,通过对 sphobjinv 的 Inventory 做一层包装,在创建前后增加日志输出,意在辅助排查 objects.inv 解析/加载相关问题。
Changes:
- 将
sphobjinv.inventory.Inventory重命名导入为BaseInventory - 新增同名包装类
Inventory(BaseInventory),在构造前后打印logger.info日志
| from sphobjinv.inventory import Inventory as BaseInventory | ||
|
|
||
|
|
||
| class Inventory(BaseInventory): |
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里新定义的 Inventory 类会遮蔽 sphobjinv.inventory.Inventory 的原始含义,后续读代码/排查问题时容易混淆(尤其在 traceback/类型提示中)。建议把该包装类改成更明确的名字(例如 LoggedInventory/DebugInventory),并在本文件内相应替换调用点;或仅在需要时用局部函数/上下文包装而不是同名类覆盖。
| class Inventory(BaseInventory): | |
| class LoggedInventory(BaseInventory): |
| def __init__(self, *args, **kwargs) -> None: | ||
| logger.info(f"Creating {self.__class__.__name__}") | ||
| super().__init__(*args, **kwargs) | ||
| logger.info(f"Created {self.__class__.__name__}") |
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在 Inventory.__init__ 里使用 logger.info 打印创建/创建完成会显著增加文档构建或工具运行时的日志噪声(该解析器会在 get_parser 中被多次初始化)。更合适的做法是改用 logger.debug,或用环境变量/命令行开关控制是否输出这类调试日志,避免污染 CI 日志。
| @@ -5,7 +5,14 @@ | |||
| from urllib.parse import urljoin | |||
|
|
|||
| from loguru import logger | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个logger也删了吧,直接print,减少下载量
Add retry mechanism with exponential backoff to the Inventory class constructor to handle transient network failures when loading API documentation inventories. The class now retries up to 3 times with a 1-second delay between attempts, logging warnings for retries and raising a ConnectionError after all attempts fail. Wrap the get_url function in a try-except block to catch and log any exceptions during URL resolution, returning an empty string on error instead of crashing. This improves the robustness of the API documentation tooling against intermittent network issues and unexpected parsing errors.
- Remove loguru dependency from pre-doc-compile.sh installation - Replace loguru logger with Python's standard logging.getLogger in api_url_parser.py and api_utils.py - Update logging calls to use standard Python string formatting syntax - Maintain existing functionality while switching to built-in logging module
增强 URL parser 的稳定性