Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
597897e3
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
597897e3
编写于
12月 02, 2020
作者:
C
chalsliu
提交者:
GitHub
12月 02, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Supprot precision test for code analysis
上级
a37963b8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
127 addition
and
10 deletion
+127
-10
tools/get_pr_ut.py
tools/get_pr_ut.py
+127
-10
未找到文件。
tools/get_pr_ut.py
浏览文件 @
597897e3
...
...
@@ -15,6 +15,9 @@
import
os
import
json
import
re
import
sys
import
requests
from
github
import
Github
PADDLE_ROOT
=
os
.
getenv
(
'PADDLE_ROOT'
,
'/paddle/'
)
...
...
@@ -26,7 +29,14 @@ class PRChecker(object):
def
__init__
(
self
):
self
.
github
=
Github
(
os
.
getenv
(
'GITHUB_API_TOKEN'
),
timeout
=
60
)
self
.
repo
=
self
.
github
.
get_repo
(
'PaddlePaddle/Paddle'
)
self
.
py_prog_oneline
=
re
.
compile
(
'\d+\|\s*#.*'
)
self
.
py_prog_multiline_a
=
re
.
compile
(
'\d+\|\s*""".*?"""'
,
re
.
DOTALL
)
self
.
py_prog_multiline_b
=
re
.
compile
(
"\d+\|\s*'''.*?'''"
,
re
.
DOTALL
)
self
.
cc_prog_online
=
re
.
compile
(
'\d+\|\s*//.*'
)
self
.
cc_prog_multiline
=
re
.
compile
(
'\d+\|\s*/\*.*?\*/'
,
re
.
DOTALL
)
self
.
lineno_prog
=
re
.
compile
(
'@@ \-\d+,\d+ \+(\d+),(\d+) @@'
)
self
.
pr
=
None
self
.
suffix
=
''
def
init
(
self
):
""" Get pull request. """
...
...
@@ -34,6 +44,9 @@ class PRChecker(object):
if
not
pr_id
:
print
(
'No PR ID'
)
exit
(
0
)
suffix
=
os
.
getenv
(
'PREC_SUFFIX'
)
if
suffix
:
self
.
suffix
=
suffix
self
.
pr
=
self
.
repo
.
get_pull
(
int
(
pr_id
))
def
get_pr_files
(
self
):
...
...
@@ -49,30 +62,134 @@ class PRChecker(object):
page
+=
1
return
file_list
def
__get_comment_by_filetype
(
self
,
content
,
filetype
):
result
=
[]
if
filetype
==
'py'
:
result
=
self
.
__get_comment_by_prog
(
content
,
self
.
py_prog_oneline
)
result
.
extend
(
self
.
__get_comment_by_prog
(
content
,
self
.
py_prog_multiline_a
))
result
.
extend
(
self
.
__get_comment_by_prog
(
content
,
self
.
py_prog_multiline_b
))
if
filetype
==
'cc'
:
result
=
self
.
__get_comment_by_prog
(
content
,
self
.
cc_prog_oneline
)
result
.
extend
(
self
.
__get_comment_by_prog
(
content
,
self
.
cc_prog_multiline
))
return
result
def
__get_comment_by_prog
(
self
,
content
,
prog
):
result
=
[]
result_list
=
prog
.
findall
(
content
)
if
not
result_list
:
return
None
for
u
in
result_list
:
result
.
extend
(
u
.
split
(
'
\n
'
))
return
result
def
get_comment_of_file
(
self
,
f
):
#content = self.repo.get_contents(f.replace(PADDLE_ROOT, ''), 'pull/').decoded_content
with
open
(
f
)
as
fd
:
lines
=
fd
.
readlines
()
lineno
=
1
inputs
=
''
for
line
in
lines
:
#for line in content.split('\n'):
#input += str(lineno) + '|' + line + '\n'
inputs
+=
str
(
lineno
)
+
'|'
+
line
lineno
+=
1
fietype
=
''
if
f
.
endswith
(
'.h'
)
or
f
.
endswith
(
'.cc'
)
or
f
.
endswith
(
'.cu'
):
filetype
=
'cc'
if
f
.
endswith
(
'.py'
):
filetype
=
'py'
else
:
return
None
return
self
.
__get_comment_by_filetype
(
inputs
,
filetype
)
def
get_pr_diff_lines
(
self
):
file_to_diff_lines
=
{}
r
=
requests
.
get
(
self
.
pr
.
diff_url
)
data
=
r
.
text
data
=
data
.
split
(
'
\n
'
)
ix
=
0
while
ix
<
len
(
data
):
if
data
[
ix
].
startswith
(
'+++'
):
if
data
[
ix
].
rstrip
(
'
\r\n
'
)
==
'+++ /dev/null'
:
ix
+=
1
continue
filename
=
data
[
ix
][
6
:]
ix
+=
1
while
ix
<
len
(
data
):
result
=
self
.
lineno_prog
.
match
(
data
[
ix
])
if
not
result
:
break
lineno
=
int
(
result
.
group
(
1
))
length
=
int
(
result
.
group
(
2
))
ix
+=
1
end
=
ix
+
length
while
ix
<
end
:
if
data
[
ix
][
0
]
==
'-'
:
end
+=
1
if
data
[
ix
][
0
]
==
'+'
:
line_list
=
file_to_diff_lines
.
get
(
filename
)
line
=
'{}{}'
.
format
(
lineno
,
data
[
ix
].
replace
(
'+'
,
'|'
))
if
line_list
:
line_list
.
append
(
line
)
else
:
file_to_diff_lines
[
filename
]
=
[
line
,
]
if
data
[
ix
][
0
]
!=
'-'
:
lineno
+=
1
ix
+=
1
ix
+=
1
return
file_to_diff_lines
def
is_only_comment
(
self
,
f
):
file_to_diff_lines
=
self
.
get_pr_diff_lines
()
comment_lines
=
self
.
get_comment_of_file
(
f
)
#for l in comment_lines:
# print(l)
diff_lines
=
file_to_diff_lines
.
get
(
f
.
replace
(
PADDLE_ROOT
,
''
))
for
l
in
diff_lines
:
if
l
not
in
comment_lines
:
return
False
return
True
def
get_pr_ut
(
self
):
""" Get unit tests in pull request. """
check_added_ut
=
False
ut_list
=
[]
file_ut_map
=
None
cmd
=
'wget -q --no-check-certificate https://sys-p0.bj.bcebos.com/prec/file_ut.json'
cmd
=
'wget -q --no-check-certificate https://sys-p0.bj.bcebos.com/prec/file_ut.json'
+
self
.
suffix
os
.
system
(
cmd
)
with
open
(
'file_ut.json'
)
as
jsonfile
:
with
open
(
'file_ut.json'
+
self
.
suffix
)
as
jsonfile
:
file_ut_map
=
json
.
load
(
jsonfile
)
for
f
in
self
.
get_pr_files
():
if
f
.
endswith
(
'.h'
)
or
f
.
endswith
(
'.cu'
):
return
''
if
f
not
in
file_ut_map
:
if
f
.
find
(
'test_'
)
!=
-
1
or
f
.
find
(
'_test'
)
!=
-
1
:
check_added_ut
=
True
continue
if
f
.
endswith
(
'.md'
):
ut_list
.
append
(
'md_placeholder'
)
elif
f
.
endswith
(
'.h'
)
or
f
.
endswith
(
'.cu'
):
if
self
.
is_only_comment
(
f
):
ut_list
.
append
(
'h_cu_comment_placeholder'
)
else
:
return
''
elif
f
.
endswith
(
'.cc'
):
if
f
.
find
(
'test_'
)
!=
-
1
or
f
.
find
(
'_test'
)
!=
-
1
:
check_added_ut
=
True
elif
self
.
is_only_comment
(
f
):
ut_list
.
append
(
'cc_comment_placeholder'
)
else
:
return
''
else
:
return
''
else
:
ut_list
.
extend
(
file_ut_map
.
get
(
f
))
if
self
.
is_only_comment
(
f
):
ut_list
.
append
(
'cc_comment_placeholder'
)
else
:
ut_list
.
extend
(
file_ut_map
.
get
(
f
))
ut_list
=
list
(
set
(
ut_list
))
cmd
=
'wget -q --no-check-certificate https://sys-p0.bj.bcebos.com/prec/prec_delta'
cmd
=
'wget -q --no-check-certificate https://sys-p0.bj.bcebos.com/prec/prec_delta'
+
self
.
suffix
os
.
system
(
cmd
)
with
open
(
'prec_delta'
)
as
delta
:
with
open
(
'prec_delta'
+
self
.
suffix
)
as
delta
:
for
ut
in
delta
:
ut_list
.
append
(
ut
.
rstrip
(
'
\r\n
'
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录