This commit is contained in:
student_2333 2024-11-12 12:36:41 +08:00
parent aa79913147
commit fb2f897f1f
No known key found for this signature in database
GPG Key ID: 665F083BEC56F2A6
3 changed files with 4 additions and 64 deletions

View File

@ -25,6 +25,7 @@ jobs:
- name: Build and Publish distribution 📦 to PyPI
run: |-
pdm install -G:all
# pdm install --prod
pdm render
pdm install -G:all
pdm pub-all

View File

@ -8,12 +8,8 @@ readme = "README.md"
[tool.pdm.dev-dependencies]
dev = [
"httpx>=0.27.2",
"beautifulsoup4>=4.12.3",
"lxml>=5.3.0",
"-e file:///${PROJECT_ROOT}/packages/nonebot-plugin-nailongremove-base#egg=nonebot-plugin-nailongremove-base",
"-e file:///${PROJECT_ROOT}/packages/nonebot-plugin-nailongremove#egg=nonebot-plugin-nailongremove",
# "-e file:///${PROJECT_ROOT}/packages/nonebot-plugin-nailongremove-gpu#egg=nonebot-plugin-nailongremove-gpu",
]
[build-system]

View File

@ -1,11 +1,8 @@
import re
from pathlib import Path
from typing import List, Optional, TypedDict, cast
from typing import TypedDict
import bs4
import httpx
import tomllib
from packaging.version import Version
from .utils import PACKAGES_PATH
@ -50,63 +47,9 @@ def get_version() -> str:
VERSION = get_version()
def format_markers(m: re.Match[str]) -> Optional[str]:
g = cast(PkgFilenameReGroups, m.groupdict())
if (not g["py"].startswith("cp")) or (g["abi"].endswith("m")):
return None
markers: List[str] = []
markers.append(f"python_version == '{g['py'][2]}.{g['py'][3:]}'")
common_os = {
"win": "win32",
"linux": "linux",
}
if x := next((x for x in common_os if g["platform"].startswith(f"{x}_")), None):
markers.extend(
(
f"sys_platform == '{common_os[x]}'",
f"platform_machine == '{g['platform'][len(x) + 1:]}'",
),
)
return " and ".join(markers)
def get_torch_deps() -> str:
def get_deps(pkg: str) -> List[str]:
html = httpx.get(f"{TORCH_INDEX}/{pkg}/").raise_for_status().text
soup = bs4.BeautifulSoup(html, "lxml")
tags: "bs4.ResultSet[bs4.Tag]" = soup.find_all("a")
links = [
(m, f"{TORCH_BASE}{h}")
for x in tags
if (
isinstance((h := x.get("href")), str)
and (m := PKG_FILENAME_RE.match(x.text))
)
]
links.sort(key=lambda x: Version(x[0]["ver"]), reverse=True)
ver: str = links[1][0]["ver"]
links = [x for x in links if x[0]["ver"] == ver]
return [f"{pkg} @ {x} ; {ms}" for m, x in links if (ms := format_markers(m))]
deps = [
*get_deps("torch"),
*get_deps("torchvision"),
]
return "\n ".join(f'"{x}",' for x in deps).strip(",")
# TORCH = get_torch_deps()
def process(file_path: Path):
file_path.with_name(file_path.name.replace(".template", "")).write_text(
(
file_path.read_text(encoding="u8").replace("%%version%%", VERSION)
# .replace('"%%torch%%"', TORCH)
),
file_path.read_text(encoding="u8").replace("%%version%%", VERSION),
"u8",
)