Skip to content

Commit 29ea53e

Browse files
committed
完善项目:添加测试、CI/CD、许可证、文档和Git hooks
- 添加测试框架:pytest配置和示例测试 - 设置CI/CD:GitHub Actions工作流(测试和代码质量) - 添加MIT许可证:LICENSE文件 - 完善文档:CONTRIBUTING.md贡献指南 - 添加开发依赖:requirements-dev.txt - 设置Git hooks:预提交钩子自动检查代码质量 - 创建开发环境脚本:setup_dev.sh一键设置 - 创建测试运行脚本:run_tests.sh - 更新项目配置:pyproject.toml添加工具配置 - 项目现在具备完整的开发生态系统
1 parent c8c55d4 commit 29ea53e

12 files changed

Lines changed: 1284 additions & 1 deletion

.github/workflows/code-quality.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Code Quality
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
quality:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.11'
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install black flake8 mypy isort
25+
26+
- name: Check code formatting with black
27+
run: |
28+
black --check --diff .
29+
30+
- name: Check import sorting with isort
31+
run: |
32+
isort --check-only --diff .
33+
34+
- name: Lint with flake8
35+
run: |
36+
flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
37+
38+
- name: Type checking with mypy
39+
run: |
40+
mypy . --ignore-missing-imports
41+
42+
- name: Security check with bandit
43+
run: |
44+
pip install bandit
45+
bandit -r . -f html -o bandit-report.html || true
46+
47+
- name: Upload security report
48+
if: always()
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: security-report
52+
path: bandit-report.html
53+
retention-days: 30

.github/workflows/test.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Python Tests
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
- cron: '0 0 * * 0' # 每周日午夜运行
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: ['3.9', '3.10', '3.11']
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install -r requirements.txt
30+
pip install pytest pytest-cov
31+
32+
- name: Lint with flake8
33+
run: |
34+
pip install flake8
35+
# 停止构建如果有语法错误或未定义的名称
36+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
37+
# 退出-zero将所有错误视为警告
38+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
39+
40+
- name: Test with pytest
41+
run: |
42+
python -m pytest tests/ -v --cov=. --cov-report=xml --cov-report=term-missing
43+
44+
- name: Upload coverage to Codecov
45+
uses: codecov/codecov-action@v3
46+
with:
47+
file: ./coverage.xml
48+
fail_ci_if_error: true
49+
50+
- name: Upload test results
51+
if: always()
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: test-results-${{ matrix.python-version }}
55+
path: |
56+
test-reports/
57+
htmlcov/
58+
retention-days: 7

.pre-commit-config.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- id: check-merge-conflict
10+
- id: check-case-conflict
11+
- id: check-toml
12+
- id: check-json
13+
14+
- repo: https://github.com/psf/black
15+
rev: 23.12.1
16+
hooks:
17+
- id: black
18+
language_version: python3
19+
20+
- repo: https://github.com/pycqa/isort
21+
rev: 5.13.2
22+
hooks:
23+
- id: isort
24+
args: ["--profile", "black"]
25+
26+
- repo: https://github.com/pycqa/flake8
27+
rev: 6.1.0
28+
hooks:
29+
- id: flake8
30+
args: ["--max-line-length=127", "--max-complexity=10"]
31+
additional_dependencies: [flake8-docstrings]
32+
33+
- repo: https://github.com/pre-commit/mirrors-mypy
34+
rev: v1.8.0
35+
hooks:
36+
- id: mypy
37+
args: [--ignore-missing-imports]
38+
additional_dependencies: [types-requests]
39+
40+
- repo: https://github.com/PyCQA/bandit
41+
rev: 1.7.7
42+
hooks:
43+
- id: bandit
44+
args: ["-c", "pyproject.toml"]
45+
exclude: ^tests/
46+
47+
- repo: https://github.com/pre-commit/mirrors-prettier
48+
rev: v3.1.0
49+
hooks:
50+
- id: prettier
51+
types_or: [markdown, yaml]
52+
exclude: ^CHANGELOG.md
53+
54+
- repo: local
55+
hooks:
56+
- id: pytest-check
57+
name: pytest check
58+
entry: python -m pytest tests/ -x
59+
language: system
60+
pass_filenames: false
61+
always_run: true
62+
stages: [push]
63+
64+
- id: requirements-check
65+
name: check requirements
66+
entry: python -c "import pkg_resources; pkg_resources.require(open('requirements.txt').read())"
67+
language: system
68+
pass_filenames: false
69+
always_run: false

0 commit comments

Comments
 (0)