Skip to content

Commit c871036

Browse files
authored
merge plsc to passl (#140)
* merge plsc to passl * update requirements.txt * update install * remove * add data folder * add dataset folder * update ci install
1 parent 9d7a9fd commit c871036

File tree

342 files changed

+27549
-373
lines changed

Some content is hidden

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

342 files changed

+27549
-373
lines changed

.gitignore

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ __pycache__/
44
*$py.class
55

66
# C extensions
7+
*.so
78

89
# Distribution / packaging
910
.Python
11+
env/
1012
build/
1113
develop-eggs/
1214
dist/
@@ -22,7 +24,6 @@ wheels/
2224
*.egg-info/
2325
.installed.cfg
2426
*.egg
25-
MANIFEST
2627

2728
# PyInstaller
2829
# Usually these files are written by a python script from a template
@@ -44,7 +45,6 @@ nosetests.xml
4445
coverage.xml
4546
*.cover
4647
.hypothesis/
47-
.pytest_cache/
4848

4949
# Translations
5050
*.mo
@@ -53,7 +53,6 @@ coverage.xml
5353
# Django stuff:
5454
*.log
5555
local_settings.py
56-
db.sqlite3
5756

5857
# Flask stuff:
5958
instance/
@@ -80,14 +79,13 @@ celerybeat-schedule
8079
# SageMath parsed files
8180
*.sage.py
8281

83-
# Environments
82+
# dotenv
8483
.env
84+
85+
# virtualenv
8586
.venv
86-
env/
8787
venv/
8888
ENV/
89-
env.bak/
90-
venv.bak/
9189

9290
# Spyder project settings
9391
.spyderproject
@@ -102,6 +100,8 @@ venv.bak/
102100
# mypy
103101
.mypy_cache/
104102

105-
# data
106-
data/
107-
output_dir/
103+
.DS_Store
104+
105+
# logs and output
106+
**/output/
107+
**/log/

.pre-commit-config.yaml

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,65 @@
11
repos:
2-
- repo: https://github.com/PaddlePaddle/mirrors-yapf.git
3-
rev: 0d79c0c469bab64f7229c9aca2b1186ef47f0e37
2+
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
3+
rev: v1.1.14
44
hooks:
5-
- id: yapf
6-
files: \.py$
5+
- id: remove-crlf
6+
- id: remove-tabs
7+
name: Tabs remover (C++)
8+
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps)$
9+
args: [--whitespaces-count, '2']
10+
- id: remove-tabs
11+
name: Tabs remover (Python)
12+
files: (.*\.(py|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
13+
args: [--whitespaces-count, '4']
14+
# Exclude the fluid directory but keep the fluid/tests directory.
15+
# And exclude some unit test files that require tabs.
16+
exclude: |
17+
(?x)^(
18+
python/paddle/fluid/(?!tests).+|
19+
python/paddle/fluid/tests/unittests/collective/fleet/test_hdfs1.py|
20+
python/paddle/fluid/tests/unittests/dygraph_to_static/test_error.py
21+
)$
722
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: a11d9314b22d8f8c7556443875b731ef05965464
23+
rev: v4.1.0
924
hooks:
25+
- id: check-added-large-files
1026
- id: check-merge-conflict
1127
- id: check-symlinks
1228
- id: detect-private-key
13-
files: (?!.*paddle)^.*$
1429
- id: end-of-file-fixer
15-
files: \.md$
30+
- id: sort-simple-yaml
31+
files: (ops|backward|op_[a-z_]+)\.yaml$
1632
- id: trailing-whitespace
17-
files: \.md$
18-
- repo: https://github.com/Lucas-C/pre-commit-hooks
19-
rev: v1.0.1
20-
hooks:
21-
- id: forbid-crlf
22-
files: \.md$
23-
- id: remove-crlf
24-
files: \.md$
25-
- id: forbid-tabs
26-
files: \.md$
27-
- id: remove-tabs
28-
files: \.md$
33+
files: (.*\.(py|bzl|md|rst|c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps|cmake|yaml|yml|hook)|BUILD|.*\.BUILD|WORKSPACE|CMakeLists\.txt)$
2934
- repo: local
3035
hooks:
31-
- id: clang-format
36+
- id: clang-format-with-version-check
3237
name: clang-format
33-
description: Format files with ClangFormat
34-
entry: bash .clang_format.hook -i
38+
description: Format files with ClangFormat.
39+
entry: bash ./codestyle/clang_format.hook -i
40+
language: system
41+
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto)$
42+
- repo: local
43+
hooks:
44+
- id: cpplint-cpp-source
45+
name: cpplint
46+
description: Check C++ code style using cpplint.py.
47+
entry: bash ./codestyle/cpplint_pre_commit.hook
48+
language: system
49+
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx)$
50+
- repo: local
51+
hooks:
52+
- id: pylint-doc-string
53+
name: pylint
54+
description: Check python docstring style using docstring_checker.
55+
entry: bash ./codestyle/pylint_pre_commit.hook
56+
language: system
57+
files: \.(py)$
58+
- repo: local
59+
hooks:
60+
- id: copyright_checker
61+
name: copyright_checker
62+
entry: python ./codestyle/copyright.hook
3563
language: system
36-
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|cuh|proto)$
64+
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto|py|sh)$
65+
exclude: (?!.*third_party)^.*$ | (?!.*book)^.*$

