-
Notifications
You must be signed in to change notification settings - Fork 724
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
[ci] 添加监测中文 apilabel 的 ci #6226
Conversation
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.
感觉像是一坨,先提一下
没关系,咱代码风格可以慢慢锻炼,这个多写写就好了,而且还有我来把控~而且比某些写了一坨还不自知的人强太多了(这个 repo 能成这样,所有代码 reviewer 都有责任)
ci_scripts/check_api_label_cn.py
Outdated
result = re.sub("api/", "", file) | ||
result = re.sub("_cn.rst", "", result) | ||
result = re.sub('/', "_", result) |
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.
不是很建议使用 re.sub,更建议直接分别使用 removeprefix、removesuffix、replace 这三个,因为 sub 的话无法确定删除的是什么位置的,前两个函数好像 3.10 才有,需要确认 CI 是 3.10 环境(我记得之前改成 3.10 了)
ci_scripts/check_api_label_cn.py
Outdated
result = re.sub("api/", "", file) | ||
result = re.sub("_cn.rst", "", result) | ||
result = re.sub('/', "_", result) | ||
result = '.. _cn_' + result + ':' |
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.
result = '.. _cn_' + result + ':' | |
result = f'.. _cn_{result}:' |
字符串操作使用 f-string 可读性会非常好~
ci_scripts/check_api_label_cn.py
Outdated
if ( | ||
file.endswith("_cn.rst") | ||
and (file not in ["Overview_cn.rst", "index_cn.rst"]) | ||
and file.startswith("api") |
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.
代码里若干处硬编码了 "api"
这个字符串,其实可以考虑怎么优化下,是否传递参数时不要 api,或者整个常量什么的
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.
ci_scripts/check_api_label_cn.py
Outdated
and file.startswith("api") | ||
): | ||
return True | ||
return False |
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.
-def fooooo():
- if xxx:
- return True
- return False
+ return xxx
直接 return 就好呀
ci_scripts/check_api_label_cn.py
Outdated
with open(rootdir + file, 'r', encoding='utf-8') as f: | ||
pattern = f.read() | ||
matches = re.findall(r":ref:`([^`]+)`", pattern) | ||
if matches: |
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.
这个判断是没必要的,因为没有结果的话 matches 是 []
,对空 list 遍历就直接跳过了,可以减少一个缩进
ci_scripts/check_api_label_cn.py
Outdated
if match.startswith('cn'): | ||
if match not in list: | ||
print(rootdir + file, 'ref' + match, 'error') | ||
else: | ||
out = re.search("<(.*?)>", match) | ||
if out and out.group(1).startswith("cn"): | ||
if out.group(1) not in list: | ||
print(rootdir + file, 'ref' + match, 'error') |
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.
这两个分支是可以合并的,其实主要就是从
:ref:`xxx`
:ref:`aaa <xxx>`
两种情况提取 xxx
嘛
可以
api_label = # 前面的 match
if api_label_match := re.match(r".+<(?P<api_label>.+?)>", api_label):
api_label = api_label_match.group("api_label")
if api_label.startswith("cn_") and api_label not in valid_api_labels:
logger.error(f"Found api label {api_label} in {rootdir}/{file}, but it is not a valid api label, please re-check it!")
sys.exit(1)
整体缩进层级会少很多~
ci_scripts/check_api_label_cn.py
Outdated
|
||
|
||
if __name__ == "__main__": | ||
pipline(sys.argv[1], sys.argv[2:]) |
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.
虽然整体很简单,但还是建议使用 argparse,参数语义会更清晰,可读性会更强
ci_scripts/check_api_label_cn.py
Outdated
if should_test(file): | ||
if check_api_label(rootdir, file): | ||
pass | ||
else: | ||
print("error:", file) |
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.
if should_test(file): | |
if check_api_label(rootdir, file): | |
pass | |
else: | |
print("error:", file) | |
if should_test(file) and not check_api_label(rootdir, file): | |
sys.exit(1) # 这里是不是应该报错?而不是仅仅 print? |
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.
新commit加上了logger.error
ci_scripts/check_api_label_cn.py
Outdated
if len(sys.argv) == 2: | ||
parser.print_help() | ||
sys.exit(1) | ||
|
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.
用了 argparse,这块是不是就可以不用了?
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.
感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-6226.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html |
@ooooo-create 可以触发一下测试一下,现在 CI 好像没有跑?测试如果没啥问题(包括正确 case 正确通过和错误 case 正常报错),我觉得就没问题了 |
好的,是在这个 pr 里,通过 修改文件 来测试吗 |
对的 |
ci_scripts/check_api_label_cn.py
Outdated
@@ -67,7 +67,8 @@ def find_api_labels_in_one_file(file_path): | |||
def should_test(file): | |||
return ( | |||
file.endswith("_cn.rst") | |||
and (file not in ["Overview_cn.rst", "index_cn.rst"]) | |||
and not file.endswith("Overview_cn.rst") | |||
and not file.endswith("index_cn.rs") |
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.
为啥是 .rs
?rust 代码么 [doge]
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.
[doge] t
走丢了,过会就回来
@SigureMo 一师傅, |
然后这句话的 b 丢了 [doge] 你先测试着,如果测试都没问题了叫我 |
ci_scripts/check_api_label_cn.py
Outdated
print(first_line) | ||
print(generate_en_label_by_path(file)) |
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.
这两行是用来 debug 的么?
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.
是的~
ci_scripts/check_api_label_cn.py
Outdated
) | ||
|
||
|
||
def pipline(rootdir, files): |
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.
pipeline?
@@ -46,7 +46,7 @@ | |||
二、动态图操作实践 | |||
--------------------------- | |||
|
|||
使用飞桨框架提供的 API:\ ``paddle.amp.auto_cast``\ 和\ ``paddle.amp.GradScaler``\ 能够实现动态图的自动混合精度训练,即在相关 OP 的计算中,自动选择 FP16 或 FP32 格式计算。开启 AMP 模式后,使用 FP16 与 FP32 进行计算的 OP 列表可以参见 :ref:`cn_overview_amp` 。 | |||
使用飞桨框架提供的 API:\ ``paddle.amp.auto_cast``\ 和\ ``paddle.amp.GradScaler``\ 能够实现动态图的自动混合精度训练,即在相关 OP 的计算中,自动选择 FP16 或 FP32 格式计算。开启 AMP 模式后,使用 FP16 与 FP32 进行计算的 OP 列表可以参见 :ref:`cn_api_paddle_geometric_reindex_grap` 。 |
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.
这个文件是用来测试还是?
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.
测试,没改回去~
ci_scripts/check_api_label_cn.py
Outdated
@@ -74,7 +72,7 @@ def should_test(file): | |||
) | |||
|
|||
|
|||
def pipline(rootdir, files): | |||
def run_cn_api_lable_checking(rootdir, files): |
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.
label?:joy:
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.
LGTMeow 🐾
link #6170
make a try
感觉像是一坨,先提一下
@sunzhongkai588 @SigureMo