Files
gpu-rent/src/gpu_rent/payload.py
T
Leonid Pershin 615cf81493 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.
2026-08-21 03:06:51 +03:00

94 lines
2.5 KiB
Python

"""Local app trees: Models / Wildcards / CustomWorkflows / Output."""
from __future__ import annotations
import hashlib
from pathlib import Path
SKIP_NAMES = {".gitkeep", "README.md", "README.txt", ".gitignore"}
WEIGHT_SUFFIXES = {".safetensors", ".ckpt", ".pt", ".pth", ".bin", ".gguf", ".sft", ".onnx"}
META_SUFFIXES = {".json", ".civitai.json", ".swarm.json", ".preview.png", ".png", ".webp", ".jpg"}
def is_skipped(path: Path) -> bool:
name = path.name
if name in SKIP_NAMES or name.startswith("."):
return True
return False
def has_payload(root: Path) -> bool:
if not root.is_dir():
return False
for path in root.rglob("*"):
if path.is_file() and not is_skipped(path):
return True
return False
def folder_bytes(root: Path) -> int:
if not root.is_dir():
return 0
total = 0
for path in root.rglob("*"):
if path.is_file() and not is_skipped(path):
total += path.stat().st_size
return total
def iter_payload_files(root: Path) -> list[Path]:
if not root.is_dir():
return []
found = []
for path in sorted(root.rglob("*")):
if path.is_file() and not is_skipped(path):
found.append(path)
return found
def is_weight(path: Path) -> bool:
return path.suffix.lower() in WEIGHT_SUFFIXES
def sha256_file(path: Path, chunk: int = 1024 * 1024) -> str:
digest = hashlib.sha256()
with path.open("rb") as fh:
while True:
block = fh.read(chunk)
if not block:
break
digest.update(block)
return digest.hexdigest()
def sidecar_stem(name: str) -> str:
lower = name.lower()
for suffix in (
".civitai.json",
".swarm.json",
".preview.png",
".preview.webp",
".preview.jpg",
".json",
".png",
".webp",
".jpg",
):
if lower.endswith(suffix):
return name[: -len(suffix)]
return Path(name).stem
def model_push_set(root: Path) -> list[Path]:
"""Weights plus same-stem sidecars. Sidecar without weights is skipped."""
files = iter_payload_files(root)
weights = [p for p in files if is_weight(p)]
wanted: set[Path] = set(weights)
stems = {p.stem for p in weights}
for path in files:
if is_weight(path):
continue
if sidecar_stem(path.name) in stems:
wanted.add(path)
return sorted(wanted)