Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeStyle][black][2.4] format the release/2.4 branch code with black #47644

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
8 changes: 4 additions & 4 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (c) 2022 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.
Expand Down Expand Up @@ -121,5 +121,5 @@
"SRCS": '*',
"DEPS": '*',
}
}
},
}
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Exclude all third-party libraries and auto-generated files globally
exclude: |
(?x)^(
patches/.+|
paddle/fluid/framework/fleet/heter_ps/cudf/.+|
paddle/fluid/distributed/ps/thirdparty/round_robin.h|
python/paddle/utils/gast/.+|
.+_py2\.py|
python/paddle/fluid/tests/unittests/npu/.+|
python/paddle/fluid/tests/unittests/mlu/.+
)$
repos:
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
rev: v1.1.14
Expand Down
4 changes: 2 additions & 2 deletions cmake/copyfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
def main():
src = sys.argv[1]
dst = sys.argv[2]
if os.path.isdir(src): #copy directory
if os.path.isdir(src): # copy directory
pathList = os.path.split(src)
dst = os.path.join(dst, pathList[-1])
if not os.path.exists(dst):
Expand All @@ -31,7 +31,7 @@ def main():
shutil.rmtree(dst)
shutil.copytree(src, dst)
print("overwritten copy directory: {0} --->>> {1}".format(src, dst))
else: #copy file, wildcard
else: # copy file, wildcard
if not os.path.exists(dst):
os.makedirs(dst)
srcFiles = glob.glob(src)
Expand Down
15 changes: 12 additions & 3 deletions cmake/make_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
out = sys.argv[2]
var = re.sub(r'[ .-]', '_', os.path.basename(res))

open(out, "w").write("const unsigned char " + var + "[] = {" + ",".join([
"0x%02x" % ord(c) for c in open(res).read()
]) + ",0};\n" + "const unsigned " + var + "_size = sizeof(" + var + ");\n")
open(out, "w").write(
"const unsigned char "
+ var
+ "[] = {"
+ ",".join(["0x%02x" % ord(c) for c in open(res).read()])
+ ",0};\n"
+ "const unsigned "
+ var
+ "_size = sizeof("
+ var
+ ");\n"
)
63 changes: 39 additions & 24 deletions paddle/fluid/eager/auto_code_generator/generate_file_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def GenerateFileStructureForFinalDygraph(eager_dir):
|- generated
| |- CMakeLists.txt
| | "add_subdirectory(forwards), add_subdirectory(backwards)"
|
|
| |- forwards
| |- "dygraph_functions.cc"
| |- "dygraph_functions.h"
Expand All @@ -41,8 +41,9 @@ def GenerateFileStructureForFinalDygraph(eager_dir):
os.mkdir(directory)

