Refactor environment and configuration management

- Updated the project structure to store configuration files (.env, models.yaml, extensions.yaml) in the project root instead of the user's home directory.
- Enhanced the setup process to automatically copy example files to the project root on first run.
- Implemented a migration function to transfer legacy configuration files from the user's home directory to the new project structure.
- Revised documentation to reflect changes in file locations and setup instructions.
- Improved code readability and maintainability by refactoring path management functions.
This commit is contained in:
Leonid Pershin
2026-08-21 03:20:18 +03:00
parent c2ca39a4a7
commit 343f741baa
22 changed files with 202 additions and 90 deletions
+20
View File
@@ -1,4 +1,5 @@
from gpu_rent.config import load_config
from gpu_rent.paths import env_path, migrate_legacy_if_needed, models_manifest_path, runtime_dir
from gpu_rent.ssh_keys import ensure_ed25519, public_path
@@ -19,6 +20,25 @@ def test_load_config_missing_auth(monkeypatch, tmp_path):
assert not cfg.auth_ok
assert "OS_USERNAME" in cfg.missing
assert cfg.data_volume_size_gb == 100
assert cfg.models_manifest == models_manifest_path()
assert runtime_dir() == tmp_path / ".gpu-rent"
assert env_path() == tmp_path / ".env"
def test_migrate_legacy_user_home(tmp_path, monkeypatch):
monkeypatch.setenv("HOME", str(tmp_path / "user"))
monkeypatch.setenv("USERPROFILE", str(tmp_path / "user"))
proj = tmp_path / "proj"
proj.mkdir()
monkeypatch.chdir(proj)
legacy = tmp_path / "user" / ".gpu-rent"
legacy.mkdir(parents=True)
(legacy / "models.yaml").write_text("checkpoint:\n - version_id: 1\n", encoding="utf-8")
(legacy / ".env").write_text("OS_USERNAME=x\n", encoding="utf-8")
notes = migrate_legacy_if_needed()
assert notes
assert (proj / "models.yaml").is_file()
assert (proj / ".env").is_file()
def test_ssh_key_generate(tmp_path):