当前位置: 首页>>代码示例>>Python>>正文


Python venv.EnvBuilder方法代码示例

本文整理汇总了Python中venv.EnvBuilder方法的典型用法代码示例。如果您正苦于以下问题:Python venv.EnvBuilder方法的具体用法?Python venv.EnvBuilder怎么用?Python venv.EnvBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在venv的用法示例。


在下文中一共展示了venv.EnvBuilder方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_overwrite_existing

# 需要导入模块: import venv [as 别名]
# 或者: from venv import EnvBuilder [as 别名]
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:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_venv.py

示例2: test_upgrade

# 需要导入模块: import venv [as 别名]
# 或者: from venv import EnvBuilder [as 别名]
def test_upgrade(self):
        """
        Test upgrading an existing environment directory.
        """
        # See Issue #21643: the loop needs to run twice to ensure
        # that everything works on the upgrade (the first run just creates
        # the venv).
        for upgrade in (False, True):
            builder = venv.EnvBuilder(upgrade=upgrade)
            self.run_with_capture(builder.create, self.env_dir)
            self.isdir(self.bindir)
            self.isdir(self.include)
            self.isdir(*self.lib)
            fn = self.get_env_file(self.bindir, self.exe)
            if not os.path.exists(fn):
                # diagnostics for Windows buildbot failures
                bd = self.get_env_file(self.bindir)
                print('Contents of %r:' % bd)
                print('    %r' % os.listdir(bd))
            self.assertTrue(os.path.exists(fn), 'File %r should exist.' % fn) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:test_venv.py

示例3: test_symlinking

# 需要导入模块: import venv [as 别名]
# 或者: from venv import EnvBuilder [as 别名]
def test_symlinking(self):
        """
        Test symlinking works as expected
        """
        for usl in (False, True):
            builder = venv.EnvBuilder(clear=True, symlinks=usl)
            builder.create(self.env_dir)
            fn = self.get_env_file(self.bindir, self.exe)
            # Don't test when False, because e.g. 'python' is always
            # symlinked to 'python3.3' in the env, even when symlinking in
            # general isn't wanted.
            if usl:
                self.assertTrue(os.path.islink(fn))

    # If a venv is created from a source build and that venv is used to
    # run the test, the pyvenv.cfg in the venv created in the test will
    # point to the venv being used to run the test, and we lose the link
    # to the source build - so Python can't initialise properly. 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_venv.py

示例4: build_venv

# 需要导入模块: import venv [as 别名]
# 或者: from venv import EnvBuilder [as 别名]
def build_venv(
        cls, path, executable=None
    ):  # type: (Union[Path,str], Optional[str]) -> ()
        if executable is not None:
            # Create virtualenv by using an external executable
            try:
                p = subprocess.Popen(
                    list_to_shell_command([executable, "-"]),
                    stdin=subprocess.PIPE,
                    shell=True,
                )
                p.communicate(encode(CREATE_VENV_COMMAND.format(path)))
            except CalledProcessError as e:
                raise EnvCommandError(e)

            return

        try:
            from venv import EnvBuilder

            # use the same defaults as python -m venv
            if os.name == "nt":
                use_symlinks = False
            else:
                use_symlinks = True

            builder = EnvBuilder(with_pip=True, symlinks=use_symlinks)
            builder.create(str(path))
        except ImportError:
            try:
                # We fallback on virtualenv for Python 2.7
                from virtualenv import create_environment

                create_environment(str(path))
            except ImportError:
                # since virtualenv>20 we have to use cli_run
                from virtualenv import cli_run

                cli_run([str(path)]) 
开发者ID:python-poetry,项目名称:poetry,代码行数:41,代码来源:env.py

示例5: test_isolation

# 需要导入模块: import venv [as 别名]
# 或者: from venv import EnvBuilder [as 别名]
def test_isolation(self):
        """
        Test isolation from system site-packages
        """
        for ssp, s in ((True, 'true'), (False, 'false')):
            builder = venv.EnvBuilder(clear=True, system_site_packages=ssp)
            builder.create(self.env_dir)
            data = self.get_text_file_contents('pyvenv.cfg')
            self.assertIn('include-system-site-packages = %s\n' % s, data) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_venv.py

示例6: test_executable_symlinks

