Create a temporary virtualenv.
329226
def mktmpenv_cmd(argv):
    """"""
    parser = mkvirtualenv_argparser()
    env = '.'
    while (workon_home / env).exists():
        env = hex(random.getrandbits(64))[2:-1]

    args, rest = parser.parse_known_args(argv)

    mkvirtualenv(env, args.python, args.packages, requirements=args.requirements,
                 rest=rest)
    print('This is a temporary environment. It will be deleted when you exit')
    try:
        if args.activate:
            # only used for testing on windows
            shell(env)
    finally:
        return rmvirtualenvs([env])
249290
def init():
    """"""
    if not os.path.isdir('venv'):
        print(cyan('\nCreating the virtual env...'))

        local('pyvenv-3.4 venv')

        print(green('Virtual env created.'))

    print(green('Virtual Environment ready.'))
604547
def lock(
    ctx,
    state,
    **kwargs
):
    """"""
    from ..core import ensure_project, do_init, do_lock

    # Ensure that virtualenv is available.
    ensure_project(three=state.three, python=state.python, pypi_mirror=state.pypi_mirror)
    if state.installstate.requirementstxt:
        do_init(
            dev=state.installstate.dev,
            requirements=state.installstate.requirementstxt,
            pypi_mirror=state.pypi_mirror,
            pre=state.installstate.pre,
        )
    do_lock(
        ctx=ctx,
        clear=state.clear,
        pre=state.installstate.pre,
        keep_outdated=state.installstate.keep_outdated,
        pypi_mirror=state.pypi_mirror,
    )
1126140
def _maketemp(name, createmode=None):
    
    d, fn = os.path.split(name)
    fd, tempname = tempfile.mkstemp(prefix=".%s-" % fn, dir=d)
    os.close(fd)

    # Temporary files are created with mode 0600, which is usually not
    # what we want. If the original file already exists, just copy its mode.
    # Otherwise, manually obey umask.
    try:
        st_mode = os.lstat(name).st_mode & 0o777
    except OSError as err:
        if err.errno != errno.ENOENT:
            raise
        st_mode = createmode
        if st_mode is None:
            st_mode = ~umask
        st_mode &= 0o666
    os.chmod(tempname, st_mode)

    return tempname
175386
def create_env(self, interpreter, is_current, options):
        """"""
        if is_current:
            # apply pyvenv options
            pyvenv_options = options['pyvenv_options']
            if "--system-site-packages" in pyvenv_options:
                self.system_site_packages = True
            logger.debug("Creating virtualenv with pyvenv. options=%s", pyvenv_options)
            self.create(self.env_path)
        else:
            virtualenv_options = options['virtualenv_options']
            logger.debug("Creating virtualenv with virtualenv")
            self.create_with_virtualenv(interpreter, virtualenv_options)
        logger.debug("env_bin_path: %s", self.env_bin_path)

        # Re check if pip was installed (supporting both binary and .exe for Windows)
        pip_bin = os.path.join(self.env_bin_path, "pip")
        pip_exe = os.path.join(self.env_bin_path, "pip.exe")
        if not (os.path.exists(pip_bin) or os.path.exists(pip_exe)):
            logger.debug("pip isn't installed in the venv, setting pip_installed=False")
            self.pip_installed = False

        return self.env_path, self.env_bin_path, self.pip_installed
45189
def _create_tmp_file(config):
        """"""
        tmp_dir = tempfile.gettempdir()
        rand_fname = py23_compat.text_type(uuid.uuid4())
        filename = os.path.join(tmp_dir, rand_fname)
        with open(filename, 'wt') as fobj:
            fobj.write(config)
        return filename
856245
def install_deps(self, virtualenv, skip_cached=True, always_exit=False, exit_if_failed=True,
                     stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr):
        
        config = self.registered_venvs[virtualenv.venv_name]
        configed_deps = config['deps']
        for dep in configed_deps:
            if dep.startswith(FILE_PREFIX):
                dep = self._full_relative_path(dep.replace(FILE_PREFIX, ''))
                virtualenv.install_requirements_file(dep, skip_cached=skip_cached,
                                                     always_exit=always_exit,
                                                     exit_if_failed=exit_if_failed, stdin=stdin,
                                                     stdout=stdout, stderr=stderr)
            else:
                virtualenv.install_deps([dep], skip_cached=skip_cached, always_exit=always_exit,
                                        exit_if_failed=exit_if_failed, stdin=stdin,
                                        stdout=stdout, stderr=stderr)
281607
def _CreateTempDir(prefix, run_dir=None):
  
  temp_dir = tempfile.mkdtemp(prefix=prefix + '-', dir=run_dir)
  try:
    yield temp_dir
  finally:
    shutil.rmtree(temp_dir)
1124138
private function createEnv(): void
    {
        if (file_exists(base_dir('.env'))) {
            $dotEnv = new Dotenv();
            $dotEnv->load(base_dir('.env'));
            $this->env = $dotEnv;
        }
    }
