Skip to content

Commit 7409516

Browse files
committed
fix migration error and add uv suppord
add uv suuort s
1 parent 85e7166 commit 7409516

11 files changed

Lines changed: 744 additions & 32 deletions

File tree

.github/workflows/build.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v4
16-
- name: Set up Python 3.11
17-
uses: actions/setup-python@v3
16+
- name: Install uv
17+
uses: astral-sh/setup-uv@v4
1818
with:
19-
python-version: "3.11"
19+
enable-cache: true
20+
- name: Set up Python 3.11
21+
run: uv python install 3.11
2022
- name: Install dependencies
21-
run: |
22-
python -m pip install --upgrade pip
23-
if [ -f backend/requirements.txt ]; then pip install -r backend/requirements.txt; fi
24-
pip install pytest pytest-asyncio
23+
working-directory: ./backend
24+
run: uv sync --group dev
2525
- name: Test
2626
working-directory: ./backend/src
2727
run: |
2828
mkdir -p config
29-
pytest
29+
uv run pytest
3030
3131
webui-test:
3232
runs-on: ubuntu-latest

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ __pycache__/
55

66
# C extensions
77
*.so
8+
.python-version
89

910
# Distribution / packaging
1011
.Python
@@ -176,6 +177,8 @@ cython_debug/
176177
.run
177178
/backend/src/templates/
178179
/backend/src/config/
180+
/backend/config/
181+
/backend/data/
179182
/src/debuger.py
180183
/backend/src/dist.zip
181184
/pyrightconfig.json

backend/README.md

Whitespace-only changes.

backend/pyproject.toml

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,88 @@
1+
[project]
2+
name = "backend"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.11"
7+
dependencies = [
8+
"beautifulsoup4>=4.13.4",
9+
"bencode-py>=4.0.0",
10+
"dotenv>=0.9.9",
11+
"fastapi>=0.116.1",
12+
"httpx[http2,socks]>=0.28.1",
13+
"jinja2>=3.1.6",
14+
"packaging>=25.0",
15+
"passlib>=1.7.4",
16+
"python-jose>=3.5.0",
17+
"python-multipart>=0.0.20",
18+
"sqlmodel>=0.0.24",
19+
"sse-starlette>=3.0.2",
20+
"urllib3>=2.5.0",
21+
"uvicorn>=0.35.0",
22+
]
123
[tool.ruff]
224
select = [
325
# pycodestyle(E): https://beta.ruff.rs/docs/rules/#pycodestyle-e-w
4-
"E",
26+
"E",
527
# Pyflakes(F): https://beta.ruff.rs/docs/rules/#pyflakes-f
6-
"F",
28+
"F",
729
# isort(I): https://beta.ruff.rs/docs/rules/#isort-i
8-
"I"
30+
"I",
931
]
1032
ignore = [
1133
# E501: https://beta.ruff.rs/docs/rules/line-too-long/
12-
'E501',
34+
'E501',
1335
# F401: https://beta.ruff.rs/docs/rules/unused-import/
1436
# avoid unused imports lint in `__init__.py`
1537
'F401',
1638
]
1739

1840
# Allow autofix for all enabled rules (when `--fix`) is provided.
19-
fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"]
41+
fixable = [
42+
"A",
43+
"B",
44+
"C",
45+
"D",
46+
"E",
47+
"F",
48+
"G",
49+
"I",
50+
"N",
51+
"Q",
52+
"S",
53+
"T",
54+
"W",
55+
"ANN",
56+
"ARG",
57+
"BLE",
58+
"COM",
59+
"DJ",
60+
"DTZ",
61+
"EM",
62+
"ERA",
63+
"EXE",
64+
"FBT",
65+
"ICN",
66+
"INP",
67+
"ISC",
68+
"NPY",
69+
"PD",
70+
"PGH",
71+
"PIE",
72+
"PL",
73+
"PT",
74+
"PTH",
75+
"PYI",
76+
"RET",
77+
"RSE",
78+
"RUF",
79+
"SIM",
80+
"SLF",
81+
"TID",
82+
"TRY",
83+
"UP",
84+
"YTT",
85+
]
2086
unfixable = []
2187

2288
# Exclude a variety of commonly ignored directories.
@@ -52,12 +118,18 @@ line-length = 88
52118
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
53119

54120
# Assume Python 3.10.
55-
target-version = "py310"
121+
target-version = "py311"
56122

57123
[tool.ruff.mccabe]
58124
# Unlike Flake8, default to a complexity level of 10.
59125
max-complexity = 10
60126

