Skip to content
Snippets Groups Projects
Commit 3a0f4058 authored by ferrari's avatar ferrari
Browse files

Add module mode

parent 378d7190
No related branches found
No related tags found
No related merge requests found
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'],
......
__version__ = "1.0.1"
__version__ = "1.1.0"
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment