@@ -56,8 +56,28 @@ def __init__(self, data_dir):
56
56
self .data_dir = data_dir
57
57
self .tee = Tee (data_dir )
58
58
self .load_graph ()
59
+ self .get_git_info ()
59
60
self .check_graph ()
60
61
62
+ def get_git_info (self ):
63
+ """
64
+ Get branch and commit info, and print
65
+ If not in git repo, print warning
66
+ """
67
+ if not hasattr (self , 'blech_clust_dir' ):
68
+ print ('Run load_graph() first' )
69
+ exit ()
70
+ pwd = os .getcwd ()
71
+ # Change to blech_clust directory
72
+ os .chdir (self .blech_clust_dir )
73
+ git_branch = os .popen ('git rev-parse --abbrev-ref HEAD' ).read ().strip ()
74
+ git_commit = os .popen ('git rev-parse HEAD' ).read ().strip ()
75
+ if git_branch == '' or git_commit == '' :
76
+ print ('Not in git repository, please clone blech_clust rather than downloading zip' )
77
+ self .git_str = f'Git branch: { git_branch } \n Git commit: { git_commit } '
78
+ # change back to original directory
79
+ os .chdir (pwd )
80
+
61
81
def load_graph (self ):
62
82
"""
63
83
Load computation graph from file, if file is present
@@ -144,6 +164,8 @@ def write_to_log(self, script_path, type = 'attempted'):
144
164
type = 'attempted' : script was attempted
145
165
type = 'completed' : script was completed
146
166
"""
167
+ if not hasattr (self , 'git_str' ):
168
+ raise ValueError ('Run get_git_info() first' )
147
169
self .log_path = os .path .join (self .data_dir , 'execution_log.json' )
148
170
current_datetime = datetime .now ().strftime ('%Y-%m-%d %H:%M:%S' )
149
171
if os .path .exists (self .log_path ):
@@ -157,6 +179,7 @@ def write_to_log(self, script_path, type = 'attempted'):
157
179
log_dict ['attempted' ][script_path ] = current_datetime
158
180
print ('============================================================' )
159
181
print (f'Attempting { os .path .basename (script_path )} , started at { current_datetime } ' )
182
+ print (self .git_str )
160
183
print ('============================================================' )
161
184
elif type == 'completed' :
162
185
if 'completed' not in log_dict .keys ():
0 commit comments