Skip to content

Commit

Permalink
#25: Saving current code in the run folder
Browse files Browse the repository at this point in the history
  • Loading branch information
ancestor-mithril committed Dec 18, 2021
1 parent 447c203 commit 2864e2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from sklearn.metrics import cohen_kappa_score

from utils import *
from utils.misc import progress_bar
from utils.misc import progress_bar, save_current_code
import models


Expand All @@ -46,6 +46,7 @@ def main(config: DictConfig):
os.makedirs(save_config_path, exist_ok=True)
with open(os.path.join(save_config_path, "README.md"), 'w+') as f:
f.write(OmegaConf.to_yaml(config, resolve=True))
save_current_code(save_config_path)

solver = Solver(config)
return solver.run()
Expand Down
17 changes: 16 additions & 1 deletion utils/misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
import time
import os
import subprocess
import zipfile

TOTAL_BAR_LENGTH = 80
LAST_T = time.time()
Expand Down Expand Up @@ -90,4 +92,17 @@ def format_time(seconds):
i += 1
if f == '':
f = '0ms'
return f
return f

def save_current_code(path: str):
print(f"Saving current code to {path}")
files_in_repo = subprocess.run(['git', 'ls-tree', '--full-tree', '-r', '--name-only', 'HEAD'],
stdout=subprocess.PIPE).stdout.decode("utf-8").split("\n")
root = subprocess.run(['git', 'rev-parse', '--show-toplevel'], stdout=subprocess.PIPE).stdout.decode(
"utf-8").rstrip('\n')
with zipfile.ZipFile(os.path.join(path, "files.zip"), "w", zipfile.ZIP_DEFLATED) as z:
for file in files_in_repo:
file_path = os.path.join(root, file)
if os.path.isfile(file_path):
print(file)
z.write(file_path, file)

0 comments on commit 2864e2b

Please sign in to comment.