• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python virtualenv.path_locations函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中virtualenv.path_locations函数的典型用法代码示例。如果您正苦于以下问题:Python path_locations函数的具体用法?Python path_locations怎么用?Python path_locations使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了path_locations函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:diosmosis,项目名称:ryppl,代码行数:26,代码来源:testutil.py


示例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)
开发者ID:cgestes,项目名称:qibuild,代码行数:35,代码来源:venv.py


示例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()
开发者ID:1stvamp,项目名称:pip,代码行数:60,代码来源:__init__.py


示例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',
     )
开发者ID:hitul007,项目名称:pre-commit,代码行数:7,代码来源:python.py


示例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"]
开发者ID:pfmoore,项目名称:virtualenv,代码行数:7,代码来源:test_zipapp.py


示例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!')
开发者ID:sdoumbouya,项目名称:ansible-flow,代码行数:31,代码来源:venv.py


示例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"))
开发者ID:pfmoore,项目名称:virtualenv,代码行数:7,代码来源:test_virtualenv.py


示例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
开发者ID:aldebaran,项目名称:qibuild,代码行数:26,代码来源:venv.py


示例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
开发者ID:pfmoore,项目名称:virtualenv,代码行数:25,代码来源:test_virtualenv.py


示例10: env_prefix

 def env_prefix(self):
     return ". '{{prefix}}{0}activate' &&".format(
         virtualenv.path_locations(
             ENVIRONMENT_DIR,
         )[-1].rstrip(os.sep) + os.sep,
         'activate',
     )
开发者ID:MMontgomeryII,项目名称:pre-commit,代码行数:7,代码来源:python.py


示例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)
开发者ID:cameronyoyos,项目名称:qibuild,代码行数:26,代码来源:venv.py


示例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)
开发者ID:ecolitan,项目名称:snakebasket,代码行数:8,代码来源:test_pip.py


示例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)
开发者ID:houssemkouki,项目名称:qibuild,代码行数:58,代码来源:venv.py


示例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)
开发者ID:Phlogistique,项目名称:qibuild,代码行数:45,代码来源:run.py


示例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
开发者ID:rocktavious,项目名称:pyul,代码行数:9,代码来源:envUtils.py


示例16: __init__

    def __init__(self, source, venv=None):
        self.dir_source = source
        if not venv:
            base, source_name = os.path.split(source)
            venv = os.path.join(base, 'venv-{}-{}'.format(source_name, os.path.basename(sys.executable)))

        venv_home, venv_lib, venv_inc, venv_bin = virtualenv.path_locations(venv)
        self.dir_venv = venv_home
        self.dir_venv_bin = venv_bin
开发者ID:rciorba,项目名称:moin-2.0-mirror,代码行数:9,代码来源:quickinstall.py


示例17: add_virtualenv_path

def add_virtualenv_path(venv=os.getenv('VIRTUAL_ENV')):
    """Add virtualenv's site-packages to `sys.path`."""
    if not venv:
        return
    import virtualenv
    venv = os.path.abspath(venv)
    home_dir, lib_dir, inc_dir, bin_dir = virtualenv.path_locations(venv)
    path = os.path.join(lib_dir, 'site-packages')
    sys.path.insert(0, path)
    site.addsitedir(path)
开发者ID:t2psyto,项目名称:emacs-jedi,代码行数:10,代码来源:jediepcserver.py


示例18: __init__

    def __init__(self, location, *args, **kwargs):
        self.location = Path(location)
        self.pip_source_dir = kwargs.pop("pip_source_dir")
        self._system_site_packages = kwargs.pop("system_site_packages", False)

        home, lib, inc, bin = _virtualenv.path_locations(self.location)
        self.lib = Path(lib)
        self.bin = Path(bin)

        super(VirtualEnvironment, self).__init__(*args, **kwargs)
开发者ID:fpytloun,项目名称:pip,代码行数:10,代码来源:venv.py


示例19: create_virtualenv

def create_virtualenv(where):
    save_argv = sys.argv
    
    try:
        import virtualenv
        sys.argv = ['virtualenv', '--quiet', '--no-site-packages', where]
        virtualenv.main()
    finally: 
        sys.argv = save_argv

    return virtualenv.path_locations(where)
开发者ID:dabrahams,项目名称:pip,代码行数:11,代码来源:test_pip.py


示例20: _update_paths

 def _update_paths(self):
     home, lib, inc, bin = _virtualenv.path_locations(self.location)
     self.bin = Path(bin)
     self.site = Path(lib) / 'site-packages'
     # Workaround for https://github.com/pypa/virtualenv/issues/306
     if hasattr(sys, "pypy_version_info"):
         version_fmt = '{0}' if six.PY3 else '{0}.{1}'
         version_dir = version_fmt.format(*sys.version_info)
         self.lib = Path(home, 'lib-python', version_dir)
     else:
         self.lib = Path(lib)
开发者ID:akaihola,项目名称:pip,代码行数:11,代码来源:venv.py



注:本文中的virtualenv.path_locations函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.VirtualFolder类代码示例发布时间:2022-05-26
下一篇:
Python virtualenv.create_environment函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap