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


Python venv.create方法代码示例

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


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

示例1: test_prefixes

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [as 别名]
def test_prefixes(self):
        """
        Test that the prefix values are as expected.
        """
        #check our prefixes
        self.assertEqual(sys.base_prefix, sys.prefix)
        self.assertEqual(sys.base_exec_prefix, sys.exec_prefix)

        # check a venv's prefixes
        rmtree(self.env_dir)
        self.run_with_capture(venv.create, self.env_dir)
        envpy = os.path.join(self.env_dir, self.bindir, self.exe)
        cmd = [envpy, '-c', None]
        for prefix, expected in (
            ('prefix', self.env_dir),
            ('prefix', self.env_dir),
            ('base_prefix', sys.prefix),
            ('base_exec_prefix', sys.exec_prefix)):
            cmd[2] = 'import sys; print(sys.%s)' % prefix
            p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            out, err = p.communicate()
            self.assertEqual(out.strip(), expected.encode()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:test_venv.py

示例2: test_overwrite_existing

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [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

示例3: test_upgrade

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [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

示例4: test_symlinking

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [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

示例5: create_virtualenv

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [as 别名]
def create_virtualenv(requirements_txt, directory):
    '''Helper function to create a virtualenv from a requirements.txt file

    Args:
        requirements_txt (string): text of requirements.txt to use to build virtualenv
        directory (string): directory directory of created base virtualenv
    Returns:
        None
    '''
    create(directory, with_pip=True)

    source = os.path.join(directory, 'bin', 'activate')
    with NamedTemporaryFile(suffix='txt') as fp:
        fp.write(requirements_txt.encode('utf-8'))
        command = ['source', source, '&&', 'pip', 'install', '-r', fp.name]
        subprocess.call(command) 
开发者ID:timkpaine,项目名称:paperboy,代码行数:18,代码来源:_virtualenv.py

示例6: test_prefixes

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [as 别名]
def test_prefixes(self):
        """
        Test that the prefix values are as expected.
        """
        #check our prefixes
        self.assertEqual(sys.base_prefix, sys.prefix)
        self.assertEqual(sys.base_exec_prefix, sys.exec_prefix)

        # check a venv's prefixes
        rmtree(self.env_dir)
        self.run_with_capture(venv.create, self.env_dir)
        envpy = os.path.join(self.env_dir, self.bindir, self.exe)
        cmd = [envpy, '-c', None]
        for prefix, expected in (
            ('prefix', self.env_dir),
            ('prefix', self.env_dir),
            ('base_prefix', sys.prefix),
            ('base_exec_prefix', sys.exec_prefix)):
            cmd[2] = 'import sys; print(sys.%s)' % prefix
            out, err = check_output(cmd)
            self.assertEqual(out.strip(), expected.encode()) 
开发者ID:bkerler,项目名称:android_universal,代码行数:23,代码来源:test_venv.py

示例7: _make_venv

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [as 别名]
def _make_venv(self):
        global BIN, BAT
        major, minor = self.CURRENT_PYTHON_VERSION
        if not os.path.exists(BLOGGER_CLI_VENV):
            import venv

            print("Making virtualenv in", BLOGGER_CLI_VENV)
            venv.create(BLOGGER_CLI_VENV, with_pip=True)

        windows_path = os.path.join(BLOGGER_CLI_VENV, "Scripts", "python")
        linux_path = os.path.join(BLOGGER_CLI_VENV, "bin", "python")
        new_python = windows_path if WINDOWS else linux_path
        new_pip = new_python + " -m pip"

        if self._version:
            install_cmd = new_pip + " install blogger-cli==" + self._version
        else:
            install_cmd = new_pip + " install blogger-cli"

        BIN = BIN.format(python_path=new_python)
        BAT = BAT.format(python_path=new_python, blogger_cli_bin="{blogger_cli_bin}")

        os.system(install_cmd) 
开发者ID:hemanta212,项目名称:blogger-cli,代码行数:25,代码来源:get_blogger.py

示例8: _make_venv

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [as 别名]
def _make_venv(self):
        global BIN, BAT
        if not os.path.exists(BLOGGER_CLI_VENV):
            import venv

            print("Making virtualenv in", BLOGGER_CLI_VENV)
            venv.create(BLOGGER_CLI_VENV, with_pip=True)

        windows_path = os.path.join(BLOGGER_CLI_VENV, "Scripts", "python")
        linux_path = os.path.join(BLOGGER_CLI_VENV, "bin", "python")
        new_python = windows_path if WINDOWS else linux_path
        new_pip = new_python + " -m pip"

        if self._version:
            install_cmd = new_pip + " install blogger-cli==" + self._version
        else:
            install_cmd = new_pip + " install -U blogger-cli"

        BIN = BIN.format(python_path=new_python)
        BAT = BAT.format(python_path=new_python, blogger_cli_bin="{blogger_cli_bin}")

        os.system(install_cmd) 
开发者ID:hemanta212,项目名称:blogger-cli,代码行数:24,代码来源:installation.py

示例9: create_venv

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [as 别名]
def create_venv(venv_dir: pathlib.Path, use_virtualenv: bool = False) -> None:
    """Create a new virtualenv."""
    if use_virtualenv:
        utils.print_col('$ python3 -m virtualenv {}'.format(venv_dir), 'blue')
        try:
            subprocess.run([sys.executable, '-m', 'virtualenv', venv_dir],
                           check=True)
        except subprocess.CalledProcessError as e:
            utils.print_error("virtualenv failed, exiting")
            sys.exit(e.returncode)
    else:
        utils.print_col('$ python3 -m venv {}'.format(venv_dir), 'blue')
        venv.create(str(venv_dir), with_pip=True) 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:15,代码来源:mkvenv.py

示例10: venv_dir

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [as 别名]
def venv_dir():
    import venv

    with tempfile.TemporaryDirectory() as d:
        venv.create(d)
        pwd = os.getcwd()
        os.chdir(d)
        yield d
        os.chdir(pwd) 
开发者ID:PacktPublishing,项目名称:pytest-Quick-Start-Guide,代码行数:11,代码来源:test_auto.py

示例11: test_defaults

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [as 别名]
def test_defaults(self):
        """
        Test the create function with default arguments.
        """
        rmtree(self.env_dir)
        self.run_with_capture(venv.create, self.env_dir)
        self.isdir(self.bindir)
        self.isdir(self.include)
        self.isdir(*self.lib)
        # Issue 21197
        p = self.get_env_file('lib64')
        conditions = ((struct.calcsize('P') == 8) and (os.name == 'posix') and
                      (sys.platform != 'darwin'))
        if conditions:
            self.assertTrue(os.path.islink(p))
        else:
            self.assertFalse(os.path.exists(p))
        data = self.get_text_file_contents('pyvenv.cfg')
        if sys.platform == 'darwin' and ('__PYVENV_LAUNCHER__'
                                         in os.environ):
            executable =  os.environ['__PYVENV_LAUNCHER__']
        else:
            executable = sys.executable
        path = os.path.dirname(executable)
        self.assertIn('home = %s' % path, data)
        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,代码行数:33,代码来源:test_venv.py

示例12: test_unoverwritable_fails

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [as 别名]
def test_unoverwritable_fails(self):
        #create a file clashing with directories in the env dir
        for paths in self.ENV_SUBDIRS[:3]:
            fn = os.path.join(self.env_dir, *paths)
            with open(fn, 'wb') as f:
                f.write(b'')
            self.assertRaises((ValueError, OSError), venv.create, self.env_dir)
            self.clear_directory(self.env_dir) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_venv.py

示例13: test_executable

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [as 别名]
def test_executable(self):
        """
        Test that the sys.executable value is as expected.
        """
        rmtree(self.env_dir)
        self.run_with_capture(venv.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,代码行数:14,代码来源:test_venv.py

示例14: test_executable_symlinks

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [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

示例15: test_no_pip_by_default

# 需要导入模块: import venv [as 别名]
# 或者: from venv import create [as 别名]
def test_no_pip_by_default(self):
        rmtree(self.env_dir)
        self.run_with_capture(venv.create, self.env_dir)
        self.assert_pip_not_installed() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_venv.py


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