Skip to content

Commit 5fa603a

Browse files
authored
Merge pull request #14 from lihuacai168/feature/uv-dependency-management
feature/uv-dependency-management
2 parents 020ec6c + 1ccaeae commit 5fa603a

File tree

9 files changed

+2413
-77
lines changed

9 files changed

+2413
-77
lines changed

.github/workflows/ci.yml

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ jobs:
3131
restore-keys: |
3232
${{ runner.os }}-pip-
3333
34+
- name: Install UV
35+
run: |
36+
curl -LsSf https://astral.sh/uv/install.sh | sh
37+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
38+
3439
- name: Install dependencies
3540
run: |
36-
python -m pip install --upgrade pip
37-
pip install -r requirements.txt
38-
pip install pytest pytest-cov pytest-asyncio httpx
41+
uv venv --python ${{ matrix.python-version }}
42+
uv pip install -e ".[dev,test]"
3943
4044
- name: Set up test environment
4145
run: |
@@ -50,19 +54,19 @@ jobs:
5054
5155
- name: Run security tests
5256
run: |
53-
python -m pytest tests/test_security.py -v --tb=short
57+
uv run pytest tests/test_security.py -v --tb=short
5458
5559
- name: Run API tests
5660
run: |
57-
python -m pytest tests/test_api.py -v --tb=short
61+
uv run pytest tests/test_api.py -v --tb=short
5862
5963
- name: Run enhanced API tests
6064
run: |
61-
python -m pytest tests/test_api_enhanced.py -v --tb=short
65+
uv run pytest tests/test_api_enhanced.py -v --tb=short
6266
6367
- name: Run full test suite with coverage
6468
run: |
65-
python -m pytest tests/ -v --cov=. --cov-report=xml --cov-report=term-missing --tb=short
69+
uv run pytest tests/ -v --cov=. --cov-report=xml --cov-report=term-missing --tb=short
6670
6771
- name: Upload coverage to Codecov
6872
uses: codecov/codecov-action@v3
@@ -85,28 +89,32 @@ jobs:
8589
with:
8690
python-version: 3.11
8791

92+
- name: Install UV
93+
run: |
94+
curl -LsSf https://astral.sh/uv/install.sh | sh
95+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
96+
8897
- name: Install linting dependencies
8998
run: |
90-
python -m pip install --upgrade pip
91-
pip install flake8 black isort mypy
92-
pip install -r requirements.txt
99+
uv venv --python 3.11
100+
uv pip install -e ".[dev,test]"
93101
94102
- name: Run flake8
95103
run: |
96-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
97-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
104+
uv run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
105+
uv run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
98106
99107
- name: Check code formatting with black
100108
run: |
101-
black --check --diff .
109+
uv run black --check --diff .
102110
103111
- name: Check import sorting with isort
104112
run: |
105-
isort --check-only --diff .
113+
uv run isort --check-only --diff .
106114
107115
- name: Type checking with mypy
108116
run: |
109-
mypy . --ignore-missing-imports --no-strict-optional
117+
uv run mypy . --ignore-missing-imports --no-strict-optional
110118
continue-on-error: true
111119

112120
security:
@@ -122,20 +130,25 @@ jobs:
122130
with:
123131
python-version: 3.11
124132

133+
- name: Install UV
134+
run: |
135+
curl -LsSf https://astral.sh/uv/install.sh | sh
136+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
137+
125138
- name: Install security dependencies
126139
run: |
127-
python -m pip install --upgrade pip
128-
pip install bandit safety
129-
pip install -r requirements.txt
140+
uv venv --python 3.11
141+
uv pip install -e ".[dev,test]"
142+
uv pip install bandit safety
130143
131144
- name: Run bandit security scan
132145
run: |
133-
bandit -r . -f json -o bandit-report.json
146+
uv run bandit -r . -f json -o bandit-report.json
134147
continue-on-error: true
135148

136149
- name: Run safety check
137150
run: |
138-
safety check --json --output safety-report.json
151+
uv run safety check --json --output safety-report.json
139152
continue-on-error: true
140153

141154
- name: Upload security reports
@@ -220,11 +233,15 @@ jobs:
220233
with:
221234
python-version: 3.11
222235

236+
- name: Install UV
237+
run: |
238+
curl -LsSf https://astral.sh/uv/install.sh | sh
239+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
240+
223241
- name: Install dependencies
224242
run: |
225-
python -m pip install --upgrade pip
226-
pip install -r requirements.txt
227-
pip install pytest pytest-asyncio httpx
243+
uv venv --python 3.11
244+
uv pip install -e ".[dev,test]"
228245
229246
- name: Set up integration test environment
230247
run: |
@@ -235,13 +252,13 @@ jobs:
235252
236253
- name: Run integration tests
237254
run: |
238-
DATABASE_URL=postgresql://testuser:testpass@localhost:5432/jmeter_test python -m pytest tests/test_api.py tests/test_security.py -v --tb=short
255+
DATABASE_URL=postgresql://testuser:testpass@localhost:5432/jmeter_test uv run pytest tests/test_api.py tests/test_security.py -v --tb=short
239256
240257
- name: Test application startup
241258
run: |
242259
export ENVIRONMENT=development
243260
export DATABASE_URL=sqlite:///./startup_test.db
244-
timeout 30s python main.py &
261+
timeout 30s uv run python main.py &
245262
sleep 5
246263
# Test health endpoint - accept both 200 and 503 (some services may be unavailable in CI)
247264
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/health)
@@ -250,7 +267,7 @@ jobs:
250267
exit 1
251268
fi
252269
echo "✅ Health check passed with status: $HTTP_STATUS"
253-
pkill -f "python main.py" || true
270+
pkill -f "uv run python main.py" || true
254271
255272
deployment-ready:
256273
name: Deployment Ready Check

README.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,39 @@ git clone <repository-url>
5555
cd jmeter_toolit
5656
```
5757

58-
### 2. 安装依赖
58+
### 2. 快速安装(推荐使用 UV)
5959
```bash
60-
# 推荐使用 Python 3.11+
60+
# 使用自动设置脚本(推荐)
61+
./setup_dev.sh
62+
63+
# 或手动安装
64+
uv venv --python 3.11
65+
uv pip install -e ".[dev,test]"
66+
```
67+
68+
### 3. 传统安装方式
69+
```bash
70+
# 如果不使用 UV
6171
pip install -r requirements.txt
6272
```
6373

64-
### 3. 启动开发服务器
74+
### 4. 启动开发服务器
6575
```bash
66-
# 简化版开发服务器(推荐)
67-
python simple_dev.py
76+
# 使用 UV(推荐)
77+
UV_INDEX_URL=https://pypi.org/simple uv run python main.py
78+
79+
# 简化版开发服务器(用于测试)
80+
UV_INDEX_URL=https://pypi.org/simple uv run python dev_server.py
81+
82+
# 或使用启动脚本
83+
./start_dev.sh
6884

69-
# 或使用完整版开发服务器
70-
python run_dev.py
85+
# 传统方式
86+
python main.py
87+
python dev_server.py
7188
```
7289

73-
### 4. 访问应用
90+
### 5. 访问应用
7491
- **主界面**: http://localhost:8000
7592
- **API文档**: http://localhost:8000/docs
7693
- **健康检查**: http://localhost:8000/health

dev_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,4 @@ async def download_file(file_type: str, file_name: str):
308308
print("🔍 健康检查: http://localhost:8000/health")
309309
print("⏹️ 按 Ctrl+C 停止服务器")
310310

311-
uvicorn.run("simple_dev:app", host="0.0.0.0", port=8000, reload=True, log_level="info")
311+
uvicorn.run("dev_server:app", host="0.0.0.0", port=8000, reload=True, log_level="info")

pyproject.toml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,117 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "jmeter-toolkit"
7+
version = "2.0.0"
8+
description = "A powerful JMeter test management toolkit built with FastAPI"
9+
readme = "README.md"
10+
license = {text = "MIT"}
11+
authors = [
12+
{name = "JMeter Toolkit Team"},
13+
]
14+
classifiers = [
15+
"Development Status :: 4 - Beta",
16+
"Intended Audience :: Developers",
17+
"License :: OSI Approved :: MIT License",
18+
"Programming Language :: Python :: 3",
19+
"Programming Language :: Python :: 3.9",
20+
"Programming Language :: Python :: 3.10",
21+
"Programming Language :: Python :: 3.11",
22+
"Programming Language :: Python :: 3.12",
23+
"Framework :: FastAPI",
24+
]
25+
requires-python = ">=3.9"
26+
dependencies = [
27+
# Web framework
28+
"fastapi>=0.104.1,<0.120.0",
29+
"uvicorn[standard]>=0.24.0,<0.35.0",
30+
"python-multipart>=0.0.6,<1.0.0",
31+
32+
# Database
33+
"sqlalchemy>=2.0.23,<2.1.0",
34+
"psycopg2-binary>=2.9.9,<2.10.0",
35+
"alembic>=1.12.1,<1.15.0",
36+
37+
# Task queue
38+
"celery>=5.3.4,<6.0.0",
39+
"redis>=5.0.1,<6.0.0",
40+
41+
# Configuration
42+
"pydantic>=2.5.0,<3.0.0",
43+
"pydantic-settings>=2.0.3,<3.0.0",
44+
"python-dotenv>=1.0.0,<2.0.0",
45+
46+
# Security
47+
"python-magic>=0.4.27,<0.5.0",
48+
"cryptography>=44.0.0,<46.0.0",
49+
50+
# Logging
51+
"loguru>=0.7.2,<0.8.0",
52+
53+
# Monitoring
54+
"prometheus-client>=0.19.0,<0.22.0",
55+
"psutil>=5.9.6,<6.0.0",
56+
57+
# Utilities
58+
"PyYAML>=6.0.1,<7.0.0",
59+
"starlette>=0.27.0,<0.40.0",
60+
"jinja2>=3.1.2,<4.0.0",
61+
]
62+
63+
[project.optional-dependencies]
64+
test = [
65+
"pytest>=7.4.3,<8.0.0",
66+
"pytest-asyncio>=0.21.1,<0.25.0",
67+
"pytest-cov>=4.1.0,<5.0.0",
68+
"httpx>=0.25.2,<0.30.0",
69+
]
70+
dev = [
71+
"black>=23.11.0,<25.0.0",
72+
"isort>=5.12.0,<6.0.0",
73+
"flake8>=6.1.0,<8.0.0",
74+
"mypy>=1.7.1,<2.0.0",
75+
"pre-commit>=3.6.0,<4.0.0",
76+
]
77+
docs = [
78+
"mkdocs>=1.5.3,<2.0.0",
79+
"mkdocs-material>=9.4.8,<10.0.0",
80+
]
81+
all = [
82+
"jmeter-toolkit[test,dev,docs]",
83+
]
84+
85+
[project.urls]
86+
Homepage = "https://github.com/lihuacai168/Jmeter-Toolkit"
87+
Repository = "https://github.com/lihuacai168/Jmeter-Toolkit"
88+
Issues = "https://github.com/lihuacai168/Jmeter-Toolkit/issues"
89+
90+
[project.scripts]
91+
jmeter-toolkit = "main:main"
92+
93+
[tool.hatch.build.targets.wheel]
94+
packages = ["."]
95+
exclude = [
96+
"/.git",
97+
"/.github",
98+
"/docs",
99+
"/tests",
100+
"/venv",
101+
"/.venv",
102+
"/htmlcov",
103+
"*.pyc",
104+
"*.pyo",
105+
"*.pyd",
106+
"__pycache__",
107+
"*.db",
108+
"*.log",
109+
"*.tar.gz",
110+
"/jmx_files",
111+
"/jtl_files",
112+
"/reports",
113+
]
114+
1115
[tool.black]
2116
line-length = 127
3117
target-version = ['py39', 'py310', 'py311', 'py312']

0 commit comments

Comments
 (0)