Repository navigation
Conversation
新增方法:按 Excel 中记录的「原文件名 → 新文件名」映射批量重命名文件。 和 replace4filename 互补:后者是按规则替换文件名中的字符,本方法适合改名规则 不统一、只能逐个列在表格里的场景。 按照贡献规范,所有代码都放在 contributors/my12yyds/ 下,未修改任何已有文件: - contributors/my12yyds/batch_rename_by_excel.py 实现,每个参数和返回值都有注释 - contributors/my12yyds/test_batch_rename_by_excel.py 单元测试,8 个用例 - skills/file/batch_rename_by_excel/SKILL.md 技能说明 - skills/file/batch_rename_by_excel/__init__.py 技能包装 函数返回 dict(renamed / skipped / missing / conflicts),支持 dry_run 先预览, 目标文件已存在时跳过而不覆盖。
CoderWanFeng
pushed a commit
that referenced
this pull request
Oct 25, 2026
Owner
|
感谢贡献!🎉 你的 PR 已合入 合入 commit:
验证情况:
我补了一处小改动( 几点很欣赏的地方:
期待你继续贡献! |
CoderWanFeng
pushed a commit
that referenced
this pull request
Oct 26, 2026
发布 1.1.0:合入 #183 / #184 / #185 三个 PR,以及自 1.0.6 以来的全部修复。 主要内容: - feat(cli): 第一波 CLI 实现 —— `po` 命令 (#184) - feat(contributors): 5 个 Excel 数据核对与整理方法 (#185) - feat(contributor): batch_rename_by_excel (#183) - fix(excel): 拆分时保留 0 值 (#180) - fix(finance): t0 的 Decimal/float TypeError (#181) - fix(excel): 拆分输出工作簿有效性 (#182) - 及其他 1.0.6 以来的修复与文档更新 - 合并 main 独有的 #141 / #155 版本号: 1.0.6 → 1.1.0
CoderWanFeng
pushed a commit
that referenced
this pull request
Oct 26, 2026
## 问题
6 个贡献者 Skill 的 `__init__.py` 用 try/except 兜底处理「contributors 目录
不随包发布」的情况,但写法是:
except ImportError as _import_error:
def xxx(*args, **kwargs):
raise ImportError('...') from _import_error
Python 3 在 except 块结束后会自动 `del` 掉 `as` 绑定的异常名,闭包里引用
的 `_import_error` 因而是未定义名字。在真实的 pip 安装环境(contributors
目录不存在)下调用这些 Skill,实际抛出的是:
NameError: name '_import_error' is not defined
而不是作者预期的、带有明确指引的 ImportError 提示。
## 影响范围
- skills/file/batch_rename_by_excel(#183)
- skills/excel/excel_diff、excel_dedupe、excel_column_stats、
excel2json、excel2csv(#185)
## 修复
把异常对象存到模块级变量 `_CONTRIBUTORS_IMPORT_ERROR`,闭包引用该变量,
既修正了 NameError,也保留了原始 ImportError 作为 `__cause__` 异常链。
## 回归覆盖
新增 tests/test_code/test_contributors_skill_fallback.py,显式 mock 掉
contributors 导入来触发兜底分支。该分支在源码仓库内永远不会自然触发,
所以常规测试抓不到这个 bug——回退修复后新测试 12 个 subtest 全部失败。
Co-authored-by: my12yyds <my12yyds@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
说明
按新的贡献规范重做:代码全部放在
contributors/my12yyds/下,没有修改任何已有文件(本次提交只有 4 个新增文件,0 个修改)。contributors/my12yyds/batch_rename_by_excel.pycontributors/my12yyds/test_batch_rename_by_excel.pyskills/file/batch_rename_by_excel/SKILL.mdskills/file/batch_rename_by_excel/__init__.py新方法:batch_rename_by_excel
按 Excel 中记录的「原文件名 → 新文件名」映射,批量重命名目录下的文件。
和现有的
replace4filename互补:replace4filename是「按规则批量替换文件名中的字符」,本方法适合改名规则不统一、只能逐个列在表格里的场景。Excel 只需两列:
返回 dict,四个键:
renamed:已重命名的记录,元素为(原文件名, 新文件名)skipped:跳过的记录及原因(新旧同名、文件名留空等)missing:Excel 里有、但目录下找不到的文件conflicts:目标文件名已存在,为避免覆盖而跳过两个安全设计:
dry_run=True可以先预览再执行;目标文件已存在时跳过而不是覆盖。测试
覆盖:正常改名、
dry_run不改文件、源文件缺失、目标已存在不覆盖、空行/同名跳过、自定义列名、缺列报错、Excel 不存在报错。两个需要你确认的点
skills/file/__init__.py我没有改。 其他 skill 都在分类的__init__.py里用from .xxx import xxx注册,但contributors/目录没有__init__.py,setup.cfg的packages = find:不会把它打进安装包。如果在那里注册,pip install python-office之后import skills.file会因为找不到contributors而整体报错。所以技能包装里用了 try/except 兜底:源码仓库中正常导入,安装包环境调用时给出明确提示。如果你希望仍然按老方式注册,我可以改。测试文件放在了
contributors/my12yyds/里,因为规范写的是「将所有代码放入该文件夹中」。如果希望统一放到tests/下,我可以移动。关于之前的两个 PR
#181 和 #182 改的是
office/下的已有代码,按新规范应该改成 issue。需要的话我关掉这两个 PR,并开对应的 issue 说明问题。