-
Notifications
You must be signed in to change notification settings - Fork 752
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
[Change] 更新文档《开发 API Python 端》与《API 文档书写规范》 #6096
[Change] 更新文档《开发 API Python 端》与《API 文档书写规范》 #6096
Conversation
感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-6096.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.
示例代码的篇幅可能太多了,之后需要看一下预览具体占据多少篇幅,如果篇幅过多,则应该单独成篇,或者以附录那种形式,不然会影响其他部分的阅读
|
||
因此,请在书写示例代码时遵循以下规范: | ||
|
||
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.
1. **显性的输出好于注释** | |
1. **显式的输出好于注释** |
|
||
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.
print
可能不是必要的?
# [[5 , 12], | ||
# [21, 32]] |
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.
# [[5 , 12], | |
# [21, 32]] | |
>>> # [[5 , 12], | |
>>> # [21, 32]] |
这里是不是指这样子的?因为原来的 CI 肯定会挂的
|
||
等,都是不建议的输出方式。 | ||
|
||
另外,在 书写/拷贝 示例代码时,请注意以下几点: |
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.
正式文档里最好不要加这种语气词、语气符号?
|
||
4. **能够检查好于跳过检查** | ||
|
||
示例代码的检查可以保证其正确性,但并不是所有代码均能够 正常/正确 的在 CI 环境中运行。 |
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.
这里正常/正确
也一样,最好不要加空格,如果是强调,可以用 **
[0.90525323, 0.42400089, 0.40641287]]) | ||
``` | ||
|
||
3. **明确的设备好于默认的设备** |
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.
这几个标题的说法还需要稍微润色下,感觉整体看起来风格可能像 The Zen of Python?
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.
啊 那不是,我只是觉得这几句感觉风格很像 python 之禅而已,但人家的翻译听起来会更好一些
> - 将 xdoctest 引入到飞桨框架工作流中, https://github.com/PaddlePaddle/community/blob/master/rfcs/Docs/%E5%B0%86%20xdoctest%20%E5%BC%95%E5%85%A5%E5%88%B0%E9%A3%9E%E6%A1%A8%E6%A1%86%E6%9E%B6%E5%B7%A5%E4%BD%9C%E6%B5%81%E4%B8%AD.md | ||
> - 将 xdoctest 引入到飞桨框架工作流中(补充) - 详细设计, https://github.com/PaddlePaddle/Paddle/blob/develop/tools/sampcd_processor_readme.md | ||
> - `doctest`, https://docs.python.org/3/library/doctest.html#module-doctest | ||
> - `xdoctest`, https://xdoctest.readthedocs.io/en/latest/ |
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.
网址链接有点长,要不都改成引用?比如
如: | ||
|
||
``` python | ||
>>> # doctest: +REQUIRES(env:GPU) |
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.
这个还真有点麻烦 ~ sphinx 默认渲染把这个删掉的 ~ 我看看换个标注行不行 ~
- 需要 `GPU` 环境 | ||
|
||
``` python | ||
>>> # doctest: +REQUIRES(env:GPU) | ||
>>> ... | ||
``` | ||
|
||
- 需要 `XPU` 环境 | ||
|
||
``` python | ||
>>> # doctest: +REQUIRES(env:XPU) | ||
>>> ... | ||
``` | ||
|
||
- 需要 `GPU`、`XPU` 等多个环境 | ||
|
||
``` python | ||
>>> # doctest: +REQUIRES(env:GPU, env:XPU) | ||
>>> ... | ||
``` |
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.
``` python | ||
>>> # doctest: +SKIP('file not exist') | ||
>>> with open('cat.jpg') as f: | ||
... im = load_image_bytes(f.read()) | ||
``` | ||
|
||
`SKIP` 指令还可以成对使用,如: | ||
``` python | ||
>>> # doctest: +SKIP('file not exist') | ||
>>> with open('cat.jpg') as f: | ||
... im = load_image_bytes(f.read()) | ||
>>> # doctest: -SKIP | ||
>>> x = paddle.to_tensor([[1, 2], [3, 4]]) | ||
>>> ... | ||
``` |
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 文档的核心部分之一,毕竟 talk is cheap,show me the code。所以,在 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.
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.
可以啊 ~
要么就像 COPY-FROM 那样单独?
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.
为啥预览里图没变..求解 @SigureMo
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.
emmm,不太清楚,可能是有缓存?
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.
有呀,我是说服务器上哪里可能有缓存?本地清缓存刷新无效的
Update 20230815由于 sphinx 对于 doctest 的渲染问题,把 python 改为 text 看看能不能正确渲染~ |
Update 202308021
@SigureMo @sunzhongkai588 请评审~ |
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.
@SigureMo 也看看,还有文档预览里面的图片没有更新的问题
@@ -18,3 +18,4 @@ | |||
./error_message_writing_specification_cn.md | |||
../git_guides/codestyle_check_guide_cn.md | |||
../git_guides/paddle_ci_manual_cn.md | |||
./code_example_writing_specification_cn.md |
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.
>>> import paddle | ||
|
||
>>> x = paddle.to_tensor([[1, 2], [3, 4]]) | ||
>>> y = paddle.to_tensor([[5, 6], [7, 8]]) | ||
>>> res = paddle.multiply(x, y) | ||
>>> print(res) | ||
Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True, | ||
[[5 , 12], | ||
[21, 32]]) | ||
|
||
>>> x = paddle.to_tensor([[[1, 2, 3], [1, 2, 3]]]) | ||
>>> y = paddle.to_tensor([2]) | ||
>>> res = paddle.multiply(x, y) | ||
>>> print(res) | ||
Tensor(shape=[1, 2, 3], dtype=int64, place=Place(cpu), stop_gradient=True, | ||
[[[2, 4, 6], | ||
[2, 4, 6]]]) |
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.
合的太快了 ... ... 换个 pr 修一下吧 ... ...
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.
LGTM,之后看看预览吧
PR types
Others
PR changes
Docs
Description
中国软件开源创新大赛:飞桨框架任务挑战赛
赛题五:将 xdoctest 引入到飞桨框架工作流中
RFC [Add]将 xdoctest 引入到飞桨框架工作流中v1
ISSUE 赛题五:将 xdoctest 引入到飞桨框架工作流中 Tracking Issue
第二阶段
任务:更新文档《开发 API Python 端》与《API 文档书写规范》
涉及文件:
docs/dev_guides/api_contributing_guides/api_docs_guidelines_cn.md
修改API 代码示例
部分。docs/dev_guides/api_contributing_guides/images/zeros_python_api.png
修改示例图片为修改后的样式。@SigureMo @luotao1 @jzhang533 @sunzhongkai588
请评审,谢谢!:)