Skip to content

Commit

Permalink
[Feature](bangc-ops):add file name format check (Cambricon#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
defei-coder authored Jun 8, 2023
1 parent 3898ef3 commit 6e5959f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tools/check_file_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/python3
# Copyright (C) [2023] by Cambricon, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall self.tcp included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR 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 self.tcp 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.
# pylint: disable=invalid-name, missing-class-docstring, missing-function-docstring
# pylint: disable=attribute-defined-outside-init

import os
import sys

def filename_check(dir):
for root, dirs, _ in os.walk(dir):
for dir in dirs:
file_name = []
for _, _, files in os.walk(os.path.join(root, dir)):
for file in files:
if file.endswith(".mlu") or file.endswith(".cpp"):
name = file.split('.')[0]
if name in file_name:
print('-- [check_file_name error] find %s.cpp and %s.mlu in directory %s,'\
%(name, name, os.path.join(root, dir)), 'the same name is forbidden.' )
exit(-1)
file_name.append(name)


def main():
dir_path = sys.argv[1]
filename_check(dir_path)


if __name__ == "__main__":
main()
8 changes: 8 additions & 0 deletions tools/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ bangc_check_list=${bangc_ops}
bangpy_check_list=${bangpy_ops}

bangc_mlu_op_h="bangc-ops/mlu_op.h"
bangc_kernels_dir='bangc-ops/kernels/'
bangc_gtest_json_file="jsoncppDist/"

bangc_exclude_list=${bangc_gtest_json_file}
Expand Down Expand Up @@ -150,6 +151,13 @@ for i in $filenames; do
python tools/check_log_error.py $i
done

echo "-- [check_file_name] Using tools/check_file_name.py to check the file_name"
python tools/check_file_name.py ${bangc_kernels_dir}

if [[ $? -ne 0 ]]; then
exit 1
fi

if [[ $# -eq 1 ]]; then
bangpy_filenames=$(git diff --name-only ${1} \
| grep -E ${bangpy_check_list})
Expand Down

0 comments on commit 6e5959f

Please sign in to comment.