Skip to content

Commit 79bdf5e

Browse files
committed
refactor: 用 ruff + basedpyright 替代 black/flake8/isort/mypy 进行代码质量检查
- 在 pyproject.toml 中添加 [tool.ruff] 和 [tool.basedpyright] 配置 - 重写 CI formatting 和 linting jobs 使用 ruff format/check 和 basedpyright - 运行 ruff format 全量格式化 204 个文件 - 运行 ruff check --fix 自动修复 783 个 lint 问题(import 排序、语法现代化等) - 为 6 个 __init__.py 添加 __all__ 声明,解决 396 个 F401 re-export 警告 - 自动修复 132 个 C408 不必要的集合构造调用(dict() → {}) - 手动修复 E722/B904/B007/SIM102/SIM103/SIM108/F811/E721 等代码质量问题 - 修复 ruff 自动修复引入的 2 个回归问题(np.array → np.ndarray、C416 误转换) - 更新 VSCode 推荐扩展(移除 black/isort/flake8,添加 Pylance) - 测试结果:334 passed, 1 failed(预先存在), 23 skipped - Lint 从 1601 errors 降至 43 errors(剩余为需人工评估的设计选择)
1 parent 1f5760a commit 79bdf5e

226 files changed

Lines changed: 8715 additions & 5713 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/code-quality.yml

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,28 @@ jobs:
5252
token: ${{ secrets.CODECOV_TOKEN }}
5353
slug: zengbin93/czsc
5454

55-
# formatting:
56-
# name: Code Formatting
57-
# runs-on: ubuntu-latest
58-
# needs: test
59-
# steps:
60-
# - name: Checkout code
61-
# uses: actions/checkout@v4
62-
63-
# - name: Install uv
64-
# uses: astral-sh/setup-uv@v2
65-
# with:
66-
# version: "latest"
67-
68-
# - name: Set up Python
69-
# run: uv python install 3.11
70-
71-
# - name: Install dependencies
72-
# run: uv sync
73-
74-
# - name: Check code formatting with black
75-
# run: |
76-
# uv add --dev black
77-
# uv run black --check --diff czsc/
78-
79-
# - name: Check import sorting with isort
80-
# run: |
81-
# uv add --dev isort
82-
# uv run isort --check-only --diff czsc/
55+
formatting:
56+
name: Code Formatting
57+
runs-on: ubuntu-latest
58+
needs: test
59+
steps:
60+
- name: Checkout code
61+
uses: actions/checkout@v4
62+
63+
- name: Install uv
64+
uses: astral-sh/setup-uv@v2
65+
with:
66+
version: "latest"
67+
68+
- name: Set up Python
69+
run: uv python install 3.11
70+
71+
- name: Install dependencies
72+
run: uv sync --extra all
73+
74+
- name: Check code formatting with ruff
75+
run: |
76+
uv run ruff format --check --diff czsc/ test/
8377
8478
linting:
8579
name: Code Linting
@@ -98,20 +92,15 @@ jobs:
9892
run: uv python install 3.11
9993

10094
- name: Install dependencies
101-
run: uv sync
95+
run: uv sync --extra all
10296

103-
- name: Lint with flake8
97+
- name: Lint with ruff
10498
run: |
105-
uv add --dev flake8
106-
# stop the build if there are Python syntax errors or undefined names
107-
uv run flake8 czsc/ --count --select=E9,F63,F7,F82 --show-source --statistics
108-
# exit-zero treats all errors as warnings. The GitHub editor is 120 chars wide
109-
uv run flake8 czsc/ --count --exit-zero --max-complexity=30 --max-line-length=120 --statistics
99+
uv run ruff check czsc/ test/
110100
111-
- name: Type checking with mypy
101+
- name: Type checking with basedpyright
112102
run: |
113-
uv add --dev mypy types-requests
114-
uv run mypy czsc/ --ignore-missing-imports || true
103+
uv run basedpyright czsc/ || true
115104
116105
security:
117106
name: Security Audit

.vscode/extensions.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"recommendations": [
33
"ms-python.python",
4-
"ms-python.black-formatter",
5-
"ms-python.isort",
6-
"ms-python.flake8",
4+
"ms-python.vscode-pylance",
75
"charliermarsh.ruff",
86
"ms-vscode.test-adapter-converter"
97
]

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"python.analysis.typeCheckingMode": "off",
66
"python.analysis.autoSearchPaths": true,
77
"python.analysis.extraPaths": [
8-
"."
8+
".",
9+
"czsc"
910
],
1011
"files.exclude": {
1112
"**/__pycache__": true,

0 commit comments

Comments
 (0)