Skip to content

Commit 29fc20c

Browse files
author
zhangkaihuo
committed
Merge branch 'release/2.2' of https://github.com/PaddlePaddle/docs into release/2.2
2 parents 23954f2 + 675f6a0 commit 29fc20c

File tree

120 files changed

+6585
-4879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+6585
-4879
lines changed

ci_scripts/checkapproval.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ for API_FILE in ${API_FILES[*]}; do
99
if [ "${API_CHANGE}" ];then
1010
approval_line=`curl -H "Authorization: token ${GITHUB_API_TOKEN}" https://api.github.com/repos/PaddlePaddle/docs/pulls/${GIT_PR_ID}/reviews?per_page=10000`
1111
if [ "${API_FILE}" == "docs/api/paddle" ];then
12-
APPROVALS=`echo ${approval_line} | python ./check_pr_approval.py 1 2870059 27208573 29231 28379894 23093488 11935832`
12+
APPROVALS=`echo ${approval_line} | python ./check_pr_approval.py 1 29231 23093488 11935832 39876205`
1313
fi
1414
fi
1515
if [ "${APPROVALS}" == "FALSE" ]; then
1616
if [ "${API_FILE}" == "docs/api/paddle" ];then
17-
echo "You must have one TPM (saxon-zh or swtkiwi or jzhang533 or Heeenrrry or dingjiaweiww or TCChenlong) approval for the api change! ${API_FILE} for the management reason of API interface and API document."
17+
echo "You must have one TPM (jzhang533/ZhangJun or dingjiaweiww/DingJiaWei or TCChenlong/ChenLong or Ligoml/LiMengLiu) approval for the api change! ${API_FILE} for the management reason of API interface and API document."
1818
fi
1919
exit 1
2020
fi

ci_scripts/hooks/pre-doc-compile.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,11 @@ for f in ${FILES_ARRAY[@]} ; do
2626
cat ${TMP_FILE} >> $TARGET_FILE
2727
done
2828

29+
30+
## 2 convert all ipynb files to markdown, and delete the ipynb files.
31+
# ../practices/**/*.ipynb
32+
for i in ${SCRIPT_DIR}/../../docs/practices/**/*.ipynb ; do
33+
echo "convert $i to markdown and delete ipynb"
34+
jupyter nbconvert --to markdown "$i"
35+
rm "$i"
36+
done

docs/api/gen_doc.py

Lines changed: 97 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,23 @@ def process_module(m, attr="__all__"):
141141
if inspect.isclass(api_info['object']):
142142
for name, value in inspect.getmembers(api_info['object']):
143143
if (not name.startswith("_")):
144-
method_full_name = full_name + '.' + name # value.__name__
145-
if name and value and isinstance(value, property):
146-
method_api_info = insert_api_into_dict(
147-
method_full_name, 'class_property')
148-
if method_api_info is not None:
149-
api_counter += 1
150-
elif hasattr(value, '__name__'):
151-
method_api_info = insert_api_into_dict(
152-
method_full_name, 'class_method')
153-
if method_api_info is not None:
154-
api_counter += 1
144+
try:
145+
method_full_name = full_name + '.' + name # value.__name__
146+
if name and value and isinstance(value,
147+
property):
148+
method_api_info = insert_api_into_dict(
149+
method_full_name, 'class_property')
150+
if method_api_info is not None:
151+
api_counter += 1
152+
elif hasattr(value, '__name__'):
153+
method_api_info = insert_api_into_dict(
154+
method_full_name, 'class_method')
155+
if method_api_info is not None:
156+
api_counter += 1
157+
except ValueError as e:
158+
logger.error(
159+
'ValueError when processing %s: %s',
160+
method_full_name, str(e))
155161
return api_counter
156162

157163

@@ -226,9 +232,14 @@ def parse_module_file(mod):
226232
if hasattr(mod, '__name__') and hasattr(mod, '__file__'):
227233
src_file = mod.__file__
228234
mod_name = mod.__name__
235+
if not (isinstance(src_file, str) and isinstance(src_file, str)):
236+
logger.error('%s: mod_name=%s, src_file=%s',
237+
str(mod), mod_name, src_file)
238+
return
229239
logger.debug("parsing %s:%s", mod_name, src_file)
230240
if len(mod_name) >= 6 and mod_name[:6] == 'paddle':
231-
if os.path.splitext(src_file)[1].lower() == '.py':
241+
fn_splited = os.path.splitext(src_file)
242+
if len(fn_splited) > 1 and fn_splited[1].lower() == '.py':
232243
mod_ast = ast.parse(open(src_file, "r").read())
233244
for node in mod_ast.body:
234245
short_names = []
@@ -436,7 +447,8 @@ def set_api_sketch():
436447
paddle.device,
437448
paddle.device.cuda,
438449
paddle.linalg,
439-
paddle.fft
450+
paddle.fft,
451+
paddle.version
440452
]
441453

442454
alldict = {}
@@ -533,44 +545,6 @@ def collect_referenced_from_infos(docdirs):
533545
docdirs)
534546

535547

