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


Python venv.create函数代码示例

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


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

示例1: install

def install(package: str, upgrade: bool):
    """Install a package"""
    click.echo('Installing {}'.format(package))

    if package_dir(package).exists() and not upgrade:
        click.echo('Application {} already installed, to upgrade use --upgrade'.format(package))
        exit(1)

    # Create venv
    venv_dir = package_dir(package)
    venv.create(str(venv_dir), clear=True, with_pip=True)

    # Ask pip to install the package
    try:
        call_pip(package, ['install', package])
    except subprocess.CalledProcessError as err:
        click.echo(err.output)
        # TODO remove package so far if it fails here
        exit(1)

    # Install entry-point launchers
    for entry_point_group, entry_point in get_entry_points(package):
        python_path = package_dir(package) / 'bin' / 'python'  # TODO ask setuptools for this info?
        launcher = create_launcher_text(
            package=package,
            version=entry_point.dist.version,
            entry_point=entry_point.name,
            entry_point_group=entry_point_group,
            python_path=str(python_path)
        )

        launcher_path = config['bindir'] / entry_point.name
        install_launcher(launcher_path, launcher)
开发者ID:milliams,项目名称:vam,代码行数:33,代码来源:vam.py

示例2: _setup_venv

    def _setup_venv(self):
        from stoqlib.lib.osutils import get_application_dir
        import venv

        stoqdir = get_application_dir("stoq")
        env_dir = os.path.join(stoqdir, 'venv')
        if not os.path.exists(env_dir):
            log.info('creating venv at %s', env_dir)
            if platform.system() == 'Windows':
                # On windows, pip will be included as an egg
                venv.create(env_dir, system_site_packages=True)
            else:
                venv.create(env_dir, system_site_packages=True, with_pip=True)
            log.info('creating venv done')

        # This is exactly what activate_this.py does
        old_os_path = os.environ.get('PATH', '')
        os.environ['PATH'] = os.path.join(env_dir, 'bin') + os.pathsep + old_os_path
        if sys.platform == 'win32':
            site_packages = os.path.join(env_dir, 'Lib', 'site-packages')
        else:
            site_packages = os.path.join(env_dir, 'lib', 'python%s' % sys.version[:3],
                                         'site-packages')
        prev_sys_path = list(sys.path)
        import site
        site.addsitedir(site_packages)
        sys.real_prefix = sys.prefix
        sys.prefix = env_dir
        # Move the added items to the front of the path:
        new_sys_path = []
        for item in list(sys.path):
            if item not in prev_sys_path:
                new_sys_path.append(item)
                sys.path.remove(item)
        sys.path[:0] = new_sys_path
开发者ID:hackedbellini,项目名称:stoq,代码行数:35,代码来源:bootstrap.py

示例3: create

    def create(self, name, *, system_site_packages=False, symlinks=False,
               with_pip=True):
        """Create a virtual environment in $VIRTUALENV_HOME with python3's ``venv``.

        Parameters
        ----------
        name : str
            Virtual environment name
        system_site_packages : bool
            If True, the system (global) site-packages dir is available to
            created environments.
        symlinks : bool
            If True, attempt to symlink rather than copy files into virtual
            environment.
        with_pip : bool
            If True, ensure pip is installed in the virtual environment. (Default is True)
        """
        # NOTE: clear=True is the same as delete then create.
        # NOTE: upgrade=True is its own method
        if isinstance(name, PathLike):
            env_path = fspath(name)
        else:
            env_path = os.path.join(self.venvdir, name)
        if not self._check_reserved(env_path):
            raise ValueError("venv can't contain reserved names ({})".format(', '.join(_subdir_names())))
        venv.create(
            env_path,
            system_site_packages=system_site_packages, symlinks=symlinks,
            with_pip=with_pip)
        events.vox_on_create.fire(name=name)
开发者ID:VHarisop,项目名称:xonsh,代码行数:30,代码来源:voxapi.py

示例4: create

    def create(self, name, *, system_site_packages=False, symlinks=False,
               with_pip=True):
        """Create a virtual environment in $VIRTUALENV_HOME with python3's ``venv``.

        Parameters
        ----------
        name : str
            Virtual environment name
        system_site_packages : bool
            If True, the system (global) site-packages dir is available to
            created environments.
        symlinks : bool
            If True, attempt to symlink rather than copy files into virtual
            environment.
        with_pip : bool
            If True, ensure pip is installed in the virtual environment. (Default is True)
        """
        # NOTE: clear=True is the same as delete then create.
        # NOTE: upgrade=True is its own method
        env_path = os.path.join(self.venvdir, name)
        venv.create(
            env_path,
            system_site_packages=system_site_packages, symlinks=symlinks,
            with_pip=with_pip)
        events.vox_on_create.fire(name)
