Returns the path to the current virtualenv
430398
def get_current_venv():
        
        if 'VIRTUAL_ENV' in os.environ:
            venv = os.environ['VIRTUAL_ENV']
        elif os.path.exists('.python-version'):  # pragma: no cover
            try:
                subprocess.check_output(['pyenv', 'help'], stderr=subprocess.STDOUT)
            except OSError:
                print("This directory seems to have pyenv's local venv, "
                      "but pyenv executable was not found.")
            with open('.python-version', 'r') as f:
                # minor fix in how .python-version is read
                # Related: https://github.com/Miserlou/Zappa/issues/921
                env_name = f.readline().strip()
            bin_path = subprocess.check_output(['pyenv', 'which', 'python']).decode('utf-8')
            venv = bin_path[:bin_path.rfind(env_name)] + env_name
        else:  # pragma: no cover
            return None
        return venv
500801
def download_virtualenv(version, dldir=None):
    '''
    
    '''
    dl_url = PYPI_DL_URL.format(VER=version)
    filename = basename(dl_url)
    if dldir:
        dl_path = join(dldir, filename)
    else:
        dl_path = filename
    data = urlopen(PYPI_DL_URL.format(VER=version))
    with open(dl_path, 'wb') as fh:
        fh.write(data.read())
    return dl_path
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')))
882756
def get_path(self):
        
        return os.path.join(self.cluster.get_path(), self.name)
657210
def get_pythonpath(self, at_start=False):
        """"""
        if at_start:
            current_path = self.get_option('current_project_path',
                                           default=None)
        else:
            current_path = self.get_active_project_path()
        if current_path is None:
            return []
        else:
            return [current_path]
90259
def get_sys_path(cls, python_path):
        

        command = [python_path, "-c", "import json, sys; print(json.dumps(sys.path))"]
        c = vistir.misc.run(command, return_object=True, block=True, nospin=True)
        assert c.returncode == 0, "failed loading virtualenv path"
        sys_path = json.loads(c.out.strip())
        return sys_path
888957
def venv_bin(name=None):  # pylint: disable=inconsistent-return-statements
    
    if not hasattr(sys, "real_prefix"):
        easy.error("ERROR: '%s' is not a virtualenv" % (sys.executable,))
        sys.exit(1)

    for bindir in ("bin", "Scripts"):
        bindir = os.path.join(sys.prefix, bindir)
        if os.path.exists(bindir):
            if name:
                bin_ext = os.path.splitext(sys.executable)[1] if sys.platform == 'win32' else ''
                return os.path.join(bindir, name + bin_ext)
            else:
                return bindir

    easy.error("ERROR: Scripts directory not found in '%s'" % (sys.prefix,))
    sys.exit(1)
948680
def get_current_searchpath(self):
        
        idx = self.currentIndex()
        if idx == CWD:
            return self.path
        elif idx == PROJECT:
            return self.project_path
        elif idx == FILE_PATH:
            return self.file_path
        else:
            return self.external_path
572408
def virtual_path(path, partial)
      return path unless partial
      if index = path.rindex("/")
        path.insert(index + 1, "_")
      else
        "_#{path}"
      end
    end
70219
def get_env():
    
    if not __ENV__:
        env = os.environ["env"] if "env" in os.environ else "Dev"
        set_env(env)
    return __ENV__
884851
def path(self):
        
        if self.parent is None:
            return "/"
        else:
            return os.path.join(self.parent.path, self.name)
666440
def current():
        
        if not EnvManager._current:
            path = os.environ.get('PROJEX_ENVMGR_PATH')
            module = os.environ.get('PROJEX_ENVMGR_MODULE')
            clsname = os.environ.get('PROJEX_ENVMGR_CLASS')
            cls = EnvManager

            if module and clsname:
                # check if the user specified an import path
                if path:
                    logger.info('Adding env manager path: %s' % path)
                    sys.path.insert(0, path)

                logger.info('Loading env manager: %s.%s' % (module, clsname))

                try:
                    __import__(module)
                    mod = sys.modules[module]
                    cls = getattr(mod, clsname)

                except ImportError:
                    logger.error('Could not import env manager %s', module)

                except KeyError:
                    logger.error('Could not import env manager %s', module)

                except AttributeError:
                    msg = '%s is not a valid class of %s' % (clsname, module)
                    logger.error(msg)

            EnvManager._current = cls()
        return EnvManager._current
108609
def relpath(self, current_file, rel_path):
        
        script_dir = os.path.dirname(os.path.abspath(current_file))
        rel_path = os.path.abspath(os.path.join(script_dir, rel_path))
        return rel_path
798680
def default_working_dir():
    
    import nameset.virtualchain_hooks as virtualchain_hooks
    return os.path.expanduser('~/.{}'.format(virtualchain_hooks.get_virtual_chain_name()))
649865
def get_vswhere_path():
    
    if alternate_path and os.path.exists(alternate_path):
        return alternate_path

    if DEFAULT_PATH and os.path.exists(DEFAULT_PATH):
        return DEFAULT_PATH

    if os.path.exists(DOWNLOAD_PATH):
        return DOWNLOAD_PATH

    _download_vswhere()
    return DOWNLOAD_PATH
140763
def get_env_path(cls):
        
        return os.path.dirname(Finder.python()) + os.pathsep + os.environ['PATH']
385793
def find_dotenv(filename='.env', raise_error_if_not_found=False, usecwd=False):
    
    if usecwd or '__file__' not in globals():
        # should work without __file__, e.g. in REPL or IPython notebook
        path = os.getcwd()
    else:
        # will work for .py files
        frame_filename = sys._getframe().f_back.f_code.co_filename
        path = os.path.dirname(os.path.abspath(frame_filename))

    for dirname in _walk_to_root(path):
        check_path = os.path.join(dirname, filename)
        if os.path.exists(check_path):
            return check_path

    if raise_error_if_not_found:
        raise IOError('File not found')

    return ''