Return new Command object that will drop a specified
        environment variable if it is set.

            new_cmd = old_cmd.without_env("PYTHON_PATH")
189566
def without_env(self, environment_variable):
        
        new_command = copy.deepcopy(self)
        new_command._env_drop.append(str(environment_variable))
        return new_command
210062
def env(*args, **kwargs):
    
    for arg in args:
        value = os.environ.get(arg, None)
        if value:
            return value
    return kwargs.get("default", "")
936322
def wipeenv_cmd(argv):
    """"""
    env = argv[0] if argv else os.environ.get('VIRTUAL_ENV')

    if not env:
        sys.exit('ERROR: no virtualenv active')
    elif not (workon_home / env).exists():
        sys.exit("ERROR: Environment '{0}' does not exist.".format(env))
    else:
        env_pip = str(workon_home / env / env_bin_dir / 'pip')
        all_pkgs = set(invoke(env_pip, 'freeze').out.splitlines())
        pkgs = set(p for p in all_pkgs if len(p.split("==")) == 2)
        ignored = sorted(all_pkgs - pkgs)
        pkgs = set(p.split("==")[0] for p in pkgs)
        to_remove = sorted(pkgs - set(['distribute', 'wsgiref']))
        if to_remove:
            print("Ignoring:\n %s" % "\n ".join(ignored))
            print("Uninstalling packages:\n %s" % "\n ".join(to_remove))
            return inve(env, 'pip', 'uninstall', '-y', *to_remove)
        else:
            print("Nothing to remove")
1196201
def get_new_command(command):
    
    dest = command.script_parts[1].split(os.sep)
    if dest[-1] == '':
        dest = dest[:-1]

    if dest[0] == '':
        cwd = os.sep
        dest = dest[1:]
    elif six.PY2:
        cwd = os.getcwdu()
    else:
        cwd = os.getcwd()
    for directory in dest:
        if directory == ".":
            continue
        elif directory == "..":
            cwd = os.path.split(cwd)[0]
            continue
        best_matches = get_close_matches(directory, _get_sub_dirs(cwd), cutoff=MAX_ALLOWED_DIFF)
        if best_matches:
            cwd = os.path.join(cwd, best_matches[0])
        else:
            return cd_mkdir.get_new_command(command)
    return u'cd "{0}"'.format(cwd)
1193738
def get_command(self, ctx, name):
        """"""
        env = ctx.ensure_object(environment.Environment)
        env.load()

        # Do alias lookup (only available for root commands)
        if len(self.path) == 0:
            name = env.resolve_alias(name)

        new_path = list(self.path)
        new_path.append(name)
        module = env.get_command(*new_path)
        if isinstance(module, types.ModuleType):
            return CommandLoader(*new_path, help=module.__doc__ or '')
        else:
            return module
788992
def env(key, default=None, required=False):
    
    try:
        value = os.environ[key]
        return ast.literal_eval(value)
    except (SyntaxError, ValueError):
        return value
    except KeyError:
        if default or not required:
            return default
        raise ImproperlyConfigured(
            "Missing required environment variable '%s'" % key)
1026962
def go_env(self, gopath=None):
    """"""
    # Forcibly nullify the GOPATH if the command does not need one - this can prevent bad user
    # GOPATHs from erroring out commands; see: https://github.com/pantsbuild/pants/issues/2321.
    # NB: As of go 1.8, when GOPATH is unset (set to ''), it defaults to ~/go (assuming HOME is
    # set - and we can't unset that since it might legitimately be used by the subcommand); so we
    # set the GOPATH here to a valid value that nonetheless will fail to work if GOPATH is
    # actually used by the subcommand.
    no_gopath = os.devnull
    return OrderedDict(GOROOT=self.goroot, GOPATH=gopath or no_gopath)
406124
def environment_as(**kwargs):
  
  new_environment = kwargs
  old_environment = {}

  def setenv(key, val):
    if val is not None:
      os.environ[key] = val if PY3 else _os_encode(val)
    else:
      if key in os.environ:
        del os.environ[key]

  for key, val in new_environment.items():
    old_environment[key] = os.environ.get(key)
    setenv(key, val)
  try:
    yield
  finally:
    for key, val in old_environment.items():
      setenv(key, val)
1068356
def _pop(self, command, *args, **kwargs):
        
        result = self._traverse_command(command, *args, **kwargs)
        if self.indexable:
            self.deindex([result])
        return result
910262
def disown(cmd):
    """"""
    subprocess.Popen(cmd,
                     stdout=subprocess.DEVNULL,
                     stderr=subprocess.DEVNULL)
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])
603699
def get(cls, key, default=None, separator='.', global_=False):
        
        # first check environnment variables
        # if we're not in global scope
        if not global_:
            ret = os.environ.get(key.upper().replace('.', '_'))
            if ret is not None:
                return ret

        # then check in local and global configuration unless global_=True
        scopes = ['global'] if global_ else ['local', 'global']
        for scope in scopes:
            ret = cls._get(scope, key, default, separator)
            if ret is not None and ret != default:
                return ret

        if ret is None or ret == default:
            return default
1233894
def inve(env, command, *args, **kwargs):
    """"""
    # we don't strictly need to restore the environment, since pew runs in
    # its own process, but it feels like the right thing to do
    with temp_environ():
        os.environ['VIRTUAL_ENV'] = str(workon_home / env)
        os.environ['PATH'] = compute_path(env)

        unsetenv('PYTHONHOME')
        unsetenv('__PYVENV_LAUNCHER__')

        try:
            return check_call([command] + list(args), shell=windows, **kwargs)
            # need to have shell=True on windows, otherwise the PYTHONPATH
            # won't inherit the PATH
        except OSError as e:
            if e.errno == 2:
                err('Unable to find', command)
                return 2
            else:
                raise
1263376
def cd(*args):
    
    if args[0] == "-":
        try:
            newpwd, os.environ["OLDPWD"] = os.environ["OLDPWD"], os.getcwd()
        except KeyError as e:  # $OLDPWD initially not set
            raise e
        else:
            os.chdir(newpwd)
            print(newpwd)
    else:
        os.environ["OLDPWD"] = os.getcwd()
        os.chdir(*args)
399043
def cmd(
        name,
        fun=None,
        arg=(),
        **kwargs):
    '''
    
    '''
    ret = {'name': name,
           'changes': {},
           'comment': '',
           'result': True}
    if fun is None:
        fun = name
    client = salt.wheel.WheelClient(__opts__)
    low = {'fun': fun,
            'arg': arg,
            'kwargs': kwargs}
    client.cmd_async(low)
    return ret
1234312
def new_cmd(argv):
    """"""
    parser = mkvirtualenv_argparser()
    parser.add_argument('-a', dest='project', help='Provide a full path to a \
project directory to associate with the new environment.')

    parser.add_argument('envname')
    args, rest = parser.parse_known_args(argv)
    project = expandpath(args.project) if args.project else None

    mkvirtualenv(args.envname, args.python, args.packages, project,
                 args.requirements, rest)
    if args.activate:
        shell(args.envname)
334367
def run_command(cmd, debug=False):
    
    if debug:
        # WARN(retr0h): Uses an internal ``sh`` data structure to dig
        # the environment out of the ``sh.command`` object.
        print_environment_vars(cmd._partial_call_args.get('env', {}))
        print_debug('COMMAND', str(cmd))
        print()
    return cmd(_truncate_exc=False)