开发者ID:astronouth7303,项目名称:xonsh,代码行数:25,代码来源:voxapi.py

示例5: main

def main():
    """ Execute the test.
    
    """
    @contextmanager
    def tmpdir():
        """ Enter a self-deleting temporary directory. """
        cwd = getcwd()
        tmp = mkdtemp()
        try:
            chdir(tmp)
            yield tmp
        finally:
            rmtree(tmp)
            chdir(cwd)
        return

    template = dirname(dirname(abspath(__file__)))
    defaults = load(open(join(template, "cookiecutter.json")))
    with tmpdir():
        cookiecutter(template, no_input=True)
        chdir(defaults["project_slug"])
        create("venv", with_pip=True)
        path = join("venv", "bin")
        pip = which("pip", path=path) or "pip"  # Travis CI workaround
        install = "{:s} install .".format(pip)
        for req in (join(root, "requirements.txt") for root in (".", "test")):
            # Add each requirements file to the install.
            install = " ".join((install, "--requirement={:s}".format(req)))
        pytest = which("pytest", path=path) or "pytest"  # Travis CI workaround
        test = "{:s} --verbose tests/".format(pytest)
        check_call(split(test))
        
        
    return 0
开发者ID:mdklatt,项目名称:cookiecutter-ansible-role,代码行数:35,代码来源:test_template.py

示例6: ensure_venv

    def ensure_venv(self):
        """
        Find the local venv.

        If it does not exist, create it and install requirements.
        """
        if not os.path.exists(self.venv_path):
            os.mkdir(self.venv_path)
            venv.create(self.venv_path, with_pip=True)
            self.install_requirements()
开发者ID:aquavitae,项目名称:pyle,代码行数:10,代码来源:pyle.py

示例7: do_pyvenv

def do_pyvenv(path, system_site_packages):
    try:
        import venv
    except ImportError:
        error("Standard Python 'venv' module not found", ERROR_EXCEPTION)
    # In Python >= 3.4 venv.create() has a new parameter with_pip=False
    # that allows to automatically install setuptools and pip with the module
    # ensurepip. Unfortunately, we cannot use this parameter and have to
    # bootstrap these packages ourselves, since some distributions of CPython
    # on Ubuntu don't include ensurepip.
    venv.create(path, system_site_packages=system_site_packages)
开发者ID:SeanFarrow,项目名称:intellij-community,代码行数:11,代码来源:packaging_tool.py

示例8: create_env

    def create_env(name):
        """Create a virtual environment in $VIRTUALENV_HOME with python3's ``venv``.

        Parameters
        ----------
        name : str
            Virtual environment name
        """
        env_path = os.path.join(builtins.__xonsh_env__['VIRTUALENV_HOME'], name)
        print('Creating environment...')
        venv.create(env_path, with_pip=True)
        msg = 'Environment {0!r} created. Activate it with "vox activate {0}".\n'
        print(msg.format(name))
开发者ID:Cheaterman,项目名称:xonsh,代码行数:13,代码来源:vox.py

示例9: package_source_tgz

def package_source_tgz():
    venv.create('build/pkgenv', clear=True, with_pip=True)
    print_and_do('./build/pkgenv/bin/pip install -r requirements.txt')
    print_and_do('./build/pkgenv/bin/pip freeze > build/requirements.freeze')
    app_version = MoneyGuru.VERSION
    name = 'moneyguru-src-{}.tar'.format(app_version)
    dest = op.join('build', name)
    print_and_do('git archive -o {} HEAD'.format(dest))
    print("Adding requirements.freeze and wrapping up")
    os.chdir('build')
    print_and_do('tar -rf {} requirements.freeze'.format(name))
    print_and_do('gzip {}'.format(name))
    os.chdir('..')
开发者ID:ancientHacker,项目名称:moneyguru,代码行数:13,代码来源:package.py