# Empty files
dygraph_forward_api_h_path = os.path.join(generated_dir,
"dygraph_functions.h")
dygraph_forward_api_h_path = os.path.join(
generated_dir, "dygraph_functions.h"
)
empty_files = [dygraph_forward_api_h_path]
empty_files.append(os.path.join(forwards_dir, "dygraph_functions.cc"))
empty_files.append(os.path.join(nodes_dir, "nodes.cc"))
Expand All @@ -59,7 +60,7 @@ def GenerateFileStructureForIntermediateDygraph(eager_dir, split_count):
|- generated
| |- CMakeLists.txt
| | "add_subdirectory(forwards), add_subdirectory(nodes)"
|
|
| |- forwards
| |- "dygraph_forward_functions.cc"
| |- CMakeLists.txt
Expand All @@ -70,7 +71,7 @@ def GenerateFileStructureForIntermediateDygraph(eager_dir, split_count):
| |- "nodes.h"
| |- CMakeLists.txt
| | "cc_library(dygraph_node SRCS nodes.cc DEPS ${eager_deps} ${fluid_deps})"
|
|
| |- dygraph_forward_api.h
"""
# Directory Generation
Expand All @@ -83,32 +84,41 @@ def GenerateFileStructureForIntermediateDygraph(eager_dir, split_count):
os.mkdir(directory)

# Empty files
dygraph_forward_api_h_path = os.path.join(generated_dir,
"dygraph_forward_api.h")
dygraph_forward_api_h_path = os.path.join(
generated_dir, "dygraph_forward_api.h"
)
empty_files = [dygraph_forward_api_h_path]
empty_files.append(os.path.join(nodes_dir, "nodes.h"))

for i in range(split_count):
empty_files.append(
os.path.join(forwards_dir,
"dygraph_forward_functions" + str(i + 1) + ".cc"))
empty_files.append(os.path.join(nodes_dir,
"nodes" + str(i + 1) + ".cc"))
os.path.join(
forwards_dir, "dygraph_forward_functions" + str(i + 1) + ".cc"
)
)
empty_files.append(
os.path.join(nodes_dir, "nodes" + str(i + 1) + ".cc")
)
empty_files.append(
os.path.join(forwards_dir, "dygraph_forward_functions_args_info.cc"))
os.path.join(forwards_dir, "dygraph_forward_functions_args_info.cc")
)
empty_files.append(
os.path.join(forwards_dir,
"dygraph_forward_functions_args_type_info.cc"))
os.path.join(
forwards_dir, "dygraph_forward_functions_args_type_info.cc"
)
)
empty_files.append(
os.path.join(forwards_dir, "dygraph_forward_functions_returns_info.cc"))
os.path.join(forwards_dir, "dygraph_forward_functions_returns_info.cc")
)
for path in empty_files:
if not os.path.exists(path):
open(path, 'a').close()

# CMakeLists
nodes_level_cmakelist_path = os.path.join(nodes_dir, "CMakeLists.txt")
generated_level_cmakelist_path = os.path.join(generated_dir,
"CMakeLists.txt")
generated_level_cmakelist_path = os.path.join(
generated_dir, "CMakeLists.txt"
)
forwards_level_cmakelist_path = os.path.join(forwards_dir, "CMakeLists.txt")

with open(nodes_level_cmakelist_path, "w") as f:
Expand All @@ -120,9 +130,11 @@ def GenerateFileStructureForIntermediateDygraph(eager_dir, split_count):
for i in range(split_count):
f.write(
" COMMAND ${CMAKE_COMMAND} -E copy_if_different \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/nodes/nodes"
+ str(i + 1) +
".tmp.cc\" \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/nodes/nodes"
+ str(i + 1) + ".cc\"\n")
+ str(i + 1)
+ ".tmp.cc\" \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/nodes/nodes"
+ str(i + 1)
+ ".cc\"\n"
)

f.write(" DEPENDS legacy_eager_codegen\n")
f.write(" VERBATIM)\n")
Expand All @@ -142,9 +154,11 @@ def GenerateFileStructureForIntermediateDygraph(eager_dir, split_count):
for i in range(split_count):
f.write(
" COMMAND ${CMAKE_COMMAND} -E copy_if_different \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/forwards/dygraph_forward_functions"
+ str(i + 1) +
".tmp.cc\" \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/forwards/dygraph_forward_functions"
+ str(i + 1) + ".cc\"\n")
+ str(i + 1)
+ ".tmp.cc\" \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/forwards/dygraph_forward_functions"
+ str(i + 1)
+ ".cc\"\n"
)
f.write(
" COMMAND ${CMAKE_COMMAND} -E copy_if_different \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/forwards/dygraph_forward_functions_args_info.tmp.cc\" \"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/fluid_generated/forwards/dygraph_forward_functions_args_info.cc\"\n"
)
Expand All @@ -167,7 +181,8 @@ def GenerateFileStructureForIntermediateDygraph(eager_dir, split_count):
"${fluid_manual_functions} DEPS ${eager_deps} ${fluid_deps} ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS})\n"
)
f.write(
"add_dependencies(dygraph_function copy_dygraph_forward_functions)")
"add_dependencies(dygraph_function copy_dygraph_forward_functions)"
)

with open(generated_level_cmakelist_path, "w") as f:
f.write("add_subdirectory(forwards)\nadd_subdirectory(nodes)")
Expand Down
Loading