Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_dist_missing_data(testdir):
"""Test failure when using a worker without pytest-cov installed."""
venv_path = os.path.join(str(testdir.tmpdir), 'venv')
virtualenv.create_environment(venv_path)
if sys.platform == 'win32':
if platform.python_implementation() == "PyPy":
exe = os.path.join(venv_path, 'bin', 'python.exe')
else:
exe = os.path.join(venv_path, 'Scripts', 'python.exe')
else:
exe = os.path.join(venv_path, 'bin', 'python')
subprocess.check_call([
exe,
'-mpip',
'install',
'py==%s' % py.__version__,
'pytest==%s' % pytest.__version__,
'pytest_xdist==%s' % xdist.__version__
])
# Create new virtual environment
print('Step 1. Create new virtual environment')
if not os.path.isdir(dest_dir) or CONFIG['virtualenv']['clear']:
kwargs = copy.copy(CONFIG['virtualenv'])
kwargs['home_dir'] = kwargs['dest_dir']
verbosity = int(kwargs['verbose']) - int(kwargs['quiet'])
logger = virtualenv.Logger([
(virtualenv.Logger.level_for_integer(2 - verbosity), sys.stdout),
])
del kwargs['dest_dir'], kwargs['quiet'], kwargs['verbose']
virtualenv.logger = logger
virtualenv.create_environment(**kwargs)
else:
print('Virtual environment %r already exists.' % \
CONFIG['virtualenv']['dest_dir'])
"""
Restart this script using the interpreter in the given virtual environment
"""
venv = os.path.abspath(venv)
if not os.path.exists(venv):
try:
import virtualenv
except ImportError:
print 'The virtual environment does not exist: %s' % venv
print 'and virtualenv is not installed, so a new environment cannot be created'
sys.exit(3)
print 'Creating new virtualenv environment in %s' % venv
virtualenv.logger = logger
logger.indent += 2
## FIXME: always have no_site_packages?
virtualenv.create_environment(venv, site_packages=False)
if sys.platform == 'win32':
python = os.path.join(venv, 'Scripts', 'python')
else:
python = os.path.join(venv, 'bin', 'python')
if not os.path.exists(python):
python = venv
if not os.path.exists(python):
raise BadCommand('Cannot find virtual environment interpreter at %s' % python)
base = os.path.dirname(os.path.dirname(python))
os.execv(python, [python, __file__] + args + [base, '___VENV_RESTART___'])
# delete the venv if it's there and use the system python
clean(app_path)
return sys.executable
# check that there's a virtualenv there and that it's got a working
# version of python
try:
subprocess.check_call([
venv_python_path,
'-c', 'import sys; sys.exit(0)'
])
except (OSError, subprocess.CalledProcessError):
# we've got to build the virtualenv
clean(app_path)
print 'tbtool: Creating virtualenv...'
virtualenv.create_environment(venv_path, site_packages=True,)
# ignore the virtualenv when the app is tracked with git
gitignore_path = os.path.join(venv_path, '.gitignore')
with open(gitignore_path, 'w') as f:
f.write(textwrap.dedent('''
# Generated by tbtool.
# Don't commit virtualenvs to git, because they contain platform-specific
# code and don't relocate well.
# '*' matches everything in this folder
*
'''))
# if PYTHONPATH is defined (this is how Tide bundles packages on Mac and Linux),
@findroot
def create_virtualenv(path):
if path:
path = os.path.join(path,
PROJECT_FOLDERNAME,
VIRTUALENV_FOLDERNAME)
virtualenv.create_environment(path, False, True)
try:
import virtualenv
except ImportError:
raise errors.DistutilsModuleError(
'The virtualenv module must be available if no virtualenv '
'bootstrap script is given: {0}'.format(bootstrap))
self.logger.info(
'Setting up a isolated Python with module: '
'{0}.create_environment({1} {2})'.format(
virtualenv, repr(home_dir), ' '.join(
'{0}={1}'.format(item) for item in opts.items())))
virtualenv.logger = virtualenv.Logger([(
virtualenv.Logger.level_for_integer(2 - self.verbose),
sys.stdout)])
virtualenv.create_environment(home_dir, **opts)
return os.path.join(
sysconfig.get_path('scripts', vars=dict(base=home_dir)),
'python' + sysconfig.get_config_var('EXE'))
@api.multi
def prepare(self):
"""
Prepare build instance, by default it will create a virtualenv,
install from requirements.txt and generate a clean database
:return:
"""
self.ensure_one()
self.clean()
_logger.info('Preparing build: %s' % self.short_name)
if not os.path.exists(self.env_dir):
virtualenv.create_environment(self.env_dir)
if not os.path.exists(os.path.join(self.repo_id.root(), 'nginx/')):
virtualenv.create_environment(
os.path.join(self.repo_id.root(), 'nginx/'))
if not os.path.exists(self.parts_dir):
os.makedirs(self.parts_dir)
if not os.path.exists(self.env_dir+'/logs'):
os.makedirs(self.env_dir+'/logs')
_logger.info('Cloning %s' % self.branch_id.name)
self.repo_id.clone(branch=self.branch_id.name, to_path=self.custom_dir,
commit=self.commit)
runbot_cfg = self.read_json()
if not runbot_cfg:
self.write({
def env_create(args):
import virtualenv
settings = load_settings()
### Create virtualenv
virtualenv.create_environment(settings.dir_virtualenv)
py_reqs = ['brubeck', 'dictshield', 'ujson']
### Ask about preferences
web_server = ask_webserver(settings)
if web_server == ENV_M2:
py_reqs.append('pyzmq')
concurrency = ask_concurrency(settings)
py_reqs.append(concurrency)
if concurrency == ENV_GEVENT:
py_reqs.append('cython')
template_engines = ask_template_engines(settings)
py_reqs = py_reqs + template_engines
### Install web server requirements
try:
import virtualenv
except ImportError:
raise errors.DistutilsModuleError(
'The virtualenv module must be available if no virtualenv '
'bootstrap script is given: {0}'.format(bootstrap))
self.logger.info(
'Setting up a isolated Python with module: '
'{0}.create_environment({1} {2})'.format(
virtualenv, repr(home_dir), ' '.join(
'{0}={1}'.format(item) for item in opts.items())))
virtualenv.logger = virtualenv.Logger([(
virtualenv.Logger.level_for_integer(2 - self.verbose),
sys.stdout)])
virtualenv.create_environment(home_dir, **opts)
activate_this = os.path.join(
sysconfig.get_path('scripts', vars=dict(base=home_dir)),
'activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
# Reinitialize much of distutils since many of the command
# objects have prefix related value stored locally
reload(distutils.sysconfig)
for command in self.distribution.command_obj.itervalues():
finalized = command.finalized
self.reinitialize_command(command)
if finalized:
command.ensure_finalized()