Created
July 11, 2014 20:11
-
-
Save nbren12/17542a6d8c2ccb2c3897 to your computer and use it in GitHub Desktop.
bootstrap virtualenv
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
import sys | |
import subprocess | |
VENV_VERSION = '1.9.1' | |
PYPI_VENV_BASE = 'http://pypi.python.org/packages/source/v/virtualenv' | |
PYTHON = 'python' | |
INITIAL_ENV = 'pyenv' | |
def shellcmd(cmd, echo=True): | |
""" Run 'cmd' in the shell and return its standard out. | |
""" | |
if echo: print '[cmd] {0}'.format(cmd) | |
out = subprocess.check_output(cmd, stderr=sys.stderr, shell=True) | |
if echo: print out | |
return out | |
dirname = 'virtualenv-' + VENV_VERSION | |
tgz_file = dirname + '.tar.gz' | |
# Fetch virtualenv from PyPI | |
venv_url = PYPI_VENV_BASE + '/' + tgz_file | |
shellcmd('wget --no-check-certificate {0}'.format(venv_url)) | |
# Untar | |
shellcmd('tar xzf {0}'.format(tgz_file)) | |
# Create the initial env | |
shellcmd('{0} {1}/virtualenv.py --system-site-packages {2}'.format(PYTHON, dirname, INITIAL_ENV)) | |
# Install the virtualenv package itself into the initial env | |
shellcmd('{0}/bin/pip install {1}'.format(INITIAL_ENV, tgz_file)) | |
# Cleanup | |
shellcmd('rm -rf {0} {1}'.format(dirname, tgz_file)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment