• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python virtualenv.create_environment函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: update_ve

    def update_ve(self, full_rebuild, force_update):

        if not path.exists(self.requirements):
            print >> sys.stderr, "Could not find requirements: file %s" % self.requirements
            return 1

        update_required = self.virtualenv_needs_update()

        if not update_required and not force_update:
            # Nothing to be done
            print "VirtualEnv does not need to be updated"
            print "use --force to force an update"
            return 0

        # if we need to create the virtualenv, then we must do that from
        # outside the virtualenv. The code inside this if statement will only
        # be run outside the virtualenv.
        if full_rebuild and path.exists(self.ve_dir):
            shutil.rmtree(self.ve_dir)
        if not path.exists(self.ve_dir):
            import virtualenv
            virtualenv.logger = virtualenv.Logger(consumers=[])
            virtualenv.create_environment(self.ve_dir, site_packages=False)

        # install the pip requirements and exit
        pip_path = path.join(self.ve_dir, 'bin', 'pip')
        # use cwd to allow relative path specs in requirements file, e.g. ../tika
        pip_retcode = subprocess.call(
                [pip_path, 'install', '--requirement=%s' % self.requirements],
                cwd=os.path.dirname(self.requirements))
        if pip_retcode == 0:
            self.update_ve_timestamp()
        return pip_retcode
开发者ID:JayFliz,项目名称:econsensus,代码行数:33,代码来源:ve_mgr.py


示例2: test_pypy_pre_import

def test_pypy_pre_import(tmp_path):
    """For PyPy, some built-in modules should be pre-imported because
    some programs expect them to be in sys.modules on startup.
    """
    check_code = inspect.getsource(check_pypy_pre_import)
    check_code = textwrap.dedent(check_code[check_code.index("\n") + 1 :])
    if six.PY2:
        check_code = check_code.decode()

    check_prog = tmp_path / "check-pre-import.py"
    check_prog.write_text(check_code)

    ve_path = str(tmp_path / "venv")
    virtualenv.create_environment(ve_path)

    bin_dir = virtualenv.path_locations(ve_path)[-1]

    try:
        cmd = [
            os.path.join(bin_dir, "{}{}".format(virtualenv.EXPECTED_EXE, ".exe" if virtualenv.IS_WIN else "")),
            str(check_prog),
        ]
        subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as exception:
        assert not exception.returncode, exception.output
开发者ID:pfmoore,项目名称:virtualenv,代码行数:25,代码来源:test_virtualenv.py


示例3: env_create

def env_create(args):
    import virtualenv

    settings = load_settings()
    
    ### Create virtualenv
    virtualenv.create_environment(settings.dir_virtualenv)
    py_reqs = ['brubeck', 'dictshield', 'ujson']

    ### Ask about preferences
    web_server = ask_webserver(settings)
    if web_server == ENV_M2:
        py_reqs.append('pyzmq')
        
    concurrency = ask_concurrency(settings)
    py_reqs.append(concurrency)
    if concurrency == ENV_GEVENT:
        py_reqs.append('cython')
    
    template_engines = ask_template_engines(settings)
    py_reqs = py_reqs + template_engines

    ### Install web server requirements
    if web_server == ENV_M2:
        install_mongrel2(settings)

    ### pip install requirements
    response = install_with_pip(py_reqs)
开发者ID:j2labs,项目名称:bpm,代码行数:28,代码来源:env.py


示例4: configure_virtualenv

def configure_virtualenv(config, python_worktree,  build_worktree=None,
                         remote_packages=None, site_packages=True):
    if not remote_packages:
        remote_packages = list()

    # create a new virtualenv
    python_worktree.config = config
    venv_path = python_worktree.venv_path
    pip = python_worktree.pip

    try:
        virtualenv.create_environment(python_worktree.venv_path,
                                      site_packages=site_packages)
    except:
        ui.error("Failed to create virtualenv")
        return

    # Install all Python projects using pip install -e .
    python_projects = python_worktree.python_projects
    for i, project in enumerate(python_projects):
        ui.info_count(i, len(python_projects),
                     ui.green, "Configuring", ui.reset, ui.blue, project.src)
        cmd = [pip, "install", "--editable", "."]
        qisys.command.call(cmd, cwd=project.path)

    # Write a qi.pth file containing path to C/C++ extensions
    if build_worktree:
        handle_extensions(venv_path, python_worktree, build_worktree)

    # Install the extension in the virtualenv
    binaries_path = virtualenv.path_locations(venv_path)[-1]
    pip_binary = os.path.join(binaries_path, "pip")
    if remote_packages:
        cmd = [pip_binary, "install"] + remote_packages
        subprocess.check_call(cmd)
开发者ID:cgestes,项目名称:qibuild,代码行数:35,代码来源:venv.py


示例5: install

    def install(self):
        # Create a new virtualenv in the temp install location
        import virtualenv
        virtualenv.create_environment(
            self.install_dir,
            site_packages=False
        )
        # chdir into the pecan source
        os.chdir(pkg_resources.get_distribution('pecan').location)

        py_exe = os.path.join(self.install_dir, 'bin', 'python')
        pecan_exe = os.path.join(self.install_dir, 'bin', 'pecan')

        # env/bin/python setup.py develop (pecan)
        subprocess.check_call([
            py_exe,
            'setup.py',
            'develop'
        ])
        # create the templated project
        os.chdir(self.install_dir)
        subprocess.check_call([pecan_exe, 'create', 'Testing123'])

        # move into the new project directory and install
        os.chdir('Testing123')
        subprocess.check_call([
            py_exe,
            'setup.py',
            'develop'
        ])
开发者ID:keitheis,项目名称:pecan,代码行数:30,代码来源:test_scaffolds.py


示例6: prepare_virtualenv

def prepare_virtualenv(packages=()):
    """
    Prepares a virtual environment.
    :rtype : VirtualEnvDescription
    """
    vroot = get_vroot()
    env_key = get_env_key(packages)
    vdir = os.path.join(vroot, env_key)

    vbin = os.path.join(vdir, ('bin', 'Scripts')[_windows])
    exe_suffix = ("", ".exe")[_windows]
    vpython = os.path.join(vbin, 'python' + exe_suffix)
    vpip = os.path.join(vbin, 'pip' + exe_suffix)
    venv_description = VirtualEnvDescription(home_dir=vdir, bin_dir=vbin, python=vpython, pip=vpip, packages=packages)

    env = get_clean_system_environment()
    env['PIP_DOWNLOAD_CACHE'] = os.path.abspath(os.path.join(vroot, "pip-download-cache"))

    # Cache environment
    done_flag_file = os.path.join(vdir, "done")
    if not os.path.exists(done_flag_file):
        if os.path.exists(vdir):
            shutil.rmtree(vdir)

        virtualenv.create_environment(vdir)

        for package_spec in packages:
            subprocess.call([vpip, "install", package_spec], env=env)

        open(done_flag_file, 'a').close()

    subprocess.call([vpython, "setup.py", "install"], env=env)

    return venv_description
开发者ID:djeebus,项目名称:teamcity-python,代码行数:34,代码来源:virtual_environments.py


示例7: run_tests

def run_tests(payload):
    #payload = get_payload(payload_id)
    job = get_current_job()

    # work out the repo_url
    repo_name = payload['repository']['name']
    owner = payload['repository']['owner']['name']
    repo_url = "[email protected]:%s/%s.git" % (owner, repo_name)

    update_progress(job, 'repo url: %s' % repo_url)
    logger.info("repo: %s" % repo_url)

    vpath = tempfile.mkdtemp(suffix="ridonkulous")

    logger.info("cloning repo %s to: %s" % (repo_url, vpath))
    update_progress(job, "cloning repo %s to: %s" % (repo_url, vpath))

    create_environment(vpath, site_packages=False)

    os.chdir(vpath)

    git.Git().clone(repo_url)
    os.chdir(os.path.join(vpath, repo_name))

    pip = "%s/bin/pip" % vpath
    #python = "%s/bin/python"
    nose = "%s/bin/nosetests" % vpath

    ret = subprocess.call(r'%s install -r requirements.txt --use-mirrors' % pip, shell=True)

    logger.info("running nose")
    ret = subprocess.call(r'%s' % nose, shell=True)
    logger.info(ret)
    update_progress(job, 'done')
    return 'ok'
开发者ID:bulkan,项目名称:ridonkulous,代码行数:35,代码来源:tasks.py


示例8: _create

 def _create(self, clear=False):
     if clear:
         self.location.rmtree()
     if self._template:
         # On Windows, calling `_virtualenv.path_locations(target)`
         # will have created the `target` directory...
         if sys.platform == 'win32' and self.location.exists:
             self.location.rmdir()
         # Clone virtual environment from template.
         self._template.location.copytree(self.location)
         self._sitecustomize = self._template.sitecustomize
         self._user_site_packages = self._template.user_site_packages
     else:
         # Create a new virtual environment.
         if self._venv_type == 'virtualenv':
             _virtualenv.create_environment(
                 self.location,
                 no_pip=True,
                 no_wheel=True,
                 no_setuptools=True,
             )
             self._fix_virtualenv_site_module()
         elif self._venv_type == 'venv':
             builder = _venv.EnvBuilder()
             context = builder.ensure_directories(self.location)
             builder.create_configuration(context)
             builder.setup_python(context)
             self.site.makedirs()
         self.sitecustomize = self._sitecustomize
         self.user_site_packages = self._user_site_packages
开发者ID:akaihola,项目名称:pip,代码行数:30,代码来源:venv.py


示例9: install

def install(package):
    if not os.path.exists('.env'):
        print('Creating virtualenv')
        create_environment('.env', never_download=True)

    print('Installing %s' % package)
    pip.main(['install', package, '-t',  os.environ['PWD'] + '/.env/lib/python2.7/site-packages/','--log-file', '.env/ppm.log'])
开发者ID:guilhermebr,项目名称:ppm,代码行数:7,代码来源:install.py


示例10: build

    def build(cls, path, key, options, force=False):
        ''' Build a virtual environment in specified path, according to given
        key and options. '''

        virtualenv.logger = virtualenv.Logger(
            [(virtualenv.Logger.level_for_integer(2), sys.stderr)])

        # a simple check that what we want to remove looks like a ve name :)
        if force and os.path.exists(path):
            if len(os.path.basename(path)) == 32:
                shutil.rmtree(path)
            else:
                raise AssertionError("Ah, you probably do not want to delete "
                                     "%s, do you?" % path)

        os.makedirs(path)
        virtualenv.create_environment(home_dir=path)
        ve = VirtualEnv(path)

        # "fix" bug in pip
        # (see: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=677801)
        if options.fix_pip:
            fragments_file = 'local/lib/python2.7/site-packages/' \
                             'pip-1.1-py2.7.egg/pip/vcs/__init__.py'
            ve.execlp("sed", "-ie",
                      "/urlparse.uses_fragment.extend(self.schemes)/d",
                      ve.local_path(fragments_file))
            ve.unlink(fragments_file + 'c')

        key.initialize(ve)

        ve.mark_as_good()

        return ve
开发者ID:whitehats,项目名称:envcacher,代码行数:34,代码来源:virtualenvcache.py


示例11: _create

    def _create(self, clear=False):
        # Create the actual virtual environment
        _virtualenv.create_environment(
            self.location,
            clear=clear,
            never_download=True,
            no_pip=True,
        )

        # Install our development version of pip install the virtual
        # environment
        cmd = [self.bin.join("python"), "setup.py", "install", "--no-compile"]
        p = subprocess.Popen(
            cmd,
            cwd=self.pip_source_dir,
            stderr=subprocess.STDOUT,
            stdout=DEVNULL,
        )
        p.communicate()
        if p.returncode != 0:
            raise subprocess.CalledProcessError(
                p.returncode,
                cmd,
                output=p.stdout,
            )
开发者ID:510908220,项目名称:pip,代码行数:25,代码来源:venv.py


示例12: create_virtual_env

def create_virtual_env(project_path, install_path):
    # remove existing virtual env if exists
    ve_path = os.path.join(project_path, cfg.VIRTUAL_ENV_PATH)
    if os.path.exists(ve_path):
        shutil.rmtree(ve_path)
    try:
        logger.info('creating virtual env')
        virtualenv.create_environment(ve_path)
    except Exception:
        logger.exception('failed to create virtualenv: ')
        raise Exception('failed to create virtualenv!')
    try:
        logger.info('installing requirements for virtualenv')
        # update pip to latest version
        run_command(['{}/ve/bin/pip'.format(project_path),
                     'install',
                     '-U',
                     'pip'])

        if not os.path.exists('{}/requirements.txt'.format(project_path)):
            logger.warning('requirements.txt not found')
            return ve_path

        run_command(['{}/ve/bin/pip'.format(project_path),
                     'install',
                     '-r',
                     '{}/requirements.txt'.format(project_path)])
        virtualenv.make_environment_relocatable(ve_path)
        fixup_scripts(install_path, ve_path)
    except Exception:
        logger.exception('failed to install requirements! error message:')
        raise Exception('fail to install requirements.')
    return ve_path
