Add package data for GPU rent and update CLI documentation

- Added package data configuration for the 'gpu_rent' package in pyproject.toml.
- Updated README.md to include usage instructions for Windows and Unix launchers.
- Enhanced CLI documentation in cli.md to reflect new commands and their functionalities.
- Revised setup.md to clarify installation steps and environment setup.
- Improved error handling and command descriptions in the CLI implementation.
- Added new functions for model version handling and flavor resolution in the codebase.
- Updated state management to include additional properties for better tracking.
This commit is contained in:
Leonid Pershin
2026-08-21 03:06:51 +03:00
parent 167d07a733
commit 615cf81493
34 changed files with 2733 additions and 117 deletions
+57 -2
View File
@@ -2,9 +2,11 @@
from __future__ import annotations
import re
from dataclasses import dataclass
from pathlib import Path
from typing import Any
from urllib.parse import parse_qs, urlparse
import yaml
@@ -17,8 +19,24 @@ MODEL_TYPES = (
"embedding",
"controlnet",
"upscaler",
"clip",
)
MODEL_DIRS = {
"checkpoint": "Stable-Diffusion",
"lora": "Lora",
"vae": "VAE",
"embedding": "Embeddings",
"controlnet": "controlnet",
"upscaler": "upscale_models",
"clip": "clip",
}
_VERSION_QS = re.compile(r"modelVersionId=(\d+)", re.I)
_VERSION_PATH = re.compile(r"/model-versions/(\d+)", re.I)
_DOWNLOAD_PATH = re.compile(r"/api/download/models/(\d+)", re.I)
_SHA_REF = re.compile(r"^[0-9a-fA-F]{40}$")
@dataclass
class ModelEntry:
@@ -71,7 +89,10 @@ def parse_models(path: Path) -> list[ModelEntry]:
if vid in (0, "0", None) and not url:
continue
version_id = int(vid) if vid not in (None, "", 0, "0") else None
entries.append(ModelEntry(kind=kind, version_id=version_id, url=str(url) if url else None))
url_s = str(url) if url else None
if version_id is None and url_s:
version_id = extract_version_id(url_s)
entries.append(ModelEntry(kind=kind, version_id=version_id, url=url_s))
return entries
@@ -94,9 +115,43 @@ def parse_extensions(path: Path) -> list[GitRepo]:
repos.append(
GitRepo(
kind=kind,
url=str(item["url"]),
url=str(item["url"]).strip(),
ref=str(item.get("ref") or "main"),
directory=str(item["dir"]) if item.get("dir") else None,
)
)
return repos
def extract_version_id(url: str) -> int | None:
text = url.strip()
for rx in (_VERSION_QS, _VERSION_PATH, _DOWNLOAD_PATH):
match = rx.search(text)
if match:
return int(match.group(1))
parsed = urlparse(text)
ids = parse_qs(parsed.query).get("modelVersionId") or parse_qs(parsed.query).get("modelversionid")
if ids:
try:
return int(ids[0])
except ValueError:
return None
return None
def repo_dirname(repo: GitRepo) -> str:
if repo.directory:
return repo.directory
name = repo.url.rstrip("/").rsplit("/", 1)[-1]
if name.endswith(".git"):
name = name[:-4]
return name or "extension"
def is_commit_sha(ref: str) -> bool:
return bool(_SHA_REF.match(ref.strip()))
def remote_root_for(repo: GitRepo) -> str:
base = "/mnt/swarm_data/Extensions" if repo.kind == "swarmui" else "/mnt/swarm_data/DLNodes"
return f"{base}/{repo_dirname(repo)}"