Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
ad47c129
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
338
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ad47c129
编写于
5月 23, 2018
作者:
朔-望
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add copyright hook
上级
7a45bbf4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
54 addition
and
55 deletion
+54
-55
.pre-commit-config.yaml
.pre-commit-config.yaml
+15
-13
tools/pre-commit.hooks/clang-format.hook
tools/pre-commit.hooks/clang-format.hook
+0
-0
tools/pre-commit.hooks/clang-tidy.hook
tools/pre-commit.hooks/clang-tidy.hook
+0
-0
tools/pre-commit.hooks/copyright.hook
tools/pre-commit.hooks/copyright.hook
+39
-42
tools/pre-commit.hooks/cpplint.hook
tools/pre-commit.hooks/cpplint.hook
+0
-0
未找到文件。
.pre-commit-config.yaml
浏览文件 @
ad47c129
...
@@ -16,16 +16,25 @@ repos:
...
@@ -16,16 +16,25 @@ repos:
-
id
:
detect-private-key
-
id
:
detect-private-key
files
:
(?!.*tar.gz)^.*$
files
:
(?!.*tar.gz)^.*$
-
id
:
end-of-file-fixer
-
id
:
end-of-file-fixer
files
:
(src).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|
cu|
h|hpp|hxx)$
files
:
(src).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|h|hpp|hxx)$
-
id
:
trailing-whitespace
-
id
:
trailing-whitespace
files
:
(src).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
files
:
(src).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|h|hpp|hxx)$
-
repo
:
local
hooks
:
-
id
:
copyright
name
:
copyright
entry
:
python ./tools/pre-commit.hooks/copyright.hook
language
:
system
files
:
(src).*\.(c|cc|cxx|cpp|h|hpp|hxx|py)$
exclude
:
(?!.*third_party)^.*$ | (?!.*book)^.*$
-
repo
:
local
-
repo
:
local
hooks
:
hooks
:
-
id
:
clang-format
-
id
:
clang-format
name
:
clang-format
name
:
clang-format
description
:
Format files with ClangFormat.
description
:
Format files with ClangFormat.
entry
:
bash ./tools/pre-commit.hooks/
.
clang-format.hook -i
entry
:
bash ./tools/pre-commit.hooks/clang-format.hook -i
language
:
system
language
:
system
files
:
(src).*\.(c|cc|cxx|cpp|h|hpp|hxx)$
files
:
(src).*\.(c|cc|cxx|cpp|h|hpp|hxx)$
...
@@ -44,15 +53,8 @@ repos:
...
@@ -44,15 +53,8 @@ repos:
-
id
:
cpplint
-
id
:
cpplint
name
:
cpplint
name
:
cpplint
description
:
Check C++ code style using cpplint.
description
:
Check C++ code style using cpplint.
entry
:
bash ./tools/pre-commit.hooks/
.
cpplint.hook
entry
:
bash ./tools/pre-commit.hooks/cpplint.hook
language
:
system
language
:
system
files
:
(src).*\.(c|cc|cxx|cpp|
cu|
h|hpp|hxx)$
files
:
(src).*\.(c|cc|cxx|cpp|h|hpp|hxx)$
exclude
:
(?!.*third_party)^.*$ | (?!.*book)^.*$i | *\.pb\.cpp
exclude
:
(?!.*third_party)^.*$ | (?!.*book)^.*$i | *\.pb\.cpp
#- repo: local
# hooks:
# - id: copyright_checker
# name: copyright_checker
# entry: python ./tools/pre-commit.hooks/.copyright.hook
# language: system
# files: (src).*\.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto|py)$
# exclude: (?!.*third_party)^.*$ | (?!.*book)^.*$
tools/pre-commit.hooks/
.
clang-format.hook
→
tools/pre-commit.hooks/clang-format.hook
浏览文件 @
ad47c129
文件已移动
tools/pre-commit.hooks/
.
clang-tidy.hook
→
tools/pre-commit.hooks/clang-tidy.hook
浏览文件 @
ad47c129
文件已移动
tools/pre-commit.hooks/
.
copyright.hook
→
tools/pre-commit.hooks/copyright.hook
浏览文件 @
ad47c129
...
@@ -3,28 +3,22 @@ from __future__ import print_function
...
@@ -3,28 +3,22 @@ from __future__ import print_function
from __future__ import unicode_literals
from __future__ import unicode_literals
import argparse
import argparse
import io, re
import io
import sys, os
import subprocess
import platform
import platform
import re
import subprocess
COPYRIGHT = '''
COPYRIGHT = '''
Copyright (c) 2016 Baidu, Inc. All Rights Reserved.
Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
Licensed under the Apache License, Version 2.0 (the "License");
of this software and associated documentation files (the "Software"), to deal
you may not use this file except in compliance with the License.
in the Software without restriction, including without limitation the rights
You may obtain a copy of the License at
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
http://www.apache.org/licenses/LICENSE-2.0
copies of the Software, and to permit persons to whom the Software is
Unless required by applicable law or agreed to in writing, software
furnished to do so, subject to the following conditions:
distributed under the License is distributed on an "AS IS" BASIS,
The above copyright notice and this permission notice shall be included in all
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
copies or substantial portions of the Software.
See the License for the specific language governing permissions and
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
limitations under the License.
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
'''
'''
LANG_COMMENT_MARK = None
LANG_COMMENT_MARK = None
...
@@ -46,22 +40,27 @@ else:
...
@@ -46,22 +40,27 @@ else:
def generate_copyright(template, lang='C'):
def generate_copyright(template, lang='C'):
end_line = ""
if lang == 'Python':
if lang == 'Python':
LANG_COMMENT_MARK = '#'
lang_coment_mark = '# '
start = lang_coment_mark
blank = " "
else:
else:
LANG_COMMENT_MARK = "//"
lang_coment_mark = ""
start = "/* "
blank = ""
end_line = " */"
lines = template.split(NEW_LINE_MARK)
lines = template.split(NEW_LINE_MARK)
BLANK = " "
ans = LANG_COMMENT_MARK + BLANK + COPYRIGHT_HEADER + NEW_LINE_MARK
ans = start + blank + COPYRIGHT_HEADER + NEW_LINE_MARK
for lino, line in enumerate(lines):
for lino, line in enumerate(lines):
if lino == 0 or lino == 1 or lino == len(lines) - 1: continue
if lino == 0 or lino == 1 or lino == len(lines) - 1:
if len(line) == 0:
continue
BLANK = ""
if lino == (len(lines) - 2):
ans += lang_coment_mark + blank + line + end_line + NEW_LINE_MARK
else:
else:
BLANK = " "
ans += lang_coment_mark + blank + line + NEW_LINE_MARK
ans += LANG_COMMENT_MARK + BLANK + line + NEW_LINE_MARK
return ans + "\n"
return ans + "\n"
...
@@ -78,14 +77,6 @@ def lang_type(filename):
...
@@ -78,14 +77,6 @@ def lang_type(filename):
return "C"
return "C"
elif filename.endswith(".cpp"):
elif filename.endswith(".cpp"):
return "C"
return "C"
elif filename.endswith(".cu"):
return "C"
elif filename.endswith(".cuh"):
return "C"
elif filename.endswith(".go"):
return "C"
elif filename.endswith(".proto"):
return "C"
else:
else:
print("Unsupported filetype %s", filename)
print("Unsupported filetype %s", filename)
exit(0)
exit(0)
...
@@ -105,9 +96,10 @@ def main(argv=None):
...
@@ -105,9 +96,10 @@ def main(argv=None):
fd = io.open(filename, encoding="utf-8")
fd = io.open(filename, encoding="utf-8")
first_line = fd.readline()
first_line = fd.readline()
second_line = fd.readline()
second_line = fd.readline()
if "COPYRIGHT (C)" in first_line.upper(): continue
if "COPYRIGHT (C)" in first_line.upper() or "COPYRIGHT (C)" in second_line.upper():
if first_line.startswith("#!") or PYTHON_ENCODE.match(
continue
second_line) != None or PYTHON_ENCODE.match(first_line) != None:
if first_line.startswith("/*") or first_line.startswith("#!") or PYTHON_ENCODE.match(
second_line) is not None or PYTHON_ENCODE.match(first_line) is not None:
continue
continue
original_contents = io.open(filename, encoding="utf-8").read()
original_contents = io.open(filename, encoding="utf-8").read()
new_contents = generate_copyright(
new_contents = generate_copyright(
...
@@ -116,9 +108,14 @@ def main(argv=None):
...
@@ -116,9 +108,14 @@ def main(argv=None):
retv = 1
retv = 1
with io.open(filename, 'w') as output_file:
with io.open(filename, 'w') as output_file:
output_file.write(new_contents)
output_file.write(new_contents)
return retv
return retv
def test_generate_copyright():
print(generate_copyright(COPYRIGHT))
if __name__ == '__main__':
if __name__ == '__main__':
# test_generate_copyright()
exit(main())
exit(main())
tools/pre-commit.hooks/
.
cpplint.hook
→
tools/pre-commit.hooks/cpplint.hook
浏览文件 @
ad47c129
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录