Add support for gpu-rent.vars and enhance git update functionality
- Updated .gitignore to include gpu-rent.vars. - Modified env.example to introduce the UPDATE_GIT variable for controlling git updates during execution. - Implemented Import-GpuRentVars function in gpu-rent.ps1 to load environment variables from gpu-rent.vars. - Enhanced gpu-rent.sh to support loading variables from gpu-rent.vars and added logic for handling default and extra arguments. - Updated CLI documentation to reflect the new gpu-rent.vars file and its usage in configuration. - Improved bootstrap and provisioning logic to conditionally perform git updates based on the new configuration.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
from pathlib import Path
|
||||
|
||||
from gpu_rent.remote.civitai_fetch import should_skip
|
||||
|
||||
|
||||
def test_should_skip_missing(tmp_path: Path):
|
||||
skip, _ = should_skip(tmp_path / "nope.safetensors", "abc")
|
||||
assert skip is False
|
||||
|
||||
|
||||
def test_should_skip_exists_no_sha(tmp_path: Path):
|
||||
dest = tmp_path / "a.safetensors"
|
||||
dest.write_bytes(b"weights")
|
||||
skip, reason = should_skip(dest, "")
|
||||
assert skip is True
|
||||
assert "уже есть" in reason
|
||||
|
||||
|
||||
def test_should_skip_sha_match(tmp_path: Path):
|
||||
dest = tmp_path / "a.safetensors"
|
||||
dest.write_bytes(b"weights")
|
||||
import hashlib
|
||||
|
||||
digest = hashlib.sha256(b"weights").hexdigest()
|
||||
skip, reason = should_skip(dest, digest)
|
||||
assert skip is True
|
||||
assert "sha ok" in reason
|
||||
|
||||
|
||||
def test_should_not_skip_bad_sha(tmp_path: Path):
|
||||
dest = tmp_path / "a.safetensors"
|
||||
dest.write_bytes(b"weights")
|
||||
skip, reason = should_skip(dest, "deadbeef" * 8)
|
||||
assert skip is False
|
||||
assert "перекачиваю" in reason
|
||||
@@ -0,0 +1,15 @@
|
||||
from gpu_rent.remote.clone_ext import do_update, is_sha
|
||||
|
||||
|
||||
def test_is_sha():
|
||||
assert is_sha("a" * 40)
|
||||
assert not is_sha("main")
|
||||
|
||||
|
||||
def test_do_update_reads_flag(tmp_path, monkeypatch):
|
||||
flag = tmp_path / "gpu-rent-update-git"
|
||||
monkeypatch.setattr("gpu_rent.remote.clone_ext.UPDATE_PATH", flag)
|
||||
flag.write_text("0\n", encoding="utf-8")
|
||||
assert do_update() is False
|
||||
flag.write_text("1\n", encoding="utf-8")
|
||||
assert do_update() is True
|
||||
@@ -0,0 +1,18 @@
|
||||
import paramiko
|
||||
|
||||
from gpu_rent.tunnel import _patch_paramiko_for_sshtunnel, _ssh_tunnel_forwarder
|
||||
|
||||
|
||||
def test_dsskey_shim_allows_sshtunnel_import():
|
||||
# Simulate paramiko>=4 (no DSSKey) then ensure sshtunnel can load.
|
||||
had = getattr(paramiko, "DSSKey", None)
|
||||
if had is not None:
|
||||
delattr(paramiko, "DSSKey")
|
||||
try:
|
||||
_patch_paramiko_for_sshtunnel()
|
||||
assert hasattr(paramiko, "DSSKey")
|
||||
cls = _ssh_tunnel_forwarder()
|
||||
assert cls is not None
|
||||
finally:
|
||||
if had is not None:
|
||||
paramiko.DSSKey = had
|
||||
@@ -0,0 +1,32 @@
|
||||
from pathlib import Path
|
||||
|
||||
from gpu_rent.varsfile import apply_vars_file, parse_vars_file, split_args
|
||||
|
||||
|
||||
def test_parse_vars_file(tmp_path: Path):
|
||||
path = tmp_path / "gpu-rent.vars"
|
||||
path.write_text(
|
||||
"# comment\n"
|
||||
"GPU_RENT_DEFAULT_ARGS=up --yes\n"
|
||||
"export UPDATE_GIT=false\n"
|
||||
"QUOTED=\"a b\"\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
data = parse_vars_file(path)
|
||||
assert data["GPU_RENT_DEFAULT_ARGS"] == "up --yes"
|
||||
assert data["UPDATE_GIT"] == "false"
|
||||
assert data["QUOTED"] == "a b"
|
||||
|
||||
|
||||
def test_apply_does_not_override(tmp_path: Path, monkeypatch):
|
||||
path = tmp_path / "gpu-rent.vars"
|
||||
path.write_text("FOO=from-file\n", encoding="utf-8")
|
||||
monkeypatch.setenv("FOO", "from-env")
|
||||
apply_vars_file(path, override=False)
|
||||
import os
|
||||
|
||||
assert os.environ["FOO"] == "from-env"
|
||||
|
||||
|
||||
def test_split_args():
|
||||
assert split_args("up --yes --no-update") == ["up", "--yes", "--no-update"]
|
||||
Reference in New Issue
Block a user