# 需要导入模块: import venv [as 别名]
# 或者: from venv import EnvBuilder [as 别名]
def test_executable_symlinks(self):
        """
        Test that the sys.executable value is as expected.
        """
        rmtree(self.env_dir)
        builder = venv.EnvBuilder(clear=True, symlinks=True)
        builder.create(self.env_dir)
        envpy = os.path.join(os.path.realpath(self.env_dir), self.bindir, self.exe)
        cmd = [envpy, '-c', 'import sys; print(sys.executable)']
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        out, err = p.communicate()
        self.assertEqual(out.strip(), envpy.encode()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:test_venv.py

示例7: setup_python_venv

# 需要导入模块: import venv [as 别名]
# 或者: from venv import EnvBuilder [as 别名]
def setup_python_venv(self, anarchy_run):
        requirements = anarchy_run['spec'].get('pythonRequirements', None)
        if not requirements:
            return None
        requirements_md5 = hashlib.md5(requirements.encode('utf-8')).hexdigest()
        virtual_env = self.ansible_private_dir + '/pythonvenv-' + requirements_md5
        requirements_file = virtual_env + '/requirements.txt'
        if not os.path.exists(virtual_env):
            venv.EnvBuilder(system_site_packages=True, with_pip=True).create(virtual_env)
            with open(requirements_file, 'w') as fh:
                fh.write(requirements)
            env = os.environ.copy()
            env['VIRTUAL_ENV'] = virtual_env
            env['PATH'] = '{}/bin:{}'.format(virtual_env, env['PATH'])
            subprocess.run(
                [virtual_env + '/bin/pip3', 'install', '-r', requirements_file],
                check=True, env=env
            )
            if not os.path.exists(virtual_env + '/bin/ansible-playbook'):
                with open(virtual_env + '/bin/ansible-playbook', 'w') as ofh:
                    ofh.write("#!{}/bin/python\n".format(virtual_env))
                    with open(shutil.which('ansible-playbook')) as ifh:
                        ofh.write(ifh.read())
                os.chmod(virtual_env + '/bin/ansible-playbook', 0o755)

        return virtual_env 
开发者ID:redhat-cop,项目名称:anarchy,代码行数:28,代码来源:anarchy-runner.py

示例8: test_create_system_site_pkgs_pyvenv

# 需要导入模块: import venv [as 别名]
# 或者: from venv import EnvBuilder [as 别名]
def test_create_system_site_pkgs_pyvenv(self):
        env_builder = envbuilder._FadesEnvBuilder()
        interpreter = 'python3'
        is_current = True
        options = {"virtualenv_options": [],
                   "pyvenv_options": ['--system-site-packages'],
                   }
        with patch.object(EnvBuilder, 'create') as mock_create:
            env_builder.create_env(interpreter, is_current, options)
            self.assertTrue(env_builder.system_site_packages)
            self.assertTrue(mock_create.called) 
开发者ID:PyAr,项目名称:fades,代码行数:13,代码来源:test_envbuilder.py

示例9: test_create_pyvenv

# 需要导入模块: import venv [as 别名]
# 或者: from venv import EnvBuilder [as 别名]
def test_create_pyvenv(self):
        env_builder = envbuilder._FadesEnvBuilder()
        interpreter = 'python3'
        is_current = True
        options = {"virtualenv_options": [],
                   "pyvenv_options": [],
                   }
        with patch.object(EnvBuilder, 'create') as mock_create:
            env_builder.create_env(interpreter, is_current, options)
            self.assertFalse(env_builder.system_site_packages)
            self.assertTrue(mock_create.called) 
开发者ID:PyAr,项目名称:fades,代码行数:13,代码来源:test_envbuilder.py

示例10: test_prompt

# 需要导入模块: import venv [as 别名]
# 或者: from venv import EnvBuilder [as 别名]
def test_prompt(self):
        env_name = os.path.split(self.env_dir)[1]

        builder = venv.EnvBuilder()
        context = builder.ensure_directories(self.env_dir)
        self.assertEqual(context.prompt, '(%s) ' % env_name)

        builder = venv.EnvBuilder(prompt='My prompt')
        context = builder.ensure_directories(self.env_dir)
        self.assertEqual(context.prompt, '(My prompt) ') 
开发者ID:bkerler,项目名称:android_universal,代码行数:12,代码来源:test_venv.py

示例11: test_unicode_in_batch_file

# 需要导入模块: import venv [as 别名]
# 或者: from venv import EnvBuilder [as 别名]
def test_unicode_in_batch_file(self):
        """
        Test handling of Unicode paths
        """
        rmtree(self.env_dir)
        env_dir = os.path.join(os.path.realpath(self.env_dir), 'ϼўТλФЙ')
        builder = venv.EnvBuilder(clear=True)
        builder.create(env_dir)
        activate = os.path.join(env_dir, self.bindir, 'activate.bat')
        envpy = os.path.join(env_dir, self.bindir, self.exe)
        out, err = check_output(
            [activate, '&', self.exe, '-c', 'print(0)'],
            encoding='oem',
        )
        self.assertEqual(out.strip(), '0') 
开发者ID:bkerler,项目名称:android_universal,代码行数:17,代码来源:test_venv.py


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