diff --git a/auto_git_info.py b/auto_git_info.py index 281beb9ac182fc469dd27fbb968a2ab611fd607e..156aea352949371acd362297a362bf94ff901cf7 100644 --- a/auto_git_info.py +++ b/auto_git_info.py @@ -2,21 +2,33 @@ import git import json import os import datetime +import argparse +import warnings import __main__ def log_info(args, path=None): - time = datetime.time() + time = datetime.datetime.now().isoformat() + if isinstance(args, argparse.Namespace): + args = args.__dict__ + elif isinstance(args, argparse.ArgumentParser): + args = args.parse_args().__dict__ if path: if '/' in path: os.makedirs(path.rsplit('/', 1)[0], exist_ok=True) else: if not os.path.isdir('run_log'): os.makedirs('run_log') - path = 'run_log/' + time.isoformat() + '.json' + path = 'run_log/' + time + '.json' with open(path, 'w') as logfile: repo = git.Repo(os.path.dirname(os.path.abspath(__main__.__file__)), search_parent_directories=True) sha = repo.head.object.hexsha + changes = repo.index.diff(None) + if len(changes): + warnings.simplefilter('always', DeprecationWarning) + warnings.warn(f'{[c.a_path for c in changes]} have differences with current commit', + DeprecationWarning, stacklevel=2) + warnings.simplefilter('default', DeprecationWarning) json.dump({'script': __main__.__file__, 'commit': sha, 'parameters': args,