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