开发者ID:kinhvan017,项目名称:debpackager,代码行数:33,代码来源:general.py


示例13: __init__

    def __init__(self, binPath, profilePath, password=None):
        self.venvDir = tempfile.mkdtemp()
        self.leafName = os.path.basename(__file__)
        self.binDir = os.path.join(self.venvDir, 'bin')
        self.profilePath = profilePath
        self.password = password
        self.subproc = None

        # create the virtualenv
        virtualenv.create_environment(self.venvDir,
            site_packages=True,
            never_download=True,
            no_pip=True,
            no_setuptools=True
        )

        # copy libraries
        if sys.platform == "linux2":
            dllfiles = "*.so"
        elif sys.platform == "darwin":
            dllfiles = "*.dylib"
        elif sys.platform == "win32":
            dllfiles = "*.dll"

        files = glob.glob(os.path.join(binPath, dllfiles))
        if not len(files):
            raise Exception("Could not find libraries in " + binPath)

        for filename in files:
            shutil.copy(filename, self.binDir)

        # copy our script
        shutil.copy(__file__, self.binDir)
开发者ID:kewisch,项目名称:lightning-connector-automation,代码行数:33,代码来源:nss.py


示例14: main

def main():
    if not requirements_modified_time > environment_modified_time:
        print 'Environment already up-to-date'
        return

    import virtualenv
    import subprocess

    if path.exists(VE_ROOT):
        shutil.rmtree(VE_ROOT)
    virtualenv.logger = virtualenv.Logger(consumers=[])
    virtualenv.create_environment(VE_ROOT, site_packages=False)

    # check requirements
    if not path.exists(PIP_CACHE_ROOT):
        os.mkdir(PIP_CACHE_ROOT)

    PIP_BASE = [VE_PIP, 'install', '-q', '-i',
                'https://simple.crate.io/',
                '--extra-index-url', 'http://e.pypi.python.org/simple',
                '--download-cache=%s' % (PIP_CACHE_ROOT,),]
    for req in REQUIREMENTS:
        subprocess.call(PIP_BASE + ['-r', req])

    file(VE_TIMESTAMP, 'w').close()
开发者ID:FBK-WED,项目名称:wed-pipe,代码行数:25,代码来源:update_virtualenv.py


示例15: bootstrap

def bootstrap(folder):
    print("+- Loading pip:", end='')
    try:
        from pip.req import InstallRequirement
    except:
        print(" failed....")
        raise
    print(" done")

    try:
        print("+- Creating virtual enviroment: ", end='')
        virtualenv.create_environment(folder, site_packages=True, clear=False)
        print(" %s" % folder)
    except Exception as e:
        print(""" failed....
                - Error instanciating the virutal enviroment. This is a catastrophic failure...
                - Something is really wrong with this Python installation

                - You could try to manually install virtualenv via:
                sudo python -m pip install -U virtualenv
                """)
        raise
    else:
        return
    finally:
        pass
开发者ID:modelli,项目名称:netsapiens-devops-appchecker,代码行数:26,代码来源:install.py


示例16: test_create_environment_from_virtual_environment

def test_create_environment_from_virtual_environment(tmpdir):
    """Create virtual environment using Python from another virtual environment
    """
    venvdir = str(tmpdir / "venv")
    home_dir, lib_dir, inc_dir, bin_dir = virtualenv.path_locations(venvdir)
    virtualenv.create_environment(venvdir)
    assert not os.path.islink(os.path.join(lib_dir, "distutils"))
开发者ID:pfmoore,项目名称:virtualenv,代码行数:7,代码来源:test_virtualenv.py


示例17: test_relative_symlink

def test_relative_symlink(tmpdir):
    """ Test if a virtualenv works correctly if it was created via a symlink and this symlink is removed """

    tmpdir = str(tmpdir)
    ve_path = os.path.join(tmpdir, "venv")
    os.mkdir(ve_path)

    workdir = os.path.join(tmpdir, "work")
    os.mkdir(workdir)

    ve_path_linked = os.path.join(workdir, "venv")
    os.symlink(ve_path, ve_path_linked)

    lib64 = os.path.join(ve_path, "lib64")

    virtualenv.create_environment(ve_path_linked, symlink=True)
    if not os.path.lexists(lib64):
        # no lib 64 on this platform
        return

    assert os.path.exists(lib64)

    shutil.rmtree(workdir)

    assert os.path.exists(lib64)
