-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime_utils.py
More file actions
24 lines (17 loc) · 846 Bytes
/
runtime_utils.py
File metadata and controls
24 lines (17 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from __future__ import annotations
import tarfile
from pathlib import Path
DEFAULT_INSTANCE_ID = "chirlu__sox.42b3557"
def package_submission(source_dir: Path, run_dir: Path, instance_id: str, *, force: bool = False) -> Path:
source_dir = source_dir.resolve()
if not (source_dir / "compile.sh").exists():
raise FileNotFoundError(f"{source_dir / 'compile.sh'} is required")
out_dir = run_dir / instance_id
out_dir.mkdir(parents=True, exist_ok=True)
archive = out_dir / "submission.tar.gz"
if archive.exists() and not force:
raise FileExistsError(f"{archive} already exists; pass --force to overwrite")
with tarfile.open(archive, "w:gz") as tar:
for path in sorted(source_dir.rglob("*")):
tar.add(path, arcname=path.relative_to(source_dir), recursive=False)
return archive