本文整理汇总了Python中virtualenv.create_environment函数的典型用法代码示例。如果您正苦于以下问题:Python create_environment函数的具体用法?Python create_environment怎么用?Python create_environment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_environment函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_ve
def update_ve(self, full_rebuild, force_update):
if not path.exists(self.requirements):
print >> sys.stderr, "Could not find requirements: file %s" % self.requirements
return 1
update_required = self.virtualenv_needs_update()
if not update_required and not force_update:
# Nothing to be done
print "VirtualEnv does not need to be updated"
print "use --force to force an update"
return 0
# if we need to create the virtualenv, then we must do that from
# outside the virtualenv. The code inside this if statement will only
# be run outside the virtualenv.
if full_rebuild and path.exists(self.ve_dir):
shutil.rmtree(self.ve_dir)
if not path.exists(self.ve_dir):
import virtualenv
virtualenv.logger = virtualenv.Logger(consumers=[])
virtualenv.create_environment(self.ve_dir, site_packages=False)
# install the pip requirements and exit
pip_path = path.join(self.ve_dir, 'bin', 'pip')
# use cwd to allow relative path specs in requirements file, e.g. ../tika
pip_retcode = subprocess.call(
[pip_path, 'install', '--requirement=%s' % self.requirements],
cwd=os.path.dirname(self.requirements))
if pip_retcode == 0:
self.update_ve_timestamp()
return pip_retcode
示例2: test_pypy_pre_import
def test_pypy_pre_import(tmp_path):
"""For PyPy, some built-in modules should be pre-imported because
some programs expect them to be in sys.modules on startup.
"""
check_code = inspect.getsource(check_pypy_pre_import)
check_code = textwrap.dedent(check_code[check_code.index("\n") + 1 :])
if six.PY2:
check_code = check_code.decode()
check_prog = tmp_path / "check-pre-import.py"
check_prog.write_text(check_code)
ve_path = str(tmp_path / "venv")
virtualenv.create_environment(ve_path)
bin_dir = virtualenv.path_locations(ve_path)[-1]
try:
cmd = [
os.path.join(bin_dir, "{}{}".format(virtualenv.EXPECTED_EXE, ".exe" if virtualenv.IS_WIN else "")),
str(check_prog),
]
subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as exception:
assert not exception.returncode, exception.output
示例3: env_create
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
if web_server == ENV_M2:
install_mongrel2(settings)
### pip install requirements
response = install_with_pip(py_reqs)
示例4: configure_virtualenv
def configure_virtualenv(config, python_worktree, build_worktree=None,
remote_packages=None, site_packages=True):
if not remote_packages:
remote_packages = list()
# create a new virtualenv
python_worktree.config = config
venv_path = python_worktree.venv_path
pip = python_worktree.pip
try:
virtualenv.create_environment(python_worktree.venv_path,
site_packages=site_packages)
except:
ui.error("Failed to create virtualenv")
return
# Install all Python projects using pip install -e .
python_projects = python_worktree.python_projects
for i, project in enumerate(python_projects):
ui.info_count(i, len(python_projects),
ui.green, "Configuring", ui.reset, ui.blue, project.src)
cmd = [pip, "install", "--editable", "."]
qisys.command.call(cmd, cwd=project.path)
# Write a qi.pth file containing path to C/C++ extensions
if build_worktree:
handle_extensions(venv_path, python_worktree, build_worktree)
# Install the extension in the virtualenv
binaries_path = virtualenv.path_locations(venv_path)[-1]
pip_binary = os.path.join(binaries_path, "pip")
if remote_packages:
cmd = [pip_binary, "install"] + remote_packages
subprocess.check_call(cmd)
示例5: install
def install(self):
# Create a new virtualenv in the temp install location
import virtualenv
virtualenv.create_environment(
self.install_dir,
site_packages=False
)
# chdir into the pecan source
os.chdir(pkg_resources.get_distribution('pecan').location)
py_exe = os.path.join(self.install_dir, 'bin', 'python')
pecan_exe = os.path.join(self.install_dir, 'bin', 'pecan')
# env/bin/python setup.py develop (pecan)
subprocess.check_call([
py_exe,
'setup.py',
'develop'
])
# create the templated project
os.chdir(self.install_dir)
subprocess.check_call([pecan_exe, 'create', 'Testing123'])
# move into the new project directory and install
os.chdir('Testing123')
subprocess.check_call([
py_exe,
'setup.py',
'develop'
])
示例6: prepare_virtualenv
def prepare_virtualenv(packages=()):
"""
Prepares a virtual environment.
:rtype : VirtualEnvDescription
"""
vroot = get_vroot()
env_key = get_env_key(packages)
vdir = os.path.join(vroot, env_key)
vbin = os.path.join(vdir, ('bin', 'Scripts')[_windows])
exe_suffix = ("", ".exe")[_windows]
vpython = os.path.join(vbin, 'python' + exe_suffix)
vpip = os.path.join(vbin, 'pip' + exe_suffix)
venv_description = VirtualEnvDescription(home_dir=vdir, bin_dir=vbin, python=vpython, pip=vpip, packages=packages)
env = get_clean_system_environment()
env['PIP_DOWNLOAD_CACHE'] = os.path.abspath(os.path.join(vroot, "pip-download-cache"))
# Cache environment
done_flag_file = os.path.join(vdir, "done")
if not os.path.exists(done_flag_file):
if os.path.exists(vdir):
shutil.rmtree(vdir)
virtualenv.create_environment(vdir)
for package_spec in packages:
subprocess.call([vpip, "install", package_spec], env=env)
open(done_flag_file, 'a').close()
subprocess.call([vpython, "setup.py", "install"], env=env)
return venv_description
示例7: run_tests
def run_tests(payload):
#payload = get_payload(payload_id)
job = get_current_job()
# work out the repo_url
repo_name = payload['repository']['name']
owner = payload['repository']['owner']['name']
repo_url = "[email protected]:%s/%s.git" % (owner, repo_name)
update_progress(job, 'repo url: %s' % repo_url)
logger.info("repo: %s" % repo_url)
vpath = tempfile.mkdtemp(suffix="ridonkulous")
logger.info("cloning repo %s to: %s" % (repo_url, vpath))
update_progress(job, "cloning repo %s to: %s" % (repo_url, vpath))
create_environment(vpath, site_packages=False)
os.chdir(vpath)
git.Git().clone(repo_url)
os.chdir(os.path.join(vpath, repo_name))
pip = "%s/bin/pip" % vpath
#python = "%s/bin/python"
nose = "%s/bin/nosetests" % vpath
ret = subprocess.call(r'%s install -r requirements.txt --use-mirrors' % pip, shell=True)
logger.info("running nose")
ret = subprocess.call(r'%s' % nose, shell=True)
logger.info(ret)
update_progress(job, 'done')
return 'ok'
示例8: _create
def _create(self, clear=False):
if clear:
self.location.rmtree()
if self._template:
# On Windows, calling `_virtualenv.path_locations(target)`
# will have created the `target` directory...
if sys.platform == 'win32' and self.location.exists:
self.location.rmdir()
# Clone virtual environment from template.
self._template.location.copytree(self.location)
self._sitecustomize = self._template.sitecustomize
self._user_site_packages = self._template.user_site_packages
else:
# Create a new virtual environment.
if self._venv_type == 'virtualenv':
_virtualenv.create_environment(
self.location,
no_pip=True,
no_wheel=True,
no_setuptools=True,
)
self._fix_virtualenv_site_module()
elif self._venv_type == 'venv':
builder = _venv.EnvBuilder()
context = builder.ensure_directories(self.location)
builder.create_configuration(context)
builder.setup_python(context)
self.site.makedirs()
self.sitecustomize = self._sitecustomize
self.user_site_packages = self._user_site_packages
示例9: install
def install(package):
if not os.path.exists('.env'):
print('Creating virtualenv')
create_environment('.env', never_download=True)
print('Installing %s' % package)
pip.main(['install', package, '-t', os.environ['PWD'] + '/.env/lib/python2.7/site-packages/','--log-file', '.env/ppm.log'])
示例10: build
def build(cls, path, key, options, force=False):
''' Build a virtual environment in specified path, according to given
key and options. '''
virtualenv.logger = virtualenv.Logger(
[(virtualenv.Logger.level_for_integer(2), sys.stderr)])
# a simple check that what we want to remove looks like a ve name :)
if force and os.path.exists(path):
if len(os.path.basename(path)) == 32:
shutil.rmtree(path)
else:
raise AssertionError("Ah, you probably do not want to delete "
"%s, do you?" % path)
os.makedirs(path)
virtualenv.create_environment(home_dir=path)
ve = VirtualEnv(path)
# "fix" bug in pip
# (see: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=677801)
if options.fix_pip:
fragments_file = 'local/lib/python2.7/site-packages/' \
'pip-1.1-py2.7.egg/pip/vcs/__init__.py'
ve.execlp("sed", "-ie",
"/urlparse.uses_fragment.extend(self.schemes)/d",
ve.local_path(fragments_file))
ve.unlink(fragments_file + 'c')
key.initialize(ve)
ve.mark_as_good()
return ve
示例11: _create
def _create(self, clear=False):
# Create the actual virtual environment
_virtualenv.create_environment(
self.location,
clear=clear,
never_download=True,
no_pip=True,
)
# Install our development version of pip install the virtual
# environment
cmd = [self.bin.join("python"), "setup.py", "install", "--no-compile"]
p = subprocess.Popen(
cmd,
cwd=self.pip_source_dir,
stderr=subprocess.STDOUT,
stdout=DEVNULL,
)
p.communicate()
if p.returncode != 0:
raise subprocess.CalledProcessError(
p.returncode,
cmd,
output=p.stdout,
)
示例12: create_virtual_env
def create_virtual_env(project_path, install_path):
# 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')
virtualenv.create_environment(ve_path)
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(['{}/ve/bin/pip'.format(project_path),
'install',
'-U',
'pip'])
if not os.path.exists('{}/requirements.txt'.format(project_path)):
logger.warning('requirements.txt not found')
return ve_path
run_command(['{}/ve/bin/pip'.format(project_path),
'install',
'-r',
'{}/requirements.txt'.format(project_path)])
virtualenv.make_environment_relocatable(ve_path)
fixup_scripts(install_path, ve_path)
except Exception:
logger.exception('failed to install requirements! error message:')
raise Exception('fail to install requirements.')
return ve_path
示例13: __init__
def __init__(self, binPath, profilePath, password=None):
self.venvDir = tempfile.mkdtemp()
self.leafName = os.path.basename(__file__)
self.binDir = os.path.join(self.venvDir, 'bin')
self.profilePath = profilePath
self.password = password
self.subproc = None
# create the virtualenv
virtualenv.create_environment(self.venvDir,
site_packages=True,
never_download=True,
no_pip=True,
no_setuptools=True
)
# copy libraries
if sys.platform == "linux2":
dllfiles = "*.so"
elif sys.platform == "darwin":
dllfiles = "*.dylib"
elif sys.platform == "win32":
dllfiles = "*.dll"
files = glob.glob(os.path.join(binPath, dllfiles))
if not len(files):
raise Exception("Could not find libraries in " + binPath)
for filename in files:
shutil.copy(filename, self.binDir)
# copy our script
shutil.copy(__file__, self.binDir)
示例14: main
def main():
if not requirements_modified_time > environment_modified_time:
print 'Environment already up-to-date'
return
import virtualenv
import subprocess
if path.exists(VE_ROOT):
shutil.rmtree(VE_ROOT)
virtualenv.logger = virtualenv.Logger(consumers=[])
virtualenv.create_environment(VE_ROOT, site_packages=False)
# check requirements
if not path.exists(PIP_CACHE_ROOT):
os.mkdir(PIP_CACHE_ROOT)
PIP_BASE = [VE_PIP, 'install', '-q', '-i',
'https://simple.crate.io/',
'--extra-index-url', 'http://e.pypi.python.org/simple',
'--download-cache=%s' % (PIP_CACHE_ROOT,),]
for req in REQUIREMENTS:
subprocess.call(PIP_BASE + ['-r', req])
file(VE_TIMESTAMP, 'w').close()
示例15: bootstrap
def bootstrap(folder):
print("+- Loading pip:", end='')
try:
from pip.req import InstallRequirement
except:
print(" failed....")
raise
print(" done")
try:
print("+- Creating virtual enviroment: ", end='')
virtualenv.create_environment(folder, site_packages=True, clear=False)
print(" %s" % folder)
except Exception as e:
print(""" failed....
- Error instanciating the virutal enviroment. This is a catastrophic failure...
- Something is really wrong with this Python installation
- You could try to manually install virtualenv via:
sudo python -m pip install -U virtualenv
""")
raise
else:
return
finally:
pass