开发者ID:pfmoore,项目名称:virtualenv,代码行数:25,代码来源:test_virtualenv.py


示例18: run

    def run(self):
        # generate the metadata first
        self.run_command('egg_info')

        venv_dir = self.bdist_dir

        virtualenv.create_environment(
            venv_dir,
            never_download=True,
        )

        pip_cmd = [os.path.join(venv_dir, 'bin', 'pip'), 'install', '.']
        if self.requirements:
            pip_cmd.extend(['-r', self.requirements])
        subprocess.check_call(pip_cmd)

        self.copy_file(os.path.join(self.egg_info, 'PKG-INFO'), venv_dir)

        virtualenv.make_environment_relocatable(venv_dir)

        log.info("creating '%s' and adding '%s' to it", self.venv_output,
                 venv_dir)
        mkpath(os.path.dirname(self.venv_output))

        with closing(tarfile.open(self.venv_output, 'w:gz')) as tar:
            tar.add(venv_dir, self.archive_root)

        self.distribution.dist_files.append(('bdist_venv', get_python_version(),
                                             self.venv_output))

        if not self.keep_temp:
            remove_tree(venv_dir)
开发者ID:mgood,项目名称:bdist_venv,代码行数:32,代码来源:bdist_venv.py


示例19: main

def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("env")
    ap.add_argument("-w", "--workdir", dest="workdir")
    args = ap.parse_args()
    env_path = os.path.join(ENVS_PATH, args.env)
    if not os.path.isdir(env_path):
        if raw_input("%s (for %s) does not exist. Create new virtualenv? [y/n] " % (env_path, args.env)) == "y":
            virtualenv.logger = virtualenv.Logger([(virtualenv.Logger.NOTIFY, sys.stdout)])
            virtualenv.create_environment(env_path, site_packages=True, unzip_setuptools=True)
        else:
            print "Abort."
            sys.exit(1)

    if args.workdir:
        workdir = os.path.realpath(args.workdir)
        if os.path.isdir(workdir):
            print "Setting environment %s workdir to '%s'." % (args.env, workdir)
            file(os.path.join(env_path, "workdir"), "wb").write(workdir)
    
    activation_script_path = os.environ.get("VW_ACTSCRIPT_PATH")
    if not activation_script_path:
        print "VW_ACTSCRIPT_PATH not set, not creating activation script"
    else:
        with file(activation_script_path, "wb") as actscript:
            actscript.write(gen_activation_script(env_path))
开发者ID:akx,项目名称:vw,代码行数:26,代码来源:vw-script.py


示例20: init

def init(config, args):
    """Create a new WSGI project skeleton and config."""
    
    log = logging.getLogger('kraftwerk.init')
    
    # project_root/src_root
    project_root = os.path.abspath(os.path.join(os.getcwd(), args.title))
    src_root = os.path.join(project_root, args.title)
    
    if os.path.exists(project_root) and os.listdir(project_root):
        init.parser.error("Directory exists and isn't empty")
    elif not os.path.exists(project_root):
        log.debug('makedirs %s' % project_root)
        os.makedirs(project_root)
    elif not os.path.isdir(project_root):
        init.parser.error("A file with this name already exists here and isn't a directory")
    
    log.debug('virtualenv %s/' % args.title)
    logger = virtualenv.Logger([
                 (virtualenv.Logger.level_for_integer(2), sys.stdout)])
    virtualenv.logger = logger
    virtualenv.create_environment(args.title, site_packages=True)
    
    log.debug('mkdir %s/service/' % project_root)
    os.makedirs(os.path.join(args.title, 'service'))
    log.debug('mkdir %s/static/' % project_root)
    os.makedirs(os.path.join(args.title, 'static'))
    log.debug('mkdir %s/' % src_root)
    os.makedirs(src_root)
    
    _copy_project(config, args.title, project_root)
    print "Your new project is at: %s" % project_root
开发者ID:rmoorman,项目名称:kraftwerk,代码行数:32,代码来源:commands.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python virtualenv.path_locations函数代码示例发布时间:2022-05-26
下一篇:
Python virtualenv.create_bootstrap_script函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap