MikeChandler's picture
feat: initial release of hf-release v0.1.0
f824e2f verified
"""Local filesystem helpers."""
from __future__ import annotations
import re
from pathlib import Path
from .exceptions import ValidationError
_REPO_ID_RE = re.compile(r"^[a-zA-Z0-9_.\-]+/[a-zA-Z0-9_.\-]+$")
_VERSION_RE = re.compile(r"^v?\d+\.\d+\.\d+([.\-].+)?$")
def validate_model_dir(path: Path) -> Path:
if not path.exists():
raise ValidationError(
f"Model directory does not exist: {path}",
suggestion="Pass the correct --model path.",
)
if not path.is_dir():
raise ValidationError(
f"--model must be a directory, got a file: {path}",
suggestion="Point --model to the directory containing your model files.",
)
files = list(path.iterdir())
if not files:
raise ValidationError(
f"Model directory is empty: {path}",
suggestion="Make sure training has completed and the output directory is correct.",
)
return path
def validate_version(version: str) -> str:
if not _VERSION_RE.match(version):
raise ValidationError(
f"Invalid version string: {version!r}",
suggestion="Use semantic versioning like v1.2.0 or 1.2.0.",
)
return version
def validate_repo_id(repo_id: str, label: str = "repo") -> str:
if not _REPO_ID_RE.match(repo_id):
raise ValidationError(
f"Invalid {label} ID: {repo_id!r}",
suggestion="Repo IDs must be in 'owner/name' format.",
)
return repo_id