本文整理汇总了Python中venv.create函数的典型用法代码示例。如果您正苦于以下问题:Python create函数的具体用法?Python create怎么用?Python create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: install
def install(package: str, upgrade: bool):
"""Install a package"""
click.echo('Installing {}'.format(package))
if package_dir(package).exists() and not upgrade:
click.echo('Application {} already installed, to upgrade use --upgrade'.format(package))
exit(1)
# Create venv
venv_dir = package_dir(package)
venv.create(str(venv_dir), clear=True, with_pip=True)
# Ask pip to install the package
try:
call_pip(package, ['install', package])
except subprocess.CalledProcessError as err:
click.echo(err.output)
# TODO remove package so far if it fails here
exit(1)
# Install entry-point launchers
for entry_point_group, entry_point in get_entry_points(package):
python_path = package_dir(package) / 'bin' / 'python' # TODO ask setuptools for this info?
launcher = create_launcher_text(
package=package,
version=entry_point.dist.version,
entry_point=entry_point.name,
entry_point_group=entry_point_group,
python_path=str(python_path)
)
launcher_path = config['bindir'] / entry_point.name
install_launcher(launcher_path, launcher)
开发者ID:milliams,项目名称:vam,代码行数:33,代码来源:vam.py
示例2: _setup_venv
def _setup_venv(self):
from stoqlib.lib.osutils import get_application_dir
import venv
stoqdir = get_application_dir("stoq")
env_dir = os.path.join(stoqdir, 'venv')
if not os.path.exists(env_dir):
log.info('creating venv at %s', env_dir)
if platform.system() == 'Windows':
# On windows, pip will be included as an egg
venv.create(env_dir, system_site_packages=True)
else:
venv.create(env_dir, system_site_packages=True, with_pip=True)
log.info('creating venv done')
# This is exactly what activate_this.py does
old_os_path = os.environ.get('PATH', '')
os.environ['PATH'] = os.path.join(env_dir, 'bin') + os.pathsep + old_os_path
if sys.platform == 'win32':
site_packages = os.path.join(env_dir, 'Lib', 'site-packages')
else:
site_packages = os.path.join(env_dir, 'lib', 'python%s' % sys.version[:3],
'site-packages')
prev_sys_path = list(sys.path)
import site
site.addsitedir(site_packages)
sys.real_prefix = sys.prefix
sys.prefix = env_dir
# Move the added items to the front of the path:
new_sys_path = []
for item in list(sys.path):
if item not in prev_sys_path:
new_sys_path.append(item)
sys.path.remove(item)
sys.path[:0] = new_sys_path
开发者ID:hackedbellini,项目名称:stoq,代码行数:35,代码来源:bootstrap.py
示例3: create
def create(self, name, *, system_site_packages=False, symlinks=False,
with_pip=True):
"""Create a virtual environment in $VIRTUALENV_HOME with python3's ``venv``.
Parameters
----------
name : str
Virtual environment name
system_site_packages : bool
If True, the system (global) site-packages dir is available to
created environments.
symlinks : bool
If True, attempt to symlink rather than copy files into virtual
environment.
with_pip : bool
If True, ensure pip is installed in the virtual environment. (Default is True)
"""
# NOTE: clear=True is the same as delete then create.
# NOTE: upgrade=True is its own method
if isinstance(name, PathLike):
env_path = fspath(name)
else:
env_path = os.path.join(self.venvdir, name)
if not self._check_reserved(env_path):
raise ValueError("venv can't contain reserved names ({})".format(', '.join(_subdir_names())))
venv.create(
env_path,
system_site_packages=system_site_packages, symlinks=symlinks,
with_pip=with_pip)
events.vox_on_create.fire(name=name)
开发者ID:VHarisop,项目名称:xonsh,代码行数:30,代码来源:voxapi.py
示例4: create
def create(self, name, *, system_site_packages=False, symlinks=False,
with_pip=True):
"""Create a virtual environment in $VIRTUALENV_HOME with python3's ``venv``.
Parameters
----------
name : str
Virtual environment name
system_site_packages : bool
If True, the system (global) site-packages dir is available to
created environments.
symlinks : bool
If True, attempt to symlink rather than copy files into virtual
environment.
with_pip : bool
If True, ensure pip is installed in the virtual environment. (Default is True)
"""
# NOTE: clear=True is the same as delete then create.
# NOTE: upgrade=True is its own method
env_path = os.path.join(self.venvdir, name)
venv.create(
env_path,
system_site_packages=system_site_packages, symlinks=symlinks,
with_pip=with_pip)
events.vox_on_create.fire(name)
开发者ID:astronouth7303,项目名称:xonsh,代码行数:25,代码来源:voxapi.py
示例5: main
def main():
""" Execute the test.
"""
@contextmanager
def tmpdir():
""" Enter a self-deleting temporary directory. """
cwd = getcwd()
tmp = mkdtemp()
try:
chdir(tmp)
yield tmp
finally:
rmtree(tmp)
chdir(cwd)
return
template = dirname(dirname(abspath(__file__)))
defaults = load(open(join(template, "cookiecutter.json")))
with tmpdir():
cookiecutter(template, no_input=True)
chdir(defaults["project_slug"])
create("venv", with_pip=True)
path = join("venv", "bin")
pip = which("pip", path=path) or "pip" # Travis CI workaround
install = "{:s} install .".format(pip)
for req in (join(root, "requirements.txt") for root in (".", "test")):
# Add each requirements file to the install.
install = " ".join((install, "--requirement={:s}".format(req)))
pytest = which("pytest", path=path) or "pytest" # Travis CI workaround
test = "{:s} --verbose tests/".format(pytest)
check_call(split(test))
return 0
开发者ID:mdklatt,项目名称:cookiecutter-ansible-role,代码行数:35,代码来源:test_template.py
示例6: ensure_venv
def ensure_venv(self):
"""
Find the local venv.
If it does not exist, create it and install requirements.
"""
if not os.path.exists(self.venv_path):
os.mkdir(self.venv_path)
venv.create(self.venv_path, with_pip=True)
self.install_requirements()
开发者ID:aquavitae,项目名称:pyle,代码行数:10,代码来源:pyle.py
示例7: do_pyvenv
def do_pyvenv(path, system_site_packages):
try:
import venv
except ImportError:
error("Standard Python 'venv' module not found", ERROR_EXCEPTION)
# In Python >= 3.4 venv.create() has a new parameter with_pip=False
# that allows to automatically install setuptools and pip with the module
# ensurepip. Unfortunately, we cannot use this parameter and have to
# bootstrap these packages ourselves, since some distributions of CPython
# on Ubuntu don't include ensurepip.
venv.create(path, system_site_packages=system_site_packages)
开发者ID:SeanFarrow,项目名称:intellij-community,代码行数:11,代码来源:packaging_tool.py
示例8: create_env
def create_env(name):
"""Create a virtual environment in $VIRTUALENV_HOME with python3's ``venv``.
Parameters
----------
name : str
Virtual environment name
"""
env_path = os.path.join(builtins.__xonsh_env__['VIRTUALENV_HOME'], name)
print('Creating environment...')
venv.create(env_path, with_pip=True)
msg = 'Environment {0!r} created. Activate it with "vox activate {0}".\n'
print(msg.format(name))
开发者ID:Cheaterman,项目名称:xonsh,代码行数:13,代码来源:vox.py
示例9: package_source_tgz
def package_source_tgz():
venv.create('build/pkgenv', clear=True, with_pip=True)
print_and_do('./build/pkgenv/bin/pip install -r requirements.txt')
print_and_do('./build/pkgenv/bin/pip freeze > build/requirements.freeze')
app_version = MoneyGuru.VERSION
name = 'moneyguru-src-{}.tar'.format(app_version)
dest = op.join('build', name)
print_and_do('git archive -o {} HEAD'.format(dest))
print("Adding requirements.freeze and wrapping up")
os.chdir('build')
print_and_do('tar -rf {} requirements.freeze'.format(name))
print_and_do('gzip {}'.format(name))
os.chdir('..')
开发者ID:ancientHacker,项目名称:moneyguru,代码行数:13,代码来源:package.py
示例10: _create_virtualenv
def _create_virtualenv(self):
"""Create virtualenv to install packages"""
Pip2Pkgbuild.log.info("Preparing virtualenv")
if os.path.exists(VENV_DIR):
return
venv.create(VENV_DIR,
with_pip=True)
# upgrade pip
Pip2Pkgbuild.log.info('checking for pip upgrade')
self._exec(subprocess.check_call, [VENV_PIP, 'install', '-U', 'pip'])
开发者ID:n3f4s,项目名称:pipman,代码行数:13,代码来源:pip2pkgbuild.py
示例11: install
def install(self):
"""Installer"""
options = self.options
path = [p for p in sys.path if 'parts' not in p]
del sys.modules['site']
sys.path[:] = path
env = os.environ.copy()
env['PYTHONPATH'] = ':'.join(path)
key = 'tox-install-dir'
if key in self.buildout['buildout']:
install_dir = self.buildout['buildout'][key]
elif key in self.options:
install_dir = self.options[key]
else:
install_dir = join(self.buildout['buildout']['parts-directory'],
self.name)
bin_bir = join(install_dir, 'bin')
tox = join(bin_bir, 'tox')
if not os.path.isfile(tox):
if sys.version_info[:2] >= (3,4):
import venv
venv.create(install_dir, with_pip=True)
del env['PYTHONPATH']
subprocess.call([join(bin_bir, 'pip'), 'install', 'tox'], env=env)
else:
import virtualenv
subprocess.call([sys.executable, virtualenv.__file__[:-1],
'-q', '--distribute', install_dir], env=env)
del env['PYTHONPATH']
subprocess.call([join(bin_bir, 'easy_install'), 'tox'],
env=env)
from zc.recipe.egg import Scripts
options['eggs'] = 'virtualenv'
options['scripts'] = 'tox'
options['entry-points'] = 'tox=os:execve'
options['arguments'] = (
'%(tox)r, [%(tox)r] + sys.argv[1:], os.environ'
) % dict(tox=tox)
options['initialization'] = '\n'.join([
'import os',
"os.environ['PYTHONPATH'] = ''",
])
script = Scripts(self.buildout, self.name, self.options)
script.install()
return tuple()
开发者ID:gawel,项目名称:gp.recipe.tox,代码行数:50,代码来源:__init__.py
示例12: create_env
def create_env(name):
"""Create a virtual environment in $VIRTUALENV_HOME with python3's ``venv``.
Parameters
----------
name : str
Virtual environment name
"""
env_path = join(builtins.__xonsh_env__['VIRTUALENV_HOME'], name)
print('Creating environment...')
venv.create(env_path, with_pip=True)
print('Environment "%s" created. Activate it with "vox activate %s".\n' % (name, name))
开发者ID:DNSGeek,项目名称:xonsh,代码行数:16,代码来源:vox.py
示例13: test_overwrite_existing
def test_overwrite_existing(self):
"""
Test creating environment in an existing directory.
"""
self.create_contents(self.ENV_SUBDIRS, 'foo')
venv.create(self.env_dir)
for subdirs in self.ENV_SUBDIRS:
fn = os.path.join(self.env_dir, *(subdirs + ('foo',)))
self.assertTrue(os.path.exists(fn))
with open(fn, 'rb') as f:
self.assertEqual(f.read(), b'Still here?')
builder = venv.EnvBuilder(clear=True)
builder.create(self.env_dir)
for subdirs in self.ENV_SUBDIRS:
fn = os.path.join(self.env_dir, *(subdirs + ('foo',)))
self.assertFalse(os.path.exists(fn))
开发者ID:FFMG,项目名称:myoddweb.piger,代码行数:17,代码来源:test_venv.py
示例14: create_virtualenv
def create_virtualenv(env_dir):
notify('\nCreating virtualenv')
res = venv.create(env_dir, system_site_packages=False, with_pip=True)
if not res:
proc = subprocess.run(
['pip', 'install', '--upgrade', 'pip'],
env=os.environ.copy())
if proc.returncode:
sys.exit(proc.returncode)
status_ok('Done')
return res
开发者ID:crossgovernmentservices,项目名称:sue-my-brother,代码行数:11,代码来源:script_utils.py
示例15: make_virtualenv
def make_virtualenv(env):
""" Create a virtualenv """
if sys.version_info.major == 2:
from urllib import urlretrieve
if find_executable("virtualenv") is not None:
cmd = ["virtualenv"] + [env]
subprocess.check_call(cmd)
else:
# Otherwise, download virtualenv from pypi
path = urlretrieve(VENV_URL)[0]
subprocess.check_call(["tar", "xzf", path])
subprocess.check_call(
[sys.executable, "virtualenv-%s/virtualenv.py" % VENV_VERSION, env]
)
os.unlink(path)
shutil.rmtree("virtualenv-%s" % VENV_VERSION)
else:
import venv
venv.create(env, with_pip=True)
开发者ID:stevearc,项目名称:dotfiles,代码行数:21,代码来源:make_standalone.py
示例16: upgrade
def upgrade(self, name, *, symlinks=False, with_pip=True):
"""Create a virtual environment in $VIRTUALENV_HOME with python3's ``venv``.
WARNING: If a virtual environment was created with symlinks or without PIP, you must
specify these options again on upgrade.
Parameters
----------
name : str
Virtual environment name
symlinks : bool
If True, attempt to symlink rather than copy files into virtual
environment.
with_pip : bool
If True, ensure pip is installed in the virtual environment.
"""
# venv doesn't reload this, so we have to do it ourselves.
# Is there a bug for this in Python? There should be.
env_path, bin_path = self[name]
cfgfile = os.path.join(env_path, 'pyvenv.cfg')
cfgops = {}
with open(cfgfile) as cfgfile:
for l in cfgfile:
l = l.strip()
if '=' not in l:
continue
k, v = l.split('=', 1)
cfgops[k.strip()] = v.strip()
flags = {
'system_site_packages': cfgops['include-system-site-packages'] == 'true',
'symlinks': symlinks,
'with_pip': with_pip,
}
# END things we shouldn't be doing.
# Ok, do what we came here to do.
venv.create(env_path, upgrade=True, **flags)
开发者ID:VHarisop,项目名称:xonsh,代码行数:37,代码来源:voxapi.py
示例17: setup
def setup(self, reinstall=False):
"""
Begins setup of the app.
"""
loc = self.configuration["install_loc"]
cprint("deploy.py: beginning app setup", "green")
cprint("deploy.py: obtaining sudo access", "green")
cprint("deploy.py: please enter your password if appropriate below.", "cyan")
# Attempt sudo access
status = call(["sudo", "true"])
if status != 0:
cprint("deploy.py: error: unable to access root", "red")
cprint("deploy.py: this may hamper your ability to run some things later on", "red")
has_root = False
else:
has_root = True
# continue
if not reinstall:
cprint("deploy.py: creating app directory", "green")
try:
os.makedirs(loc)
except PermissionError:
if not has_root:
cprint("deploy.py: unable to make project directory. exiting.", "red")
sys.exit(1)
call("sudo mkdir -v {}".format(loc))
call("sudo chown -v {}:{} {}".format(os.geteuid(), os.getegid(), loc))
except FileExistsError:
# oh well
call("sudo chown -v {}:{} {}".format(os.geteuid(), os.getegid(), loc))
cprint("deploy.py: changing working directory...", "green")
original_cwd = os.getcwd()
# change cwd
os.chdir(loc)
cprint("deploy.py: new cwd is {}".format(loc), "cyan")
cprint("deploy.py: getting app sources", "green")
if self.configuration["project_download_type"] == "git":
if not reinstall:
call("git init")
call("git remote add deploy {}".format(self.configuration["git_url"]))
call("git fetch deploy")
res = call("git checkout deploy/{}".format(self.configuration["git_branch"]))
if res:
cprint("deploy.py: error: unable to clone project files. exiting.", "red")
sys.exit(1)
cprint("deploy.py: app sources downloaded, creating virtual environment")
venv.create("./.venv/", with_pip=True)
cprint("deploy.py: pretending we're in that virtualenv", "green")
cprint("deploy.py: this may break things", "yellow")
# Ungodly os.path.join.
sys.path.insert(0, os.path.join("lib", "python" + '.'.join(map(str, sys.version_info[0:2])), "site-packages"))
sys.executable = os.path.abspath("./.venv/bin/python")
cprint("deploy.py: overriding $PATH", "yellow")
os.environ["PATH"] = os.path.abspath("./.venv/bin/") + ":" + os.environ["PATH"]
cprint("deploy.py: copying deployment files to app directory...")
shutil.copy(os.path.join(original_cwd, "deploy.py"), os.path.join(os.getcwd(), "deploy.py"))
if not os.path.exists(os.path.join(os.getcwd(), "deployconf.py")):
shutil.copy(os.path.join(original_cwd, "deployconf.py"), os.path.join(os.getcwd(), "deployconf.py"))
cprint("deploy.py: switching to new interpreter...", "green")
cprint("deploy.py: this will attempt to pick up where we left off.")
executable = os.path.join(os.getcwd(), ".venv/bin/python")
print()
print()
subprocess.original_call([executable, "deploy.py", "--run-hooks"] + (["--reinstall"] if reinstall else []))
开发者ID:SunDwarf,项目名称:deploy.py,代码行数:64,代码来源:deploy_obj.py
示例18: _stage1_create_venv
def _stage1_create_venv():
# Create it in our cwd + '.venv'.
venv.create(venv_path, with_pip=True)
开发者ID:SunDwarf,项目名称:deploy.py,代码行数:3,代码来源:deploy.py
示例19: dedent
""" Enable venv and show convenience message """
import subprocess
import sys
from textwrap import dedent
try:
# python 3.2+
import venv
VIRTUALENV_AVAILABLE = True
except ImportError:
VIRTUALENV_AVAILABLE = False
if VIRTUALENV_AVAILABLE:
venv.create('.', with_pip=True)
proc = subprocess.Popen(
['bin/pip', 'install', '--upgrade', 'pip', 'setuptools'],
shell=sys.platform.startswith('win'),
cwd='.'
)
proc.wait()
proc = subprocess.Popen(
['bin/pip', 'install', '-e', '.'],
shell=sys.platform.startswith('win'),
cwd='.'
)
proc.wait()
separator = "=" * 79
msg = dedent(
开发者ID:Pylons,项目名称:substanced-cookiecutter,代码行数:31,代码来源:post_gen_project.py
示例20:
"""Python virtual environments.
See also <http://www.python.org/dev/peps/pep-0405/>.
"""
import venv
venv.create('pyvenv')
#import markdown
#print(markdown.markdown('**hello**'))
开发者ID:vlasovskikh,项目名称:whatsnew33-demo,代码行数:10,代码来源:pyvenv.py
注:本文中的venv.create函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论