Skip to content

Instantly share code, notes, and snippets.

@mattvonrocketstein
Created March 27, 2015 04:27
Show Gist options
  • Save mattvonrocketstein/6e6a13668c23f39c8379 to your computer and use it in GitHub Desktop.
Save mattvonrocketstein/6e6a13668c23f39c8379 to your computer and use it in GitHub Desktop.
self-hosting fabfile
if __name__ == '__main__':
# a neat hack that makes this file a "self-hosting" fabfile,
# ie it is invoked directly but still gets all the fabric niceties
# like real option parsing, including --help and -l (for listing
# commands). note that as of fabric 1.10, the file for some reason
# needs to end in .py, despite what the documentation says. see:
# http://docs.fabfile.org/en/1.4.2/usage/fabfiles.html#fabfile-discovery
#
# the .index() manipulation below should make this work regardless of
# whether this is invoked from shell as "./foo.py" or "python foo.py"
from fabric.main import main as fmain
patched_argv = ['fab', '-f', __file__, ] + \
sys.argv[sys.argv.index(__file__)+1:]
sys.argv = patched_argv
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fmain()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment