Skip to content

Commit

Permalink
[CodeStyle] Bump ruff to 0.3.3, and update codestyle docs (PaddlePadd…
Browse files Browse the repository at this point in the history
  • Loading branch information
SigureMo authored Mar 17, 2024
1 parent 15da7ea commit ab68ebb
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repos:
files: \.md$|\.rst$
# For Python files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.0
rev: v0.3.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --no-cache]
Expand Down
1 change: 1 addition & 0 deletions ci_scripts/hooks/post_filter_htmls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""
do sth. after the html generated.
"""

import argparse
import os
import sys
Expand Down
1 change: 1 addition & 0 deletions docs/api/copy_codes_from_en_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
copy code-blocks from en api doc-strings.
"""

import argparse
import inspect
import json
Expand Down
5 changes: 1 addition & 4 deletions docs/api/gen_alias_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ def _find_real_api_by_grep_file(self, api_list):
elif inspect.isfunction(obj):
reg = "def %s(" % api.split(".")[-1]

shell_cmd = "find {} -name '*.py' | xargs grep \"{}\" ".format(
self.paddle_root_path,
reg,
)
shell_cmd = f"find {self.paddle_root_path} -name '*.py' | xargs grep \"{reg}\" "

p = subprocess.Popen(
shell_cmd, shell=True, stdout=subprocess.PIPE, stderr=None
Expand Down
30 changes: 15 additions & 15 deletions docs/api/gen_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,30 +306,30 @@ def parse_module_file(mod):
api_info_dict[obj_id]["src_file"] = src_file[
src_file_start_ind:
]
api_info_dict[obj_id][
"doc_filename"
] = obj_full_name.replace(".", "/")
api_info_dict[obj_id]["doc_filename"] = (
obj_full_name.replace(".", "/")
)
api_info_dict[obj_id]["full_name"] = obj_full_name
api_info_dict[obj_id]["short_name"] = short_name
api_info_dict[obj_id]["module_name"] = mod_name
api_info_dict[obj_id]["lineno"] = node.lineno
if has_end_lineno:
api_info_dict[obj_id][
"end_lineno"
] = node.end_lineno
api_info_dict[obj_id]["end_lineno"] = (
node.end_lineno
)
if isinstance(node, ast.FunctionDef):
api_info_dict[obj_id][
"args"
] = gen_functions_args_str(node)
api_info_dict[obj_id]["args"] = (
gen_functions_args_str(node)
)
elif isinstance(node, ast.ClassDef):
for n in node.body:
if (
hasattr(n, "name")
and n.name == "__init__"
):
api_info_dict[obj_id][
"args"
] = gen_functions_args_str(n)
api_info_dict[obj_id]["args"] = (
gen_functions_args_str(n)
)
break
else:
logger.debug("%s omitted", obj_full_name)
Expand All @@ -354,9 +354,9 @@ def parse_module_file(mod):
api_info_dict[obj_id]["full_name"] = obj_full_name
api_info_dict[obj_id]["short_name"] = short_name
api_info_dict[obj_id]["module_name"] = mod_name
api_info_dict[obj_id][
"doc_filename"
] = obj_full_name.replace(".", "/")
api_info_dict[obj_id]["doc_filename"] = (
obj_full_name.replace(".", "/")
)
else:
logger.debug("%s omitted", obj_full_name)

Expand Down
3 changes: 1 addition & 2 deletions docs/dev_guides/git_guides/codestyle_check_guide_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ Date: xxx
| [Lucas-C/pre-commit-hooks](https://github.com/Lucas-C/pre-commit-hooks.git) | 社区维护的一些通用的 hook,含将 CRLF 改为 LF、移除 Tab 等 hook | 1.5.1 |
| [copyright_checker](https://github.com/PaddlePaddle/Paddle/blob/develop/tools/codestyle/copyright.hook) | Copyright 检查 | 本地脚本 |
| [black](https://github.com/psf/black) | Python 代码格式化 | 23.3.0 |
| [flake8](https://github.com/PyCQA/flake8) | Python 代码风格检查(即将被 Ruff 完全替换) | 5.0.4 |
| [ruff](https://github.com/astral-sh/ruff) | Python 代码风格检查 | 0.2.0 |
| [ruff](https://github.com/astral-sh/ruff) | Python 代码风格检查 | 0.3.0 |
| [clang-format](https://github.com/llvm/llvm-project/tree/main/clang/tools/clang-format) | C++ 代码格式化 | 13.0.0 |
| [cpplint](https://github.com/cpplint/cpplint) | C++ 代码风格检查 | 1.6.0 |
| [clang-tidy](https://github.com/llvm/llvm-project/tree/main/clang-tools-extra/clang-tidy) | C++ 代码风格检查 | 15.0.2.1 |
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ select = [

# Pygrep-hooks
"PGH004",

# Ruff-specific rules
"RUF100",
]
unfixable = [
"NPY001"
Expand Down

0 comments on commit ab68ebb

Please sign in to comment.