Skip to content

Conversation

megemini
Copy link
Contributor

@megemini megemini commented Jun 7, 2024

PR Category

User Experience

PR Types

Improvements

Description

修改 tools/type_checking.py ,使其可以单独检查指定的 api,具体用法为:

  1. checking from input apis
> python type_checking.py paddle.abs paddle.abs_ paddle.sin
  1. checking from spec, with increment api
> python type_checking.py
  1. checking from spec, with full apis
> python type_checking.py --full-test

--full-test and apis should not be set at the same time.

@SigureMo

Copy link

paddle-bot bot commented Jun 7, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Jun 7, 2024
@megemini megemini changed the title [Change] type checking with apis [Typing] type checking with apis Jun 7, 2024
@megemini megemini changed the title [Typing] type checking with apis [Typing all] type checking with apis Jun 7, 2024
@megemini megemini changed the title [Typing all] type checking with apis [] type checking with apis Jun 7, 2024
@megemini megemini changed the title [] type checking with apis [Typing] type checking with apis Jun 7, 2024
@@ -598,41 +598,48 @@ def get_test_capacity(run_on_device="cpu"):
def get_docstring(
full_test: bool = False,
filter_api: typing.Callable[[str], bool] | None = None,
apis: tuple[tuple[str, str], ...] | None = None,
Copy link
Member

Choose a reason for hiding this comment

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

这里是不是用 list 更合适?

# We type-check the `Example` codes from docstring.
# We type-check the `Example` codes from docstring, like:
# 1. checking from input `apis`
# > python type_checking.py paddle.abs paddle.abs_ paddle.sin
Copy link
Member

@SigureMo SigureMo Jun 7, 2024

Choose a reason for hiding this comment

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

这里的 1 需要预先手动生成 spec 么?

Copy link
Contributor Author

@megemini megemini Jun 8, 2024

Choose a reason for hiding this comment

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

不用 ~ 单独检查指定的 api (如 python type_checking.py paddle.abs paddle.abs_ paddle.sin)与通过 spec 检查(如 python type_checking.py)是互斥的 ~

也就是说,开发者可以用这个脚本在本地检查 api 的 typing ~

本来是想把这个功能单独写一个工具的,就像之前 xdoctest 那个,但是,出于以下考虑,整合在了这里:

  • type checking 需要动态获取 api 的签名

    之前的 xdoctest 可以看作是静态检查,而 type checking 需要开发者改完之后重新打包安装,或者手动覆盖掉修改的文件,所以要麻烦很多 ~

  • mypy 的配置文件应该会不断更新

    如果像之前那样单列工具,那么两边同步的工作会很多,不利用使用 ~

由此,这里把 type_checking.py 简单扩展了一下,方便开发者本地调试 ~ 当然,调试前还是需要自己手动重新打包安装 ~

看看还没有什么更好的方式?

执行方式:

> python type_checking.py paddle.abs paddle.acos
----------------Codeblock Type Checking Start--------------------
>>> Get docstring from api ...
API_PR is diff from API_DEV: dict_keys(['paddle.abs', 'paddle.acos'])
Total api: 2
>>> Running type checker ...
>>> Print summary ...
----------------Check results--------------------
----------------Check results--------------------
>>> Type checking is successful!
>>> Type checking is successful!
----------------End of the Check--------------------
----------------End of the Check--------------------

Copy link
Member

Choose a reason for hiding this comment

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

嗯嗯,这里没什么更多问题了,只是在 CI 中是否可以像 codestyle 流水线一样,失败后提示用户如何复现问题?

echo "Your PR code style check failed."
echo "Please install pre-commit locally and set up git hook scripts:"
echo ""
echo " pip install pre-commit==2.17.0"
echo " pre-commit install"
echo ""
if [[ $num_diff_files -le 100 ]];then
echo "Then, run pre-commit to check codestyle issues in your PR:"
echo ""
echo " pre-commit run --files" $(echo ${diff_files} | tr "\n" " ")
echo ""
fi
echo "For more information, please refer to our codestyle check guide:"
echo "https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/dev_guides/git_guides/codestyle_check_guide_cn.html"

仅提示失败的那几个就好~比如 API diff 含 paddle.abspaddle.acos,前者成功,后者失败,那么提示使用 python type_checking.py paddle.acos 来复现

@megemini megemini changed the title [Typing] type checking with apis [Typing all] type checking with apis Jun 10, 2024
@SigureMo
Copy link
Member

image

话说为什么会有一些分布式 API 也被检查了呢?

logger.error(
">>> Please recheck the type annotations. Run `tools/type_checking.py` to check the typing issues:"
)
logger.error("> python type_checking.py " + " ".join(failed_apis))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logger.error("> python type_checking.py " + " ".join(failed_apis))
logger.error("> python tools/type_checking.py " + " ".join(failed_apis))

@megemini
Copy link
Contributor Author

话说为什么会有一些分布式 API 也被检查了呢?

print_signatures.py 里是这么获取的 api ,我们只负责检查 ~

需要过滤一下?

@SigureMo
Copy link
Member

print_signatures.py 里是这么获取的 api ,我们只负责检查 ~

喔喔,没注意用了 typing all,我以为用的是 typing

@SigureMo SigureMo changed the title [Typing all] type checking with apis [Typing] type checking with apis Jun 12, 2024
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants