Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_virtualenv(where, distribute=False):
save_argv = sys.argv
try:
import virtualenv
distribute_opt = distribute and ['--distribute'] or []
sys.argv = ['virtualenv', '--quiet'] + distribute_opt + ['--no-site-packages', '--unzip-setuptools', where]
virtualenv.main()
finally:
sys.argv = save_argv
return virtualenv.path_locations(where)
def create_virtualenv(venv_name, dir_path=None):
dir_path = dir_path or tempfile.mkdtemp()
old_args = sys.argv
try:
from virtualenv import main
sys.argv = ['virtualenv', op.join(dir_path, venv_name)]
main()
finally:
sys.argv = old_args
print("Created virtualenv %s at %s" % (venv_name, dir_path))
return dir_path
if not os.path.isdir(TARGET_DIR):
sys.exit('Existing non-directory found at: {}'.format(TARGET_DIR))
else:
os.mkdir(TARGET_DIR)
if os.path.exists(VENV_DIR):
shutil.rmtree(VENV_DIR)
if os.path.exists(TMP_DIR):
shutil.rmtree(TMP_DIR)
original = sys.argv
sys.argv = ['', VENV_DIR]
try:
sys_stdout.write('creating virtualenv {}\n'.format(VENV_DIR).encode())
virtualenv.main()
finally:
sys.argv = original
if platform.system() == 'Windows':
pip_exe = os.path.join(VENV_DIR, 'Scripts', 'pip.exe')
deps_dir = os.path.join(VENV_DIR, 'Lib', 'site-packages')
else:
pip_exe = os.path.join(VENV_DIR, 'bin', 'pip')
python_dir = os.listdir(os.path.join(VENV_DIR, 'lib'))[0]
deps_dir = os.path.join(VENV_DIR, 'lib', python_dir, 'site-packages')
if not os.path.isfile(pip_exe):
sys.exit('Pip not found in: {}'.format(pip_exe))
for req_file in REQ_FILES:
if reason:
info('Removing invalidated virtualenv. (%s)' % reason)
run(('rm', '-rf', venv_path))
else:
info('Keeping valid virtualenv from previous run.')
raise SystemExit(0) # looks good! we're done here.
# this is actually a documented extension point:
# http://virtualenv.readthedocs.org/en/latest/reference.html#adjust_options
import virtualenv
virtualenv.adjust_options = adjust_options
from sys import argv
argv[:] = ('virtualenv',) + args
info(colorize(argv))
raise_on_failure(virtualenv.main)
# There might not be a venv_path if doing something like "venv= --version"
# and not actually asking virtualenv to make a venv.
if return_values.venv_path is not None:
run(('rm', '-rf', join(return_values.venv_path, 'local')))
def create_virtual_env(project_path, install_path, ve_args):
# remove existing virtual env if exists
ve_path = os.path.join(project_path, cfg.VIRTUAL_ENV_PATH)
if os.path.exists(ve_path):
shutil.rmtree(ve_path)
try:
logger.info('creating virtual env')
sys.argv = ['']
if '--no-wheel' not in ve_args:
sys.argv.append('--no-wheel')
sys.argv.extend(ve_args)
sys.argv.append(ve_path)
try:
virtualenv.main()
except SystemExit as sysext:
if sysext.code != 0:
raise SystemExit(sysext)
except Exception:
logger.exception('failed to create virtualenv: ')
raise Exception('failed to create virtualenv!')
try:
logger.info('installing requirements for virtualenv')
# update pip to latest version
run_command(['{}/{}/bin/pip'.format(project_path,
cfg.VIRTUAL_ENV_PATH),
'install',
'-U',
'pip'])
def run(inst):
virtualenv.after_install = inst.after_install
virtualenv.adjust_options = inst.adjust_options
virtualenv.main()
def run():
virtualenv.after_install = after_install
virtualenv.adjust_options = adjust_options
virtualenv.main()