CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Typing] 添加 libpaddle
的 stub 文件生成脚本
#66357
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
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/requirements.txt
Outdated
Pillow | ||
decorator | ||
astor | ||
opt_einsum==3.3.0 | ||
networkx | ||
typing_extensions | ||
pybind11-stubgen==2.5.1 # generate stub file from pybind11 C++ APIs |
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.
这个库,只是在运行 setup.py 时需要,在 paddlepaddle package 的运行时,并不需要吧?
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.
运行时不需要,现在还只在测试,之后会考虑在用户的依赖里过滤掉,目前考虑的是直接在 requirements.txt
里加个 [build]
标记,在 setup 里过滤掉,以免影响各种流水线和开发流程什么的
比如
Pillow
decorator
astor
opt_einsum==3.3.0
networkx
typing_extensions
pybind11-stubgen==2.5.1 # [build]
长期来看,我们应该有 requirements-build.txt
、requirements-dev.txt
、requirements-test.txt
等多个依赖清单
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.
OK, 明白了。
等 ready 后 ping 我一下,我再给 approve。
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.
是的 ~
目前 paddle 有三个 requirements.txt
(我找到的 ... ...
- paddle 打包安装时的依赖,也就是这个
python/requirements.txt
(直接面对用户的,与编译测试无关) - 单测时的依赖,
python/unittest_py/requirements.txt
(类似requirements-test.txt
) - 编译时的依赖,
paddle/scripts/compile_requirements.txt
(类似requirements-build.txt
)
感觉 pybind11-stubgen
应该放在 paddle/scripts/compile_requirements.txt
中,但是,之前试过,无法触发安装(windows 下可以,mac 和 linux 下不行)。
而 setup.py
中检查 build
依赖,只会检查 python/requirements.txt
,也就导致 pybind11-stubgen
无法在编译时安装。(当然,可以放在 CMakeLists 中,直接在编译时安装,但个人感觉不太合适)
所以,这里先放在 python/requirements.txt
验证一下功能。
另外,单独提一下,后续如果区分 requirements.txt
、 requirements-build.txt
等依赖关系的时候,需要注意一下: requirements-build.txt
>= requirements.txt
即,编译时的依赖需要包含运行时依赖,因为:
- 至少从 typing 特性的角度来说,需要在编译后、
安装打包 前,能够正常导入paddle
以及libpaddle
- 目前的编译打包逻辑也是如此验证环境的
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.
目前考虑的是直接在
requirements.txt
里加个[build]
标记,在 setup 里过滤掉
记得合入前需要实现这个机制,并验证下(unzip
wheel 包查看 dist-info
里的 METADATA
就可以看到依赖项了)
Update 20240724
另外,计划通过解析 |
libpaddle
的 stub 文件生成脚本libpaddle
的 stub 文件生成脚本
… typing_libpaddle
libpaddle
的 stub 文件生成脚本libpaddle
的 stub 文件生成脚本
libpaddle
的 stub 文件生成脚本libpaddle
的 stub 文件生成脚本
Sorry to inform you that 7175f55's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
… typing_libpaddle
… typing_libpaddle
… typing_libpaddle
… typing_libpaddle
… typing_libpaddle
… typing_libpaddle
… typing_libpaddle
python/setup.py.in
Outdated
package_data['paddle'] = [ | ||
*package_data.get('paddle', []), | ||
'py.typed', | ||
'*.pyi', | ||
] |
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.
这块封装个函数吧,比如
extend_package_data(
package_data,
{
"paddle": ['py.typed', '*.pyi'],
"paddle.framework": ["*.pyi"],
...
}
)
… typing_libpaddle
… typing_libpaddle
Update 20240830
在本 PR 中修复此问题 ~ |
… typing_libpaddle
… typing_libpaddle
… typing_libpaddle
… typing_libpaddle
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.
PR Category
User Experience
PR Types
Improvements
Description
添加
libpaddle
的 stub 文件生成脚本。使用工具
pybind11-stubgen
生成libpaddle
的 stub 文件。有几点需要注意的:
没有在
python/paddle/base
下直接生成libpaddle
文件夹(内含 stub 文件)主要原因是,一旦这个文件夹被污染,则极有可能程序中无法正常导入
libpaddle
模块。因此,将生成的文件统一放到了
python/paddle/_typing/libs
目录下,这里以后也可以放置其他 pybind11 的 C++ API 相应的 stub 文件。patch 了
pybind11-stubgen
中Printer
的方法,主要目的是,使pyi
文件消除语法错误,以可以正常进行mypy
检查主要改动为:
对于
Printer
中的print_xxx
方法,如果输入参数中的name
不合法,则会在name
后添加_
。这里主要应对 C++ 中有参数用的
in
作为输入参数,因此修改了输入参数名,如in
改为in_
。影响是,使用kwargs
的方式调用的时候可能会发现输入参数名不对。另外,发现有个函数名是assert
,也改为了assert_
,这个函数是没法直接调用了(静态检查的时候)~ 整体上来说感觉影响不大 ~对于
Printer
中的print_invalid_exp
方法,由直接输出不合法的名称,改为通过引号引用。如
def dist_config(self) -> paddle::DistConfig
改为了def dist_config(self) -> "paddle::DistConfig":
。改动前的代码是存在语法错误的,改动后的语法正常,而在类型检查时转为了Any
。这类错误主要是 pybind11 使用不当引起的 ~与
Tensor.pyi
一样,会在paddle_binary_dir
和paddle_source_dir
中同时添加。大体看了一下生成的文件,出问题的地方基本都是 pybind11 使用不当导致的,整体来看可用性还行?!~
关联
@SigureMo