diff --git a/.copyright.hook b/.copyright.hook new file mode 100644 index 0000000000000000000000000000000000000000..0871ae716a7fad16dccb7f7f6164f86c2db6b242 --- /dev/null +++ b/.copyright.hook @@ -0,0 +1,121 @@ +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals + +import argparse +import io, re +import sys, os +import subprocess +import platform + +COPYRIGHT = ''' + Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +''' + +LANG_COMMENT_MARK = None + +NEW_LINE_MARK = None + +COPYRIGHT_HEADER = None + +if platform.system() == "Windows": + NEW_LINE_MARK = "\r\n" +else: + NEW_LINE_MARK = '\n' + COPYRIGHT_HEADER = COPYRIGHT.split(NEW_LINE_MARK)[1] + p = re.search('(\d{4})', COPYRIGHT_HEADER).group(0) + process = subprocess.Popen(["date", "+%Y"], stdout=subprocess.PIPE) + date, err = process.communicate() + date = date.decode("utf-8").rstrip("\n") + COPYRIGHT_HEADER = COPYRIGHT_HEADER.replace(p, date) + + +def generate_copyright(template, lang='C'): + if lang == 'Python': + LANG_COMMENT_MARK = '#' + else: + LANG_COMMENT_MARK = "//" + + lines = template.split(NEW_LINE_MARK) + BLANK = " " + ans = LANG_COMMENT_MARK + BLANK + COPYRIGHT_HEADER + NEW_LINE_MARK + for lino, line in enumerate(lines): + if lino == 0 or lino == 1 or lino == len(lines) - 1: continue + if len(line) == 0: + BLANK = "" + else: + BLANK = " " + ans += LANG_COMMENT_MARK + BLANK + line + NEW_LINE_MARK + + return ans + "\n" + + +def lang_type(filename): + if filename.endswith(".py"): + return "Python" + elif filename.endswith(".h"): + return "C" + elif filename.endswith(".c"): + return "C" + elif filename.endswith(".hpp"): + return "C" + elif filename.endswith(".cc"): + return "C" + elif filename.endswith(".cpp"): + 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: + print("Unsupported filetype %s", filename) + exit(0) + + +PYTHON_ENCODE = re.compile("^[ \t\v]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)") + + +def main(argv=None): + parser = argparse.ArgumentParser( + description='Checker for copyright declaration.') + parser.add_argument('filenames', nargs='*', help='Filenames to check') + args = parser.parse_args(argv) + + retv = 0 + for filename in args.filenames: + fd = io.open(filename, encoding="utf-8") + first_line = fd.readline() + second_line = fd.readline() + if "COPYRIGHT (C)" in first_line.upper(): continue + if first_line.startswith("#!") or PYTHON_ENCODE.match( + second_line) != None or PYTHON_ENCODE.match(first_line) != None: + continue + original_contents = io.open(filename, encoding="utf-8").read() + new_contents = generate_copyright( + COPYRIGHT, lang_type(filename)) + original_contents + print('Auto Insert Copyright Header {}'.format(filename)) + retv = 1 + with io.open(filename, 'w') as output_file: + output_file.write(new_contents) + + return retv + + +if __name__ == '__main__': + exit(main()) diff --git a/paddle_hub/commands/run.py b/paddle_hub/commands/run.py index 3712cca2700a67fba579ea5d30ca4bfed6e20b51..96984f6a1969e002906e9e8195dc68c85fbf060b 100644 --- a/paddle_hub/commands/run.py +++ b/paddle_hub/commands/run.py @@ -15,12 +15,14 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function + from paddle_hub.tools.logger import logger from paddle_hub.commands.base_command import BaseCommand, ENTRY -from paddle_hub.data.reader import csv_reader, yaml_reader +from paddle_hub.io.reader import csv_reader, yaml_reader from paddle_hub.module.manager import default_module_manager from paddle_hub.tools import utils from paddle_hub.tools.arg_helper import add_argument, print_arguments + import paddle_hub as hub import argparse import os diff --git a/paddle_hub/hub_server.py b/paddle_hub/hub_server.py index 553e8990eff8e57080eba2fafa0fd8c91425d8a7..1d8293cf25a8958262d81c29928ea85909d90953 100644 --- a/paddle_hub/hub_server.py +++ b/paddle_hub/hub_server.py @@ -17,7 +17,7 @@ from __future__ import division from __future__ import print_function from paddle_hub.tools import utils from paddle_hub.tools.downloader import default_downloader -from paddle_hub.data.reader import csv_reader +from paddle_hub.io.reader import csv_reader import os import time import paddle_hub as hub diff --git a/paddle_hub/data/__init__.py b/paddle_hub/io/__init__.py similarity index 100% rename from paddle_hub/data/__init__.py rename to paddle_hub/io/__init__.py diff --git a/paddle_hub/data/augmentation.py b/paddle_hub/io/augmentation.py similarity index 100% rename from paddle_hub/data/augmentation.py rename to paddle_hub/io/augmentation.py diff --git a/paddle_hub/data/postprocess.py b/paddle_hub/io/postprocess.py similarity index 100% rename from paddle_hub/data/postprocess.py rename to paddle_hub/io/postprocess.py diff --git a/paddle_hub/data/preprocess.py b/paddle_hub/io/preprocess.py similarity index 100% rename from paddle_hub/data/preprocess.py rename to paddle_hub/io/preprocess.py diff --git a/paddle_hub/data/reader.py b/paddle_hub/io/reader.py similarity index 100% rename from paddle_hub/data/reader.py rename to paddle_hub/io/reader.py diff --git a/paddle_hub/data/type.py b/paddle_hub/io/type.py similarity index 100% rename from paddle_hub/data/type.py rename to paddle_hub/io/type.py diff --git a/paddle_hub/module/module.py b/paddle_hub/module/module.py index 5ae672cc6290d2f1a5a0760dd84a5aeac08d9884..751a5056d054a8b7449144fae05d90eafaba667b 100644 --- a/paddle_hub/module/module.py +++ b/paddle_hub/module/module.py @@ -23,7 +23,7 @@ from paddle_hub.module import module_desc_pb2 from paddle_hub.module import check_info_pb2 from paddle_hub.module.signature import Signature, create_signature from paddle_hub.module.checker import ModuleChecker -from paddle_hub.data.reader import yaml_reader +from paddle_hub.io.reader import yaml_reader from paddle_hub import version from paddle_hub.module.base_processor import BaseProcessor from shutil import copyfile