當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。