示例10: _create_virtualenv

    def _create_virtualenv(self):
        """Create virtualenv to install packages"""
        Pip2Pkgbuild.log.info("Preparing virtualenv")

        if os.path.exists(VENV_DIR):
            return

        venv.create(VENV_DIR,
                    with_pip=True)

        # upgrade pip
        Pip2Pkgbuild.log.info('checking for pip upgrade')
        self._exec(subprocess.check_call, [VENV_PIP, 'install', '-U', 'pip'])
开发者ID:n3f4s,项目名称:pipman,代码行数:13,代码来源:pip2pkgbuild.py

示例11: install

    def install(self):
        """Installer"""
        options = self.options

        path = [p for p in sys.path if 'parts' not in p]
        del sys.modules['site']
        sys.path[:] = path
        env = os.environ.copy()
        env['PYTHONPATH'] = ':'.join(path)

        key = 'tox-install-dir'
        if key in self.buildout['buildout']:
            install_dir = self.buildout['buildout'][key]
        elif key in self.options:
            install_dir = self.options[key]
        else:
            install_dir = join(self.buildout['buildout']['parts-directory'],
                               self.name)

        bin_bir = join(install_dir, 'bin')

        tox = join(bin_bir, 'tox')
        if not os.path.isfile(tox):
            if sys.version_info[:2] >= (3,4):
                import venv
                venv.create(install_dir, with_pip=True)
                del env['PYTHONPATH']
                subprocess.call([join(bin_bir, 'pip'), 'install', 'tox'], env=env)
            else:
                import virtualenv
                subprocess.call([sys.executable, virtualenv.__file__[:-1],
                                '-q', '--distribute', install_dir], env=env)
                del env['PYTHONPATH']
                subprocess.call([join(bin_bir, 'easy_install'), 'tox'],
                                env=env)

        from zc.recipe.egg import Scripts
        options['eggs'] = 'virtualenv'
        options['scripts'] = 'tox'
        options['entry-points'] = 'tox=os:execve'
        options['arguments'] = (
                '%(tox)r, [%(tox)r] + sys.argv[1:], os.environ'
              ) % dict(tox=tox)
        options['initialization'] = '\n'.join([
                'import os',
                "os.environ['PYTHONPATH'] = ''",
            ])
        script = Scripts(self.buildout, self.name, self.options)
        script.install()
        return tuple()
开发者ID:gawel,项目名称:gp.recipe.tox,代码行数:50,代码来源:__init__.py

示例12: create_env

    def create_env(name):
        """Create a virtual environment in $VIRTUALENV_HOME with python3's ``venv``.

        Parameters
        ----------
        name : str
            Virtual environment name
        """

        env_path = join(builtins.__xonsh_env__['VIRTUALENV_HOME'], name)

        print('Creating environment...')

        venv.create(env_path, with_pip=True)

        print('Environment "%s" created. Activate it with "vox activate %s".\n' % (name, name))
开发者ID:DNSGeek,项目名称:xonsh,代码行数:16,代码来源:vox.py

示例13: test_overwrite_existing

    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:FFMG,项目名称:myoddweb.piger,代码行数:17,代码来源:test_venv.py

示例14: create_virtualenv

def create_virtualenv(env_dir):
    notify('\nCreating virtualenv')
    res = venv.create(env_dir, system_site_packages=False, with_pip=True)
    if not res:
        proc = subprocess.run(
            ['pip', 'install', '--upgrade', 'pip'],
            env=os.environ.copy())
        if proc.returncode:
            sys.exit(proc.returncode)
        status_ok('Done')
    return res
开发者ID:crossgovernmentservices,项目名称:sue-my-brother,代码行数:11,代码来源:script_utils.py

示例15: make_virtualenv

def make_virtualenv(env):
    """ Create a virtualenv """
    if sys.version_info.major == 2:
        from urllib import urlretrieve

        if find_executable("virtualenv") is not None:
            cmd = ["virtualenv"] + [env]
            subprocess.check_call(cmd)
        else:
            # Otherwise, download virtualenv from pypi
            path = urlretrieve(VENV_URL)[0]
            subprocess.check_call(["tar", "xzf", path])
            subprocess.check_call(
                [sys.executable, "virtualenv-%s/virtualenv.py" % VENV_VERSION, env]
            )
            os.unlink(path)
            shutil.rmtree("virtualenv-%s" % VENV_VERSION)
    else:
        import venv

        venv.create(env, with_pip=True)
开发者ID:stevearc,项目名称:dotfiles,代码行数:21,代码来源:make_standalone.py


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