Files
gpu_runner/code/utils.py
T
2023-07-13 11:53:14 +02:00

34 lines
912 B
Python

from pydantic import AnyHttpUrl
from pathlib import Path
from git import Repo
import logging
import shutil
import os
import yaml
from runner_script import RunnerScript
def clone_repository(repo_url: AnyHttpUrl) -> Path:
# extract repo name
repo_name = repo_url.split('/')[-1].replace('.git', '')
repo_dir = os.getenv('REPO_DIR', default=None)
assert repo_dir is not None
dst_dir = Path(repo_dir) / repo_name
# prepare repo download dir
if dst_dir.exists():
shutil.rmtree(dst_dir)
dst_dir.mkdir()
# git clone repo
Repo.clone_from(url=repo_url, to_path=dst_dir)
logging.debug('finished')
return dst_dir
def load_runner_script(path: Path) -> RunnerScript:
assert path.exists()
with open(path, 'r') as fh:
script = yaml.safe_load(fh)
runner_script = RunnerScript.parse_obj(script)
logging.debug('finished')
return runner_script