-
-
Save pepasflo/b09ad3302c96a2d4083b0604b97fb089 to your computer and use it in GitHub Desktop.
A pod wrapper script which uses 'bundle exec' if a Gemfile is found.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# A wrapper for 'pod' which detects if it should run 'bundle exec pod' or | |
# use the system 'pod' command, based on the presence of a 'Gemfile'. | |
# If a Gemfile exists in any directory above pwd, 'bundle exec pod' should | |
# be used. Otherwise, the system 'pod' is used. | |
# Expected behavior: | |
# $ pwd | |
# /Users/foo/github/some_repo | |
# $ pod --version | |
# 1.4.0 | |
# $ cd /tmp | |
# $ pod --version | |
# 1.5.3 | |
import os | |
import sys | |
def gemfile_exists(): | |
# Ascend up the directory tree looking for a Gemfile. | |
gempath = 'Gemfile' | |
while True: | |
if os.path.exists(gempath): | |
return True | |
else: | |
if os.path.abspath(gempath) == '/Gemfile': | |
return False | |
else: | |
gempath = '../' + gempath | |
continue | |
if __name__ == "__main__": | |
if gemfile_exists(): | |
cmd = ['bundle', 'exec', 'pod'] + sys.argv[1:] | |
else: | |
scriptdir = os.path.dirname(__file__) | |
pathchunks = os.environ["PATH"].split(':') | |
if scriptdir in pathchunks: | |
os.environ["PATH"] = ':'.join( | |
filter(lambda x: x != scriptdir, pathchunks) | |
) | |
else: | |
# We can't find an exact match in $PATH, so fall back to the | |
# alternate strategy of chopping one leading component from $PATH | |
# and recursing. | |
# (To instead chop a trailing component, change '[1:]' to '[:1]') | |
os.environ["PATH"] = ':'.join(pathchunks[1:]) | |
cmd = ['pod'] + sys.argv[1:] | |
os.execvp(cmd[0], cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment