How to use the virtualenv.logger function in virtualenv

To help you get started, we’ve selected a few virtualenv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github warner / python-versioneer / test / git / test_invocations.py View on Github external
os.mkdir(self.subpath("venvs"))
        venv_dir = self.subpath("venvs/%s" % mode)
        # python3 on OS-X uses a funky two-part executable and an environment
        # variable to communicate between them. If this variable is still set
        # by the time a virtualenv's 'pip' or 'python' is run, and if that
        # command spawns another sys.executable underneath it, that second
        # child may use the wrong python, and can install things into the
        # real system library instead of the virtualenv. Invoking
        # virtualenv.create_environment() clears this as a side-effect, but
        # to make things safe I'll just clear this now. See
        # https://github.com/pypa/virtualenv/issues/322 and
        # https://bugs.python.org/issue22490 for some hints. I tried
        # switching to 'venv' on py3, but only py3.4 includes pip, and even
        # then it's an ancient version.
        os.environ.pop("__PYVENV_LAUNCHER__", None)
        virtualenv.logger = virtualenv.Logger([]) # hush
        # virtualenv causes DeprecationWarning/ResourceWarning on py3
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            virtualenv.create_environment(venv_dir)
        return venv_dir
github ryppl / __legacy / pip.py View on Github external
def restart_in_venv(venv, args):
    """
    Restart this script using the interpreter in the given virtual environment
    """
    venv = os.path.abspath(venv)
    if not os.path.exists(venv):
        try:
            import virtualenv
        except ImportError:
            print 'The virtual environment does not exist: %s' % venv
            print 'and virtualenv is not installed, so a new environment cannot be created'
            sys.exit(3)
        print 'Creating new virtualenv environment in %s' % venv
        virtualenv.logger = logger
        logger.indent += 2
        ## FIXME: always have no_site_packages?
        virtualenv.create_environment(venv, site_packages=False)
    if sys.platform == 'win32':
        python = os.path.join(venv, 'Scripts', 'python')
    else:
        python = os.path.join(venv, 'bin', 'python')
    if not os.path.exists(python):
        python = venv
    if not os.path.exists(python):
        raise BadCommand('Cannot find virtual environment interpreter at %s' % python)
    base = os.path.dirname(os.path.dirname(python))
    file = __file__
    if file.endswith('.pyc'):
        file = file[:-1]
    os.execv(python, [python, file] + args + [base, '___VENV_RESTART___'])
github pypa / pip / pip / venv.py View on Github external
#    a relative one makes no sense (or does it?)
        if os.path.isabs(base):
            venv = os.path.join(base, venv)

    if venv.startswith('~'):
        venv = os.path.expanduser(venv)

    if not os.path.exists(venv):
        try:
            import virtualenv
        except ImportError:
            print('The virtual environment does not exist: %s' % venv)
            print('and virtualenv is not installed, so a new environment cannot be created')
            sys.exit(3)
        print('Creating new virtualenv environment in %s' % venv)
        virtualenv.logger = logger
        logger.indent += 2
        virtualenv.create_environment(venv, site_packages=site_packages)
    if sys.platform == 'win32':
        python = os.path.join(venv, 'Scripts', 'python.exe')
        # check for bin directory which is used in buildouts
        if not os.path.exists(python):
            python = os.path.join(venv, 'bin', 'python.exe')
    else:
        python = os.path.join(venv, 'bin', 'python')
    if not os.path.exists(python):
        python = venv
    if not os.path.exists(python):
        raise BadCommand('Cannot find virtual environment interpreter at %s' % python)
    base = os.path.dirname(os.path.dirname(python))
    file = os.path.join(os.path.dirname(__file__), 'runner.py')
    if file.endswith('.pyc'):
github pypa / pip / pip.py View on Github external
def restart_in_venv(venv, args):
    """
    Restart this script using the interpreter in the given virtual environment
    """
    venv = os.path.abspath(venv)
    if not os.path.exists(venv):
        try:
            import virtualenv
        except ImportError:
            print 'The virtual environment does not exist: %s' % venv
            print 'and virtualenv is not installed, so a new environment cannot be created'
            sys.exit(3)
        print 'Creating new virtualenv environment in %s' % venv
        virtualenv.logger = logger
        logger.indent += 2
        ## FIXME: always have no_site_packages?
        virtualenv.create_environment(venv, site_packages=False)
    if sys.platform == 'win32':
        python = os.path.join(venv, 'Scripts', 'python')
    else:
        python = os.path.join(venv, 'bin', 'python')
    if not os.path.exists(python):
        python = venv
    if not os.path.exists(python):
        raise BadCommand('Cannot find virtual environment interpreter at %s' % python)
    base = os.path.dirname(os.path.dirname(python))
    os.execv(python, [python, __file__] + args + [base, '___VENV_RESTART___'])
github pypa / pip / pip.py View on Github external
def restart_in_venv(venv, args):
    """
    Restart this script using the interpreter in the given virtual environment
    """
    venv = os.path.abspath(venv)
    if not os.path.exists(venv):
        try:
            import virtualenv
        except ImportError:
            print 'The virtual environment does not exist: %s' % venv
            print 'and virtualenv is not installed, so a new environment cannot be created'
            sys.exit(3)
        print 'Creating new virtualenv environment in %s' % venv
        virtualenv.logger = logger
        logger.indent += 2
        ## FIXME: always have no_site_packages?
        virtualenv.create_environment(venv, site_packages=False)
    if sys.platform == 'win32':
        python = os.path.join(venv, 'Scripts', 'python')
    else:
        python = os.path.join(venv, 'bin', 'python')
    if not os.path.exists(python):
        python = venv
    if not os.path.exists(python):
        raise BadCommand('Cannot find virtual environment interpreter at %s' % python)
    base = os.path.dirname(os.path.dirname(python))
    os.execv(python, [python, __file__] + args + [base, '___VENV_RESTART___'])
github apache / bloodhound / installer / installer.py View on Github external
"""Installer for Bloodhound - depends on the supplied requirements.txt file
to determine the installation packages"""

import os
from optparse import OptionParser
import subprocess
import platform
import sys
from getpass import getpass

import virtualenv
from createdigest import htdigest_create

if not hasattr(virtualenv, 'logger'):
    virtualenv.logger = virtualenv.Logger([(virtualenv.Logger.LEVELS[-1], 
                                          sys.stdout)])

DEFAULT_DB_USER = 'bloodhound'
DEFAULT_DB_NAME = 'bloodhound'
DEFAULT_ADMIN_USER = 'admin'

BASE_CONFIG = """
[components]
bhtheme.* = enabled
bhdashboard.* = enabled
multiproduct.* = enabled
permredirect.* = enabled
themeengine.* = enabled
trac.ticket.web_ui.ticketmodule = disabled
trac.ticket.report.reportmodule = disabled
github csrocha / odooenv / odooenv / environment.py View on Github external
def create_environment(path, config_ori):
    """Create environment structure.
    """
    # Archivo de configuracion destino
    config_dst = join(path, 'etc', config_filename)

    if not exists(path) or not listdir(path):
        # Crea el ambiente python
        virtualenv.logger = virtualenv.Logger(
            [(virtualenv.Logger.level_for_integer(2), sys.stdout)])
        virtualenv.create_environment(path, site_packages=False)

        # Crea el directorio donde va el archivo de configuracion
        makedirs(dirname(config_dst))

        # Descarga el archivo de configuracion environment.yml
        urlretrieve(config_ori, config_dst)

    # Prepara el ambiente Odoo
    env = OdooEnvironment(path)
    env.setup()

    return env
github rpatterson / iiswsgi / iiswsgi / install_virtualenv.py View on Github external
virtualenv_globals['main']()
            finally:
                sys.argv[:] = orig_argv
        else:
            try:
                import virtualenv
            except ImportError:
                raise errors.DistutilsModuleError(
                    'The virtualenv module must be available if no virtualenv '
                    'bootstrap script is given: {0}'.format(bootstrap))
            self.logger.info(
                'Setting up a isolated Python with module: '
                '{0}.create_environment({1} {2})'.format(
                    virtualenv, repr(home_dir), ' '.join(
                        '{0}={1}'.format(item) for item in opts.items())))
            virtualenv.logger = virtualenv.Logger([(
                virtualenv.Logger.level_for_integer(2 - self.verbose),
                sys.stdout)])

            virtualenv.create_environment(home_dir, **opts)

        activate_this = os.path.join(
            sysconfig.get_path('scripts', vars=dict(base=home_dir)),
            'activate_this.py')
        execfile(activate_this, dict(__file__=activate_this))

        # Reinitialize much of distutils since many of the command
        # objects have prefix related value stored locally
        reload(distutils.sysconfig)
        for command in self.distribution.command_obj.itervalues():
            finalized = command.finalized
            self.reinitialize_command(command)
github dustinlacewell / pin / pin / plugins / venv.py View on Github external
import os
from argparse import ArgumentParser

from pin import registry
from pin.event import register, eventhook
from pin.plugin import PinHook, register
from pin.util import *

import virtualenv
virtualenv.logger = virtualenv.Logger(consumers=[])

# Utility methods
@findroot
def create_virtualenv(path):
    if path:
        path = os.path.join(path,
                            PROJECT_FOLDERNAME,
                            VIRTUALENV_FOLDERNAME)
        virtualenv.create_environment(path, False, True)

# Virtual environment hooks
class VirtualEnvPinHook(PinHook):

    name = "venv"

    def __init__(self):
github aptivate / dye / {{cookiecutter.project_name}} / deploy / ve_mgr.py View on Github external
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)

        if self.pypi_cache_url is not None:
            pypi_cache_args = ['-i', self.pypi_cache_url]
        else:
            pypi_cache_args = []
        
        # install the pip requirements and exit
        pip_path = path.join(self.ve_dir, 'bin', 'pip')
        # first ensure we have an up to date version of distribute
        command = [pip_path, 'install', '-U', 'distribute'] + pypi_cache_args
        
        try:
            pip_retcode = subprocess.call(command)
        except OSError, e:
            print "command failed: %s: %s" % (" ".join(command), e)