536-
def get_shortest_api(api_list):
537-
"""
538-
find the shortest api name (suggested name) in list.
539-
540-
Problems:
541-
1. fuild - if there is any apis don't contain 'fluid' in name, use them.
542-
2. core vs core_avx - using the 'core'.
543-
"""
544-
if len(api_list) == 1:
545-
return api_list[0]
546-
# try to find shortest path of api as the real api
547-
api_info = [
548-
] # {'name': name, 'fluid_in_name': True/False, 'core_avx_in_name': True/Flase', 'len': len}
549-
for api in api_list:
550-
fields = api.split('.')
551-
api_info.append({
552-
'name': api,
553-
'fluid_in_name': 'fluid' in fields,
554-
'core_avx_in_name': 'core_avx' in fields,
555-
'len': len(fields),
556-
})
557-
558-
def shortest(api_info):
559-
if not api_info:
560-
return None
561-
elif len(api_info) == 1:
562-
return api_info[0].get('name')
563-
api_info.sort(key=lambda ele: ele.get('len'))
564-
return api_info[0].get('name')
565-
566-
if not all([api.get('fuild_in_name') for api in api_info]):
567-
api_info = [api for api in api_info if not api.get('fluid_in_name')]
568-
sn = shortest([api for api in api_info if not api.get('core_avx_in_name')])
569-
if sn is None:
570-
sn = shortest(api_info)
571-
return sn
572-
573-
574548
def remove_all_en_files(path="./paddle"):
575549
"""
576550
remove all the existed en doc files
@@ -768,8 +742,13 @@ def print_class(self):
768742
}
769743
tmpl = 'default'
770744
for m in [
771-
'fluid.dygraph', 'paddle.vision', 'paddle.callbacks',
772-
'paddle.hapi.callbacks', 'paddle.io', 'paddle.nn'
745+
'fluid.dygraph',
746+
'paddle.vision',
747+
'paddle.callbacks',
748+
'paddle.hapi.callbacks',
749+
'paddle.io',
750+
'paddle.nn',
751+
'paddle.incubate.nn',
773752
]:
774753
if self.api_name.startswith(m):
775754
tmpl = 'no-inherited'
@@ -822,11 +801,65 @@ def __call__(self):
822801
return self.api_name, self.api_ref_name
823802

824803

804+
def get_shortest_api(api_list):
805+
"""
806+
find the shortest api name (suggested name) in list.
807+
808+
Problems:
809+
1. fuild - if there is any apis don't contain 'fluid' in name, use them.
810+
2. core vs core_avx - using the 'core'.
811+
"""
812+
if len(api_list) == 1:
813+
return api_list[0]
814+
# try to find shortest path of api as the real api
815+
api_info = [
816+
] # {'name': name, 'fluid_in_name': True/False, 'core_avx_in_name': True/Flase', 'len': len}
817+
for api in api_list:
818+
fields = api.split('.')
819+
api_info.append({
820+
'name': api,
821+
'fluid_in_name': 'fluid' in fields,
822+
'core_avx_in_name': 'core_avx' in fields,
823+
'len': len(fields),
824+
})
825+
826+
def shortest(api_info):
827+
if not api_info:
828+
return None
829+
elif len(api_info) == 1:
830+
return api_info[0].get('name')
831+
api_info.sort(key=lambda ele: ele.get('len'))
832+
return api_info[0].get('name')
833+
834+
if not all([api.get('fuild_in_name') for api in api_info]):
835+
api_info = [api for api in api_info if not api.get('fluid_in_name')]
836+
sn = shortest([api for api in api_info if not api.get('core_avx_in_name')])
837+
if sn is None:
838+
sn = shortest(api_info)
839+
return sn
840+
841+
825842
def insert_suggested_names():
826843
"""
827-
add suggested_name field, updte the doc_filename, and sort the all_names.
844+
add suggested_name field, updte the doc_filename, and sort the all_names and api_sketch_names.
828845
"""
829846
pat = re.compile(r'paddle\.fluid\.core_[\w\d]+\.(.*)$')
847+
848+
def sort_name_list(api_names):
849+
"""
850+
sort and move paddle.Tensor.* to the end
851+
"""
852+
names_sorted = sorted(list(api_names))
853+
cnt = 0 # count of paddle.Tensor.*
854+
for n in names_sorted:
855+
if n.startswith('paddle.Tensor.'):
856+
cnt += 1
857+
else:
858+
break
859+
if cnt:
860+
names_sorted = names_sorted[cnt:] + names_sorted[:cnt]
861+
return names_sorted
862+
830863
for id_api in api_info_dict:
831864
if "all_names" not in api_info_dict[id_api]:
832865
api_info_dict[id_api]["all_names"] = set()
@@ -840,9 +873,15 @@ def insert_suggested_names():
840873
if mo:
841874
api_info_dict[id_api]["all_names"].add('paddle.fluid.core.' +
842875
mo.group(1))
843-
api_info_dict[id_api]["all_names"] = sorted(
844-
list(api_info_dict[id_api]["all_names"]))
845-
sn = get_shortest_api(api_info_dict[id_api]["all_names"])
876+
api_info_dict[id_api]["all_names"] = sort_name_list(
877+
api_info_dict[id_api]["all_names"])
878+
sn = None
879+
if 'api_sketch_names' in api_info_dict[id_api]:
880+
api_info_dict[id_api]['api_sketch_names'] = sort_name_list(
881+
api_info_dict[id_api]['api_sketch_names'])
882+
sn = get_shortest_api(api_info_dict[id_api]['api_sketch_names'])
883+
if not sn:
884+
sn = get_shortest_api(api_info_dict[id_api]["all_names"])
846885
if sn:
847886
# Delete alias_name, api_info_dict[id_api]["alias_name"] = sn
848887
api_info_dict[id_api]["suggested_name"] = sn
@@ -1239,8 +1278,8 @@ def parse_args():
12391278
set_display_attr_of_apis()
12401279
set_source_code_attrs()
12411280
set_referenced_from_attr()
1242-
insert_suggested_names()
12431281
set_api_sketch()
1282+
insert_suggested_names()
12441283
if ('__all__' not in realattrs) or ('__all__' in realattrs and
12451284
realattr == '__all__'):
12461285
if args.gen_rst:

0 commit comments

Comments
 (0)