Last active
August 29, 2015 14:08
-
-
Save wolph/fb98f7dc6ba6f05da2b8 to your computer and use it in GitHub Desktop.
Virtualenv recreating using virtualenvwrapper. Tested with OS X Homebrew but should work with any linux/unix system
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
#!/bin/zsh -e | |
if [ ! -d "$PROJECT_HOME" ]; then | |
echo 'Your $PROJECT_HOME needs to be defined' | |
echo 'http://virtualenvwrapper.readthedocs.org/en/latest/install.html#location-of-project-directories' | |
exit 1 | |
fi | |
if [ "" = "$1" ]; then | |
echo "Usage: $0 <project_name>" | |
exit 1 | |
fi | |
env="$1" | |
project_dir="$PROJECT_HOME/$1" | |
env_dir="$HOME/envs/$1" | |
function command_exists(){ | |
type $1 2>/dev/null | grep -vq ' not found' | |
} | |
if command_exists workon; then | |
echo 'Getting virtualenvwrapper from environment' | |
# Workon exists, nothing to do :) | |
elif [ -x ~/bin/mount_workon ]; then | |
echo 'Using mount workon' | |
# Optional support for packaged project directories and virtualenvs using | |
# https://github.com/WoLpH/dotfiles/blob/master/bin/mount_workon | |
. ~/bin/mount_workon | |
mount_file "$project_dir" | |
mount_file "$env_dir" | |
elif command_exists virtualenvwrapper.sh; then | |
echo 'Using virtualenvwrapper' | |
. $(which virtualenvwrapper.sh) | |
fi | |
if ! command_exists workon; then | |
echo 'Virtualenvwrapper not found, please install it' | |
exit 1 | |
fi | |
rmvirtualenv $env || true | |
echo "Recreating $env" | |
mkvirtualenv $env || true | |
workon "$env" || true | |
pip install virtualenv{,wrapper} | |
cd $project_dir | |
setvirtualenvproject | |
if [ -f setup.py ]; then | |
echo "Installing local package" | |
pip install -e . | |
fi | |
function install_requirements(){ | |
# Installing requirements from given file, if it exists | |
if [ -f "$1" ]; then | |
echo "Installing requirements from $1" | |
pip install -r "$1" | |
fi | |
} | |
install_requirements requirements_test.txt | |
install_requirements requirements-test.txt | |
install_requirements requirements.txt | |
install_requirements test_requirements.txt | |
install_requirements test-requirements.txt | |
if [ -d docs ]; then | |
echo "Found docs, installing sphinx" | |
pip install sphinx{,-pypi-upload} py | |
fi | |
echo "Installing ipython" | |
pip install ipython | |
if [ -f tox.ini ]; then | |
deps=$(python -c " | |
parser=__import__('ConfigParser').ConfigParser(); | |
parser.read('tox.ini'); | |
print parser.get('testenv', 'deps').strip().replace('{toxinidir}/', '')") | |
echo "Found deps from tox.ini: $deps" | |
echo $deps | parallel -v --no-notice pip install {} | |
fi | |
if [ -f .travis.yml ]; then | |
echo "Found deps from travis:" | |
installs=$(grep 'pip install' .travis.yml | grep -v '\$' | sed -e 's/.*pip install/pip install/' | grep -v 'pip install . --use-mirrors' | sed -e 's/$/;/') | |
echo $installs | |
eval $installs | |
fi | |
deactivate |
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
#!/bin/zsh -e | |
export PATH="/usr/local/bin:$PATH" | |
. $(which virtualenvwrapper.sh) | |
envs=$(find ~/envs -mindepth 1 -maxdepth 1 -type d -print -or -name '*.sparseimage' -print | sed -e 's/.*\///' | sed 's/.sparseimage$//' | sort -u) | |
echo "$envs" | parallel -v --no-notice ~/scripts/recreate_virtualenv.sh {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment