Skip to content

Instantly share code, notes, and snippets.

@Gribouillis
Created January 20, 2018 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gribouillis/02f8e6213c3f6ed6be39094265b044a4 to your computer and use it in GitHub Desktop.
Save Gribouillis/02f8e6213c3f6ed6be39094265b044a4 to your computer and use it in GitHub Desktop.
A script to watch files and automatically run a python script
#!/usr/bin/env python3
# -*-coding: utf8-*-
'''doc
'''
__version__ = '0.1.0'
from argparse import ArgumentParser
import sys
def task_AutoExecution():
"""my doc"""
yield {
'basename': 'AutoExecution',
'actions': ['PYTHONIOENCODING="utf8" {python} {script}'.format(python=sys.executable, script=SCRIPT)],
'watch': [PROG] + WATCH,
'verbosity': 2,
}
if __name__ == '__main__':
parser = ArgumentParser(description='Automatically runs a python script every time it is changed on disk')
parser.add_argument('script', metavar='SCRIPT', help='python script to execute', action='store')
parser.add_argument('-w', '--watch', metavar='FILE', help='additional file to watch (end arglist with --)', nargs='*')
args = parser.parse_args()
SCRIPT = args.script
PROG = SCRIPT.strip().split()[0]
WATCH = args.watch or []
sys.argv[1:] = ['auto',]
import doit
doit.run(globals())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment