diff --git a/setup.py b/setup.py index 1d930f09a317b922e46d8984ae215de6a02a715f..af34bc6d889d16904494fee8a38ed84885b83061 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages setup(name='auto_git_info', - version='1.0.1', + version='1.1.0', description='Automatically log your command line arguments and commit sha', author='Maxence Ferrari', py_modules=['auto_git_info'], diff --git a/src/__init__.py b/src/__init__.py index 5c4105cd39cc4181c773f21fc007b4d120968c8b..6849410aae0a8010e76d5f0a44ced13d750b0989 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1 +1 @@ -__version__ = "1.0.1" +__version__ = "1.1.0" diff --git a/src/auto_git_info.py b/src/auto_git_info.py index fec1ec14c8f12b0bbf9254b8115ece1fc44c5b6f..60de9c8a6168cd4abd7f2e7a5202c43f3e1a99da 100644 --- a/src/auto_git_info.py +++ b/src/auto_git_info.py @@ -46,3 +46,41 @@ def log_info(args, *, path=None, **kwargs): 'time': time} out.update({k: v for k, v in kwargs.items() if k not in out}) json.dump(out, logfile) + + +if __name__ == '__main__': + import sys + import subprocess + import getopt # https://github.com/python/cpython/blob/main/Lib/pdb.py#L1950 + + opts, args = getopt.getopt(sys.argv[1:], 'h:', ['help', ]) + + _usage = """\ + usage: auto_git_info.py [log_path=path.json] pyfile [arg] ... + automatically log the info of pyfile and its argument in a json file + + """ + + if not args: + print('_usage') + sys.exit(2) + + if any(opt in ['-h', '--help'] for opt, optarg in opts): + print('_usage') + sys.exit() + + if '=' in args[0]: + cmd, path = args[0].split('=') + if cmd not in 'log_path': + print('Error: {args[0]} contains an = but is not log_path option') + sys.exit(2) + args = args[1:] + elif args[0] in 'log_path': + path = args[1] + args = args[2:] + else: + path = None + sys.argv[:] = args # Hide "pdb.py" and pdb options from argument list + __main__.__file__ = os.path.abspath(args[0]) + log_info(args[1:], path=path, parsed_arguments=False) + subprocess.Popen(['python'] + args).wait(timeout=None)