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] use black instead of yapf #46014

Merged
merged 4 commits into from
Oct 23, 2022
Merged
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.
2 changes: 1 addition & 1 deletion .cmake-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,5 @@
"SRCS": '*',
"DEPS": '*',
}
}
},
}
14 changes: 10 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ repos:
python/paddle/fluid/tests/unittests/collective/fleet/test_hdfs1.py|
python/paddle/fluid/tests/unittests/dygraph_to_static/test_error.py
)$
- repo: https://github.com/google/yapf
rev: v0.32.0
- repo: https://github.com/psf/black.git
rev: 22.8.0
hooks:
- id: yapf
files: (.*\.(py|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
- id: black
files: (.*\.(py|pyi|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
# Temporary exclude, will be formatted in a separate PR
exclude: |
(?x)^(
python/paddle/fluid/tests/unittests/dygraph_to_static/test_error.py|
python/paddle/fluid/tests/unittests/dygraph_to_static/test_origin_info.py
)$
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
Expand Down
3 changes: 0 additions & 3 deletions .style.yapf

This file was deleted.

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
16 changes: 12 additions & 4 deletions cmake/make_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +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"
)
57 changes: 36 additions & 21 deletions paddle/fluid/eager/auto_code_generator/generate_file_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down Expand Up @@ -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