287181
def ensure_virtualenv(args, return_values):
    """"""
    def adjust_options(options, args):
        # TODO-TEST: proper error message with no arguments
        venv_path = return_values.venv_path = args[0]

        if venv_path == DEFAULT_VIRTUALENV_PATH or options.prompt == '<dirname>':
            from os.path import abspath, basename, dirname
            options.prompt = '(%s)' % basename(dirname(abspath(venv_path)))
        # end of option munging.

        # there are two python interpreters involved here:
        # 1) the interpreter we're instructing virtualenv to copy
        if options.python is None:
            source_python = None
        else:
            source_python = virtualenv.resolve_interpreter(options.python)
        # 2) the interpreter virtualenv will create
        destination_python = venv_python(venv_path)

        if exists(destination_python):
            reason = invalid_virtualenv_reason(venv_path, source_python, destination_python, options)
            if reason:
                info('Removing invalidated virtualenv. (%s)' % reason)
                run(('rm', '-rf', venv_path))
            else:
                info('Keeping valid virtualenv from previous run.')
                raise SystemExit(0)  # looks good! we're done here.

    # this is actually a documented extension point:
    #   http://virtualenv.readthedocs.org/en/latest/reference.html#adjust_options
    import virtualenv
    virtualenv.adjust_options = adjust_options

    from sys import argv
    argv[:] = ('virtualenv',) + args
    info(colorize(argv))
    raise_on_failure(virtualenv.main)
    # There might not be a venv_path if doing something like "venv= --version"
    # and not actually asking virtualenv to make a venv.
    if return_values.venv_path is not None:
        run(('rm', '-rf', join(return_values.venv_path, 'local')))
561658
def install(args):
    "  "

    # Deactivate virtualenv
    if 'VIRTUAL_ENV' in environ:
        LOGGER.warning('Virtualenv enabled: %s' % environ['VIRTUAL_ENV'])

    # Install from base modules
    if args.module:
        args.src = op.join(settings.MOD_DIR, args.module)
        assert op.exists(args.src), "Not found module: %s" % args.module

    # Fix project name
    args.PROJECT = args.PROJECT.replace('-', '_')

    args.home = op.abspath(args.path)

    # Create engine
    engine = Installer(args)
    args.deploy_dir = engine.target_dir

    # Check dir exists
    assert args.info or args.repeat or args.update or not op.exists(
        engine.target_dir), "Path %s exists. Stop deploy." % args.deploy_dir

    try:
        if args.repeat:
            site = Site(engine.target_dir)
            site.run_install()
            return site

        site = engine.clone_source()
        if not site:
            return True

        engine.build(args.update)
        site.run_install()
        return site

    except (CalledProcessError, AssertionError):
        LOGGER.error("Installation failed")
        LOGGER.error("Fix errors and repeat installation with (-r) or run 'makesite uninstall %s' for cancel." % args.deploy_dir)
        raise
243536
def create_virtualenv(srcdir, datadir, preload_image, get_container_name):
    
    try:
        if docker.is_boot2docker():
            docker.data_only_container(
                get_container_name('venv'),
                ['/usr/lib/ckan'],
                )
            img_id = docker.web_command(
                '/bin/mv /usr/lib/ckan/ /usr/lib/ckan_original',
                image=preload_image,
                commit=True,
                )
            docker.web_command(
                command='/bin/cp -a /usr/lib/ckan_original/. /usr/lib/ckan/.',
                volumes_from=get_container_name('venv'),
                image=img_id,
                )
            docker.remove_image(img_id)
            return

        docker.web_command(
            command='/bin/cp -a /usr/lib/ckan/. /usr/lib/ckan_target/.',
            rw={datadir + '/venv': '/usr/lib/ckan_target'},
            image=preload_image,
            )
    finally:
        rw = {datadir + '/venv': '/usr/lib/ckan'} if not docker.is_boot2docker() else {}
        volumes_from = get_container_name('venv') if docker.is_boot2docker() else None
        # fix venv permissions
        docker.web_command(
            command='/bin/chown -R --reference=/project /usr/lib/ckan',
            rw=rw,
            volumes_from=volumes_from,
            ro={srcdir: '/project'},
            )
978670
def create_tempdir(suffix='', prefix='tmp', directory=None, delete=True):
    
    tempd = tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=directory)
    if delete:
        atexit.register(_cleanup_tempdir, tempd)
    return tempd
1237702
def tmpfile (dir=None, prefix="temp", suffix=None):
    """"""
    return tempfile.mkstemp(suffix=suffix, prefix=prefix, dir=dir)[1]
1221720
def temporary(self, path):
    """"""
    if path is None:
      raise ValueError('Can only temporarily establish a build root given a path.')
    prior = self._root_dir
    self._root_dir = path
    try:
      yield
    finally:
      self._root_dir = prior
1024415
def init():
    """"""
    print(yellow("# Setting up development environment...\n", True))
    virtualenv.init()
    virtualenv.update()
    print(green("\n# DONE.", True))
    print(green("Type ") + green("activate", True) + green(" to enable your dev virtual environment."))
361779
def generate(env):
    """"""

    env['MIDL']          = 'MIDL.EXE'
    env['MIDLFLAGS']     = SCons.Util.CLVar('/nologo')
    env['MIDLCOM']       = '$MIDL $MIDLFLAGS /tlb ${TARGETS[0]} /h ${TARGETS[1]} /iid ${TARGETS[2]} /proxy ${TARGETS[3]} /dlldata ${TARGETS[4]} $SOURCE 2> NUL'
    env['BUILDERS']['TypeLibrary'] = midl_builder