Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created November 9, 2011 23:05
Show Gist options
  • Save jordanorelli/1353465 to your computer and use it in GitHub Desktop.
Save jordanorelli/1353465 to your computer and use it in GitHub Desktop.
install python package conditionally in bash
#!/usr/bin/env bash
ARCHIVE_URL="https://github.com/recurly/recurly-client-python/tarball/master"
ARCHIVE_NAME="recurly.tar.gz"
if ! python -c 'import recurly' &> /dev/null; then
TMP_DIR=$(mktemp -d XXXXX)
pushd "$TMP_DIR"
wget "$ARCHIVE_URL" -O "$ARCHIVE_NAME"
tar --strip-components 1 -xf "$ARCHIVE_NAME"
find . -type f -name 'setup.py' -exec python {} install \;
rm "$ARCHIVE_NAME"
popd
rm -rf "$TMP_DIR"
fi
@jordanorelli
Copy link
Author

this kinda works. it doesn't fully work because their setup.py doesn't install the package's dependencies automatically, but if you have the prereqs it works. kinda a shitty solution, but it's a good example of shell exit codes and the -c flag for the python interpreter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment