Skip to content

Commit

Permalink
merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Asthestarsfalll committed Mar 26, 2024
2 parents 5c8edd4 + 75d9e6a commit 0417f1a
Show file tree
Hide file tree
Showing 1,323 changed files with 23,495 additions and 12,815 deletions.
18 changes: 11 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# IDE settings
*.DS_Store
.vscode/
/doc/fluid/menu.zh.json
/doc/fluid/menu.en.json
.idea
build
.vscode
output/
.idea

# virtualenv
venv/
ENV/

# Compiled Python files
__pycache__/

*.pyc
# Build and output directories
build
output/
24 changes: 4 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,12 @@ repos:
hooks:
- id: insert-whitespace-between-cn-and-en-char
files: \.md$|\.rst$
- repo: https://github.com/reyoung/pre-commit-hooks-jinja-compile.git
rev: 4a369cc72a4a2b8d3813ab8cc17abb5f5b21ef6c
hooks:
- id: convert-jinja2-into-html
# The argument means repleace filename from pattern `.*/([^/]*)\.tmpl` to `\1`
args: ['--filename_pattern=.*/([^/]*)\.tmpl', '--filename_repl=\1']
- repo: local
hooks:
- id: convert-markdown-into-html
name: convert-markdown-into-html
description: Convert README.md into index.html and README.cn.md into index.cn.html
entry: python .pre-commit-hooks/convert_markdown_into_html.py
language: system
files: .+README(\.cn)?\.md$
# For Python files
- repo: https://github.com/psf/black.git
rev: 23.3.0
hooks:
- id: black
files: \.py$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.5
rev: v0.3.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --no-cache]
types_or: [ python, pyi ]
- id: ruff-format
types_or: [ python, pyi, jupyter ]
95 changes: 0 additions & 95 deletions .pre-commit-hooks/convert_markdown_into_html.py

This file was deleted.

8 changes: 0 additions & 8 deletions .pre-commit-hooks/convert_markdown_into_ipynb.sh

This file was deleted.

30 changes: 15 additions & 15 deletions ci_scripts/CAPItools/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# 解析所有的函数, 类, 枚举, 返回一个字典
# 多线程使用并不安全, 请不要使用多线程
def analysis_file(path):
header = CppHeaderParser.CppHeader(path, encoding='utf8')
header = CppHeaderParser.CppHeader(path, encoding="utf8")
data = json.loads(header.toJSON())
return data

Expand All @@ -36,8 +36,8 @@ def generate_docs(
func_name = item["name"].replace("/", "")

# Note: 操作符仅不生成rst,实际上在Overview列表依然会呈现以提示存在此操作符
if func_name.startswith('operator'):
checkwords = func_name.replace('operator', '', 1)
if func_name.startswith("operator"):
checkwords = func_name.replace("operator", "", 1)
if re.search(r"\w", checkwords) is None:
continue # 跳过操作符声明
rst_dir = os.path.join(save_dir, LANGUAGE, path, func_name + ".rst")
Expand All @@ -47,7 +47,7 @@ def generate_docs(
helper.create_and_write_file(rst_dir, LANGUAGE)
except:
print(traceback.format_exc())
print('FAULT GENERATE:' + rst_dir)
print("FAULT GENERATE:" + rst_dir)

for item in all_class:
path = item["filename"].replace("../", "").replace(".h", "")
Expand All @@ -62,7 +62,7 @@ def generate_docs(
helper.create_and_write_file(rst_dir, LANGUAGE)
except:
print(traceback.format_exc())
print('FAULT GENERATE:' + rst_dir)
print("FAULT GENERATE:" + rst_dir)


# cpp 对应 python api
Expand All @@ -80,13 +80,13 @@ def cpp2py(data: dict):
# 2. 提取待生成文档的PADDLE_API list
# 3. 生成文档
if __name__ == "__main__":
root_dir = ''
save_dir = '.' # 默认保存在当前目录
root_dir = ""
save_dir = "." # 默认保存在当前目录
if len(sys.argv) == 3:
root_dir = sys.argv[1]
save_dir = sys.argv[2]

if root_dir == '':
if root_dir == "":
try:
import inspect

Expand All @@ -95,8 +95,8 @@ def cpp2py(data: dict):
root_dir = os.path.dirname(inspect.getsourcefile(paddle))
except:
# for simple run
root_dir = '../paddle'
save_dir = '.' # 默认保存在当前目录
root_dir = "../paddle"
save_dir = "." # 默认保存在当前目录

all_funcs = []
all_class = []
Expand All @@ -115,8 +115,8 @@ def cpp2py(data: dict):
cpp2py_api_list = cpp2py(cpp2py_data).copy()

# 跳过文件中未包含PADDLE_API
with open(file_path, encoding='utf-8') as f:
if 'PADDLE_API ' not in f.read():
with open(file_path, encoding="utf-8") as f:
if "PADDLE_API " not in f.read():
continue

print("Parsing: ", file_path)
Expand All @@ -131,9 +131,9 @@ def cpp2py(data: dict):
all_class.extend(current_class)
overview_list.append(
{
'h_file': file_path,
'class': current_class,
'function': current_func,
"h_file": file_path,
"class": current_class,
"function": current_func,
}
)

Expand Down
52 changes: 26 additions & 26 deletions ci_scripts/CAPItools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def get_PADDLE_API_func(data: dict):
result = []
for i in data["functions"]:
if 'PADDLE_API' in i['debug']:
if "PADDLE_API" in i["debug"]:
result.append(i)
return result

Expand Down Expand Up @@ -32,7 +32,7 @@ def get_parameters(parameters):
# parameter_api = "" # 这里解析是给api使用的 (暂时不用)
parameter_dict = {}
for i in parameters:
parameter_type_tmp = i['type'].replace(" &", "").replace(" *", "")
parameter_type_tmp = i["type"].replace(" &", "").replace(" *", "")
# * 和 & 情况
# parameter_api += parameter_type_tmp

Expand All @@ -41,18 +41,18 @@ def get_parameters(parameters):
if i["pointer"] == 1:
# parameter_api += "*"
parameter_type_tmp += "*"
if i["constant"] == 1 and not parameter_type_tmp.startswith('const'):
if i["constant"] == 1 and not parameter_type_tmp.startswith("const"):
parameter_type_tmp = "const " + parameter_type_tmp
# parameter_api += f" {i['name']}, "
desc = i.get('desc', '').replace(' ', '')
desc = i.get("desc", "").replace(" ", "")

# special progress for none parameter name case
if i['name'] == '&':
if i["name"] == "&":
continue
else:
parameter_dict[i['name']] = {
'type': parameter_type_tmp,
'intro': desc,
parameter_dict[i["name"]] = {
"type": parameter_type_tmp,
"intro": desc,
}
# parameter += f"\t- **{i['name']}** ({parameter_type_tmp}) - {desc}\n"
# 去掉末尾的逗号
Expand All @@ -67,27 +67,27 @@ def get_parameters(parameters):
# 解析后分别将对应关键字后的内容放入字典对应关键字后
def parse_doxygen(doxygen):
doxygen_dict = {
'intro': '',
'returns': '',
'param_intro': {},
'note': '',
"intro": "",
"returns": "",
"param_intro": {},
"note": "",
}

if '@' in doxygen:
doxygen = doxygen[doxygen.find('@') :]
for doxygen_part in doxygen.split('@'):
if doxygen_part.startswith('brief '):
doxygen_dict['intro'] = doxygen_part.replace('brief ', '', 1)
elif doxygen_part.startswith('return '):
doxygen_dict['returns'] = doxygen_part.replace('return ', '', 1)
elif doxygen_part.startswith('param '):
param_intro = doxygen_part.replace('param ', '', 1)
param_name = param_intro[: param_intro.find(' ')]
doxygen_dict['param_intro'][param_name] = param_intro[
param_intro.find(' ') + 1 :
if "@" in doxygen:
doxygen = doxygen[doxygen.find("@") :]
for doxygen_part in doxygen.split("@"):
if doxygen_part.startswith("brief "):
doxygen_dict["intro"] = doxygen_part.replace("brief ", "", 1)
elif doxygen_part.startswith("return "):
doxygen_dict["returns"] = doxygen_part.replace("return ", "", 1)
elif doxygen_part.startswith("param "):
param_intro = doxygen_part.replace("param ", "", 1)
param_name = param_intro[: param_intro.find(" ")]
doxygen_dict["param_intro"][param_name] = param_intro[
param_intro.find(" ") + 1 :
]
elif doxygen_part.startswith('note '):
doxygen_dict['note'] = doxygen_part.replace('note ', '', 1)
elif doxygen_part.startswith("note "):
doxygen_dict["note"] = doxygen_part.replace("note ", "", 1)
else:
pass

Expand Down
Loading

0 comments on commit 0417f1a

Please sign in to comment.