codestyle/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pyc

codestyle/clang_format.hook

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -e
3+
4+
readonly VERSION="13.0.0"
5+
6+
version=$(clang-format -version)
7+
8+
if ! [[ $(python -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1$2}') -ge 36 ]]; then
9+
echo "clang-format installation by pip need python version great equal 3.6,
10+
please change the default python to higher version."
11+
exit 1
12+
fi
13+
14+
if ! [[ $version == *"$VERSION"* ]]; then
15+
# low version of pip may not have the source of clang-format whl
16+
pip install --upgrade pip
17+
pip install clang-format==13.0.0
18+
fi
19+
20+
clang-format $@

codestyle/copyright.hook

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import absolute_import
16+
from __future__ import print_function
17+
from __future__ import unicode_literals
18+
19+
import argparse
20+
import io
21+
import re
22+
import sys
23+
import os
24+
import datetime
25+
26+
COPYRIGHT = '''Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
27+
28+
Licensed under the Apache License, Version 2.0 (the "License");
29+
you may not use this file except in compliance with the License.
30+
You may obtain a copy of the License at
31+
32+
http://www.apache.org/licenses/LICENSE-2.0
33+
34+
Unless required by applicable law or agreed to in writing, software
35+
distributed under the License is distributed on an "AS IS" BASIS,
36+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37+
See the License for the specific language governing permissions and
38+
limitations under the License.'''
39+
40+
def _generate_copyright(comment_mark):
41+
copyright=COPYRIGHT.split(os.linesep)
42+
header = copyright[0].rstrip()
43+
44+
p = re.search('(\d{4})', header).group(0)
45+
now = datetime.datetime.now()
46+
47+
header = header.replace(p,str(now.year))
48+
49+
ans=[comment_mark + " " + header + os.linesep]
50+
for idx, line in enumerate(copyright[1:]):
51+
ans.append(comment_mark + " " + line.rstrip() + os.linesep)
52+
53+
return ans
54+
55+
def _get_comment_mark(path):
56+
lang_type=re.compile(r"\.(py|sh)$")
57+
if lang_type.search(path) is not None:
58+
return "#"
59+
60+
lang_type=re.compile(r"\.(h|c|hpp|cc|cpp|cu|go|cuh|proto)$")
61+
if lang_type.search(path) is not None:
62+
return "//"
63+
64+
return None
65+
66+
67+
RE_ENCODE = re.compile(r"^[ \t\v]*#.*?coding[:=]", re.IGNORECASE)
68+
RE_COPYRIGHT = re.compile(r".*Copyright \(c\) \d{4}", re.IGNORECASE)
69+
RE_SHEBANG = re.compile(r"^[ \t\v]*#[ \t]?\!")
70+
71+
def _check_copyright(path):
72+
head=[]
73+
try:
74+
with open(path) as f:
75+
head = [next(f) for x in range(4)]
76+
except StopIteration:
77+
pass
78+
79+
for idx, line in enumerate(head):
80+
if RE_COPYRIGHT.search(line) is not None:
81+
return True
82+
83+
return False
84+
85+
def generate_copyright(path, comment_mark):
86+
original_contents = io.open(path, encoding="utf-8").readlines()
87+
head = original_contents[0:4]
88+
89+
insert_line_no=0
90+
for i, line in enumerate(head):
91+
if RE_ENCODE.search(line) or RE_SHEBANG.search(line):
92+
insert_line_no=i+1
93+
94+
copyright = _generate_copyright(comment_mark)
95+
if insert_line_no == 0:
96+
new_contents = copyright
97+
if len(original_contents) > 0 and len(original_contents[0].strip()) != 0:
98+
new_contents.append(os.linesep)
99+
new_contents.extend(original_contents)
100+
else:
101+
new_contents=original_contents[0:insert_line_no]
102+
new_contents.append(os.linesep)
103+
new_contents.extend(copyright)
104+
if len(original_contents) > insert_line_no and len(original_contents[insert_line_no].strip()) != 0:
105+
new_contents.append(os.linesep)
106+
new_contents.extend(original_contents[insert_line_no:])
107+
new_contents="".join(new_contents)
108+
109+
with io.open(path, 'w') as output_file:
110+
output_file.write(new_contents)
111+
112+
113+
114+
def main(argv=None):
115+
parser = argparse.ArgumentParser(
116+
description='Checker for copyright declaration.')
117+
parser.add_argument('filenames', nargs='*', help='Filenames to check')
118+
args = parser.parse_args(argv)
119+
120+
retv = 0
121+
for path in args.filenames:
122+
comment_mark = _get_comment_mark(path)
123+
if comment_mark is None:
124+
print("warning:Unsupported file", path, file=sys.stderr)
125+
continue
126+
127+
if _check_copyright(path):
128+
continue
129+
130+
generate_copyright(path, comment_mark)
131+
132+
133+
if __name__ == '__main__':
134+
exit(main())

codestyle/cpplint_pre_commit.hook

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
TOTAL_ERRORS=0
4+
5+
readonly VERSION="1.6.0"
6+
7+
version=$(cpplint --version)
8+
9+
if [[ ! $TRAVIS_BRANCH ]]; then
10+
# install cpplint on local machine.
11+
if ! [[ $version == *"$VERSION"* ]]; then
12+
pip install cpplint==1.6.0
13+
fi
14+
# diff files on local machine.
15+
files=$(git diff --cached --name-status | awk '$1 != "D" {print $2}')
16+
else
17+
# diff files between PR and latest commit on Travis CI.
18+
branch_ref=$(git rev-parse "$TRAVIS_BRANCH")
19+
head_ref=$(git rev-parse HEAD)
20+
files=$(git diff --name-status $branch_ref $head_ref | awk '$1 != "D" {print $2}')
21+
fi
22+
# The trick to remove deleted files: https://stackoverflow.com/a/2413151
23+
for file in $files; do
24+
if [[ $file =~ ^(patches/.*) ]]; then
25+
continue;
26+
else
27+
cpplint --filter=-readability/fn_size,-build/include_what_you_use,-build/c++11,-whitespace/parens $file;
28+
TOTAL_ERRORS=$(expr $TOTAL_ERRORS + $?);
29+
fi
30+
done
31+
32+
exit $TOTAL_ERRORS

0 commit comments

Comments
 (0)