本文整理汇总了Python中virtualenv.path_locations函数的典型用法代码示例。如果您正苦于以下问题:Python path_locations函数的具体用法?Python path_locations怎么用?Python path_locations使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了path_locations函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_virtualenv
def create_virtualenv(where=None, distribute=False, **kw):
"""
Create a virtual Python environment for testing purposes. If
distribute is True, installs the distribute package in place of
setuptools.
Returns the directory of the environment itself, its Python
library directory (which contains site-packages), its 'include'
and binary file directory (bin, or on windows, Scripts)
respectively. Additional keyword arguments are passed to mkdtemp
to create the virtual environment directory.
"""
save_argv = sys.argv
if not where:
where = mkdtemp(**kw)
try:
import virtualenv
distribute_opt = ['--distribute'] if distribute else []
sys.argv = ['virtualenv', '--quiet'] + distribute_opt + ['--no-site-packages', '--unzip-setuptools', where]
virtualenv.main()
finally:
sys.argv = save_argv
return virtualenv.path_locations(where)
示例2: 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)
示例3: __init__
def __init__(self, base_path, *args, **kwargs):
# Make our base_path a test.lib.path.Path object
base_path = Path(base_path)
# Store paths related to the virtual environment
_virtualenv = kwargs.pop("virtualenv")
venv, lib, include, bin = virtualenv.path_locations(_virtualenv)
self.venv_path = venv
self.lib_path = lib
self.include_path = include
self.bin_path = bin
if hasattr(sys, "pypy_version_info"):
self.site_packages_path = self.venv_path.join("site-packages")
else:
self.site_packages_path = self.lib_path.join("site-packages")
self.user_base_path = self.venv_path.join("user")
self.user_bin_path = self.user_base_path.join(self.bin_path - self.venv_path)
self.user_site_path = self.venv_path.join(
"user",
site.USER_SITE[len(site.USER_BASE) + 1:],
)
# Create a Directory to use as a scratch pad
self.scratch_path = base_path.join("scratch").mkdir()
# Set our default working directory
kwargs.setdefault("cwd", self.scratch_path)
# Setup our environment
environ = kwargs.get("environ")
if environ is None:
environ = os.environ.copy()
environ["PIP_LOG_FILE"] = base_path.join("pip-log.txt")
environ["PATH"] = Path.pathsep.join(
[self.bin_path] + [environ.get("PATH", [])],
)
environ["PYTHONUSERBASE"] = self.user_base_path
# Writing bytecode can mess up updated file detection
environ["PYTHONDONTWRITEBYTECODE"] = "1"
kwargs["environ"] = environ
# Call the TestFileEnvironment __init__
super(PipTestEnvironment, self).__init__(base_path, *args, **kwargs)
# Expand our absolute path directories into relative
for name in ["base", "venv", "lib", "include", "bin", "site_packages",
"user_base", "user_site", "user_bin", "scratch"]:
real_name = "%s_path" % name
setattr(self, name, getattr(self, real_name) - self.base_path)
# Ensure the tmp dir exists, things break horribly if it doesn't
self.temp_path.mkdir()
# create easy-install.pth in user_site, so we always have it updated
# instead of created
self.user_site_path.makedirs()
self.user_site_path.join("easy-install.pth").touch()
示例4: env_prefix
def env_prefix(self):
return ". '{{prefix}}{0}activate' &&".format(
virtualenv.path_locations(
helpers.environment_dir(ENVIRONMENT_DIR, self.language_version)
)[-1].rstrip(os.sep) + os.sep,
'activate',
)
示例5: version_exe
def version_exe(venv, exe_name):
_, _, _, bin_dir = virtualenv.path_locations(str(venv))
exe = os.path.join(bin_dir, exe_name)
script = "import sys; import json; print(json.dumps(dict(v=list(sys.version_info), e=sys.executable)))"
cmd = [exe, "-c", script]
out = json.loads(subprocess.check_output(cmd, universal_newlines=True))
return out["v"], out["e"]
示例6: create_env
def create_env():
if env_exists():
raise Exception('Virtual environment already exists.')
log('Creating virtual environment...')
home_dir, lib_dir, inc_dir, bin_dir = venv.path_locations(ENV_PATH)
python_loc = venv.install_python(
home_dir,
lib_dir,
inc_dir,
bin_dir,
site_packages=False,
clear=False,
symlink=True
)
python_abs_loc = os.path.abspath(python_loc)
venv.install_activate(home_dir, bin_dir)
venv.install_wheel(['setuptools', 'pip'], python_abs_loc, None)
venv.install_distutils(home_dir)
log('Installing requirements...')
req_cmd = '{0}/bin/pip install {1}'.format(
ENV_PATH,
get_config().requirements
)
execute_under_env(req_cmd)
log('Virtual environment created!')
示例7: test_create_environment_from_virtual_environment
def test_create_environment_from_virtual_environment(tmpdir):
"""Create virtual environment using Python from another virtual environment
"""
venvdir = str(tmpdir / "venv")
home_dir, lib_dir, inc_dir, bin_dir = virtualenv.path_locations(venvdir)
virtualenv.create_environment(venvdir)
assert not os.path.islink(os.path.join(lib_dir, "distutils"))
示例8: handle_pure_python
def handle_pure_python(venv_path, python_worktree, env=None):
""" Add the paths of all python projects to the virtualenv """
lib_path = virtualenv.path_locations(venv_path)[1]
qi_pth_dest = os.path.join(venv_path, lib_path, "site-packages/qi.pth")
res = True
with open(qi_pth_dest, "w") as fp:
fp.write("")
for i, project in enumerate(python_worktree.python_projects):
ui.info_count(i, len(python_worktree.python_projects),
ui.blue, project.name)
if project.setup_with_distutils:
cmd = [python_worktree.pip, "install"]
if not ui.CONFIG["verbose"]:
cmd.append("--quiet")
cmd.extend(["--editable", "."])
rc = qisys.command.call(cmd, cwd=project.path, ignore_ret_code=True,
env=env)
if rc != 0:
ui.warning("Failed to run pip install on", project.src)
res = False
else:
ui.debug("Adding python path for project", project.name, ":\n",
project.python_path)
for path in project.python_path:
fp.write(path + "\n")
return res
示例9: 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
示例10: env_prefix
def env_prefix(self):
return ". '{{prefix}}{0}activate' &&".format(
virtualenv.path_locations(
ENVIRONMENT_DIR,
)[-1].rstrip(os.sep) + os.sep,
'activate',
)
示例11: handle_extensions
def handle_extensions(venv_path, python_worktree, build_worktree):
""" Check if there is a build project matching the given source, and
add the correct path to the virtualenv
"""
extensions_projects = list()
build_projects = build_worktree.build_projects
for project in python_worktree.python_projects:
parent_project = qisys.parsers.find_parent_project(build_projects,
project.path)
if parent_project:
extensions_projects.append(parent_project)
to_write = ""
for project in extensions_projects:
qi_pth_src = os.path.join(project.sdk_directory, "qi.pth")
if os.path.exists(qi_pth_src):
with open(qi_pth_src, "r") as fp:
to_write += fp.read()
if not to_write.endswith("\n"):
to_write += "\n"
lib_path = virtualenv.path_locations(venv_path)[1]
qi_pth_dest = os.path.join(venv_path, lib_path, "site-packages/qi.pth")
with open(qi_pth_dest, "a") as fp:
fp.write(to_write)
示例12: create_virtualenv
def create_virtualenv(where, distribute=False):
import virtualenv
if sys.version_info[0] > 2:
distribute = True
virtualenv.create_environment(
where, use_distribute=distribute, unzip_setuptools=True)
return virtualenv.path_locations(where)
示例13: configure_virtualenv
def configure_virtualenv(config, python_worktree, build_worktree=None,
remote_packages=None, site_packages=True):
""" Main entry point. Called by ``qipy bootstrap``
:param: remote_packages List of third-party packages to add in the virtualenv
:param: site_packages Allow access to global site packages
"""
ui.info(ui.green, "Configuring virtualenv for", ui.reset, ui.bold, python_worktree.root)
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 False
ui.info("Adding python projects")
# Write a qi.pth file containing path to C/C++ extensions and
# path to pure python modules or packages
pure_python_ok = handle_pure_python(venv_path, python_worktree)
if build_worktree:
handle_extensions(venv_path, python_worktree, build_worktree)
ui.info("Adding other requirements: " + ", ".join(remote_packages))
binaries_path = virtualenv.path_locations(venv_path)[-1]
pip_binary = os.path.join(binaries_path, "pip")
remote_ok = True
if remote_packages:
cmd = [pip_binary, "install"] + remote_packages
rc = qisys.command.call(cmd, ignore_ret_code=True)
remote_ok = (rc == 0)
if pure_python_ok and remote_ok:
ui.info(ui.green, "Done")
if not pure_python_ok:
ui.info(ui.red, "Failed to add some python projects")
if not remote_ok:
ui.info(ui.red, "Failed to add some third party requirements")
requirements_ok = True
for project in python_worktree.python_projects:
path = os.path.join(project.path, "requirements.txt")
if os.path.isfile( path ):
ui.info(ui.green, " * Installing dependencies from " + path)
cmd = [pip_binary, "install", "--requirement", path]
rc = qisys.command.call(cmd, ignore_ret_code=True)
requirements_ok = (rc == 0)
else:
ui.debug(ui.yellow, " * missing " + path)
return (pure_python_ok and remote_ok and requirements_ok)
示例14: do
def do(args):
build_worktree = qibuild.parsers.get_build_worktree(args)
env = build_worktree.get_env()
build_config = qibuild.parsers.get_build_config(build_worktree, args)
worktree = build_worktree.worktree
cmd = args.command
venvs_path = os.path.join(worktree.dot_qi,
"venvs")
name = build_config.build_directory("py")
venv_root = os.path.join(venvs_path, name)
if not os.path.exists(venv_root):
err = "No Virtualenv found in %s\n" % (venv_root)
err += "Please run `qipy bootstrap`"
raise Exception(err)
binaries_path = virtualenv.path_locations(venv_root)[-1]
if args.dolist:
for f in sorted(os.listdir(binaries_path)):
if os.path.isfile(os.path.join(binaries_path, f)):
print f
return
if not cmd:
cmd = ["ipython"]
if os.path.exists(cmd[0]):
# Assume it is a script we want to run
python_path = os.path.join(binaries_path, "python")
cmd.insert(0, python_path)
else:
script_path = qipy.venv.find_script(venv_root, cmd[0])
if script_path:
cmd[0] = script_path
lib_path = virtualenv.path_locations(venv_root)[1]
env["PYTHONHOME"] = venv_root
env["PYTHONPATH"] = os.path.join(lib_path, "site-packages")
if args.exec_:
ui.debug("exec", cmd)
os.execve(cmd[0], cmd, env)
else:
qisys.command.call(cmd, env=env)
示例15: get_paths
def get_paths(name):
_, lib_dir, inc_dir, bin_dir = virtualenv.path_locations(name)
venv_home = get_venv_home()
home_dir = get_env_home(name)
lib_dir = os.path.join(venv_home, lib_dir)
pkg_dir = os.path.join(lib_dir, 'site-packages')
inc_dir = os.path.join(venv_home, inc_dir)
bin_dir = os.path.join(venv_home, bin_dir)
return home_dir, lib_dir, pkg_dir, inc_dir, bin_dir