61127
[tool.black]
62128
line-length = 88
63-
target-version = ['py310', 'py311']
129+
target-version = ['py311']
130+
131+
[dependency-groups]
132+
dev = [
133+
"pytest>=8.4.1",
134+
"pytest-asyncio>=1.1.0",
135+
]

backend/requirements.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
anyio==3.7.0
21
bencode.py ==4.0.0
32
bs4==0.0.1
43
certifi==2023.5.7
54
charset-normalizer==3.1.0
6-
click==8.1.3
75
fastapi==0.97.0
8-
h11==0.14.0
96
idna==3.4
10-
pydantic~=1.10
117
httpx[http2,socks]==0.25.0
128
six==1.16.0
139
sniffio==1.3.0
1410
soupsieve==2.4.1
15-
typing_extensions==4.6.3
1611
urllib3==2.0.3
1712
uvicorn==0.22.0
1813
attrdict==2.0.1

backend/src/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
}
3030

3131

32-
3332
def create_app() -> FastAPI:
3433
app = FastAPI(lifespan=lifespan)
3534

@@ -66,7 +65,6 @@ async def get_poster(path: str):
6665
logger.warning(f"[Poster] Path outside allowed directory: {path}")
6766
raise HTTPException(status_code=400, detail="Path outside allowed directory")
6867

69-
7068
# 如果文件不存在,尝试下载
7169
if not post_path.exists():
7270
try:
@@ -101,6 +99,7 @@ def html(request: Request, path: str):
10199
return templates.TemplateResponse("index.html", context)
102100

103101
else:
102+
104103
@app.get("/", status_code=302, tags=["html"])
105104
def index():
106105
return RedirectResponse("/docs")

backend/src/module/database/migration.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
from sqlmodel import Session, text
1212

1313
from module.conf import DATA_PATH
14-
from .engine import engine
1514
from module.models import DatabaseVersion
1615

16+
from .engine import engine
17+
1718
logger = logging.getLogger(__name__)
1819

1920

@@ -118,6 +119,7 @@ def check_compatibility(self) -> dict[str, any]:
118119

119120
def _get_migration_path(self, from_version: str, to_version: str) -> list[str]:
120121
"""获取迁移路径"""
122+
121123
available_versions = list(self.migration_history.keys())
122124

123125
# 找出所有需要升级的版本(大于from_version且小于等于to_version)
@@ -131,7 +133,7 @@ def _get_migration_path(self, from_version: str, to_version: str) -> list[str]:
131133
migrations_needed.append(version)
132134

133135
# 按版本号排序
134-
migrations_needed.sort(key=lambda v: version.parse(v))
136+
# migrations_needed.sort(key=lambda v: version.parse(v))
135137

136138
return migrations_needed
137139

@@ -142,7 +144,7 @@ def _version_compare(self, version1: str, version2: str) -> int:
142144
try:
143145
v1 = version.parse(version1)
144146
v2 = version.parse(version2)
145-
147+
146148
if v1 > v2:
147149
return 1
148150
elif v1 < v2:
@@ -159,7 +161,6 @@ def _version_compare(self, version1: str, version2: str) -> int:
159161
else:
160162
return 0
161163

162-
163164
def _migrate_to_3_2_0(self, session: Session):
164165
"""迁移到版本 3.2.0"""
165166
logger.info("开始迁移到版本 3.2.0")

backend/src/module/manager/trgger.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

backend/src/module/network/proxy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def set_proxy() -> str | None:
2424

2525

2626
def test_proxy() -> bool:
27-
with httpx.Client(proxies=set_proxy()) as client:
27+
with httpx.Client(proxy=set_proxy()) as client:
2828
try:
2929
client.get("https://www.baidu.com")
3030
return True
@@ -47,7 +47,7 @@ def test_proxy() -> bool:
4747

4848
if __name__ == "__main__":
4949
print(set_proxy())
50-
with httpx.Client(proxies=set_proxy()) as client:
50+
with httpx.Client(proxy=set_proxy()) as client:
5151
client.headers["User-Agent"] = (
5252
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
5353
)

backend/src/module/network/request_url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async def check_url(self, url: str):
6363

6464
async def __aenter__(self):
6565
self.client: httpx.AsyncClient = httpx.AsyncClient(
66-
http2=True, proxies=self.proxy, headers=self.header, timeout=self.timeout
66+
http2=True, proxy=self.proxy, headers=self.header, timeout=self.timeout
6767
)
6868
return self
6969

0 commit comments

Comments
 (0)