Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
docs/ci_scripts/CAPItools/main.py at develop · PaddlePaddle/docs · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
PaddlePaddle
docs
Repository navigation
Code
Issues
19
(19)
Pull requests
41
(41)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
develop
Breadcrumbs
docs
/
ci_scripts
/
CAPItools
/
main.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
151 lines (123 loc) · 4.94 KB
develop
Breadcrumbs
docs
/
ci_scripts
/
CAPItools
/
main.py
Copy path
Top
File metadata and controls
Code
Blame
151 lines (123 loc) · 4.94 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# python main.py [source dir] [target dir]
# python main.py ../paddle .
import
json
import
os
import
re
import
sys
import
traceback
import
CppHeaderParser
from
utils
import
get_PADDLE_API_class
,
get_PADDLE_API_func
from
utils_helper
import
class_helper
,
func_helper
,
generate_overview
# 解析所有的函数, 类, 枚举, 返回一个字典
# 多线程使用并不安全, 请不要使用多线程
def
analysis_file
(
path
):
header
=
CppHeaderParser
.
CppHeader
(
path
,
encoding
=
"utf8"
)
data
=
json
.
loads
(
header
.
toJSON
())
return
data
# 生成文件
# 根据给定的list内容,生成对应的文档信息
def
generate_docs
(
all_funcs
,
all_class
,
cpp2py_api_list
,
save_dir
,
LANGUAGE
=
"cn"
):
for
item
in
all_funcs
:
path
=
item
[
"filename"
].
replace
(
"../"
,
""
).
replace
(
".h"
,
""
)
dir_path
=
os
.
path
.
join
(
save_dir
,
LANGUAGE
,
path
)
if
not
os
.
path
.
exists
(
dir_path
):
os
.
makedirs
(
dir_path
)
# 这个反斜杠需要单独处理, 在 linux 下
func_name
=
item
[
"name"
].
replace
(
"/"
,
""
)
# Note: 操作符仅不生成rst,实际上在Overview列表依然会呈现以提示存在此操作符
if
func_name
.
startswith
(
"operator"
):
checkwords
=
func_name
.
replace
(
"operator"
,
""
,
1
)
if
re
.
search
(
r"\w"
,
checkwords
)
is
None
:
continue
# 跳过操作符声明
rst_dir
=
os
.
path
.
join
(
save_dir
,
LANGUAGE
,
path
,
func_name
+
".rst"
)
# avoid a filename such as operate*.rst, only windows
try
:
helper
=
func_helper
(
item
,
cpp2py_api_list
)
helper
.
create_and_write_file
(
rst_dir
,
LANGUAGE
)
except
:
print
(
traceback
.
format_exc
())
print
(
"FAULT GENERATE:"
+
rst_dir
)
for
item
in
all_class
:
path
=
item
[
"filename"
].
replace
(
"../"
,
""
).
replace
(
".h"
,
""
)
dir_path
=
os
.
path
.
join
(
save_dir
,
LANGUAGE
,
path
)
if
not
os
.
path
.
exists
(
dir_path
):
os
.
makedirs
(
dir_path
)
func_name
=
item
[
"name"
].
replace
(
"PADDLE_API"
,
""
)
rst_dir
=
os
.
path
.
join
(
save_dir
,
LANGUAGE
,
path
,
func_name
+
".rst"
)
try
:
helper
=
class_helper
(
item
)
helper
.
create_and_write_file
(
rst_dir
,
LANGUAGE
)
except
:
print
(
traceback
.
format_exc
())
print
(
"FAULT GENERATE:"
+
rst_dir
)
# cpp 对应 python api
# 用于存储 api 的名称, 用于后续生成对应python api文档链接
def
cpp2py
(
data
:
dict
):
cpp2py_api_list
=
[]
for
i
in
data
[
"using"
]:
cpp2py_api_list
.
append
(
i
.
replace
(
"paddle::"
,
""
))
return
cpp2py_api_list
# 运行主函数,主要流程如下
# 1. 确定生成的目录
# 2. 提取待生成文档的PADDLE_API list
# 3. 生成文档
if
__name__
==
"__main__"
:
root_dir
=
""
save_dir
=
"."
# 默认保存在当前目录
if
len
(
sys
.
argv
)
==
3
:
root_dir
=
sys
.
argv
[
1
]
save_dir
=
sys
.
argv
[
2
]
if
root_dir
==
""
:
try
:
import
inspect
import
paddle
root_dir
=
os
.
path
.
dirname
(
inspect
.
getsourcefile
(
paddle
))
except
:
# for simple run
root_dir
=
"../paddle"
save_dir
=
"."
# 默认保存在当前目录
all_funcs
=
[]
all_class
=
[]
cpp2py_api_list
=
[]
overview_list
=
[]
for
home
,
dirs
,
files
in
os
.
walk
(
root_dir
):
for
file_name
in
files
:
# 跳过不需要处理的文件
if
file_name
.
split
(
"."
)[
-
1
]
not
in
[
"cc"
,
"cu"
,
"h"
]:
continue
file_path
=
os
.
path
.
join
(
home
,
file_name
)
# 处理 cpp 和 py api对应的文件, 目前只有这个文件内的 cpp api和 python api是对应的
if
file_name
==
"tensor_compat.h"
:
cpp2py_data
=
analysis_file
(
file_path
)
cpp2py_api_list
=
cpp2py
(
cpp2py_data
).
copy
()
# 跳过文件中未包含PADDLE_API
with
open
(
file_path
,
encoding
=
"utf-8"
)
as
f
:
if
"PADDLE_API "
not
in
f
.
read
():
continue
print
(
"Parsing: "
,
file_path
)
data
=
analysis_file
(
file_path
)
# 信息抽取
current_func
=
get_PADDLE_API_func
(
data
)
current_class
=
get_PADDLE_API_class
(
data
)
# 信息记录
all_funcs
.
extend
(
current_func
)
all_class
.
extend
(
current_class
)
overview_list
.
append
(
{
"h_file"
:
file_path
,
"class"
:
current_class
,
"function"
:
current_func
,
}
)
# 生成文档
generate_docs
(
all_funcs
,
all_class
,
cpp2py_api_list
,
save_dir
,
"cn"
)
generate_docs
(
all_funcs
,
all_class
,
cpp2py_api_list
,
save_dir
,
"en"
)
# 生成 overview
generate_overview
(
overview_list
,
save_dir
,
"cn"
)
generate_overview
(
overview_list
,
save_dir
,
"en"
)
# 统计信息
print
(
"PADDLE_API func count: "
,
len
(
all_funcs
))
print
(
"PADDLE_API class count: "
,
len
(
all_class
))
print
(
"cpp2py api count: "
,
len
(
cpp2py_api_list
))
You can’t perform that action at this time.