Exemplo n.º 1
0
def deactivate(conda=None):
    if conda is None:
        conda = which_conda()

    bash = run_subproc([[conda, 'shell.posix', 'deactivate']],
                       captured="stdout")
    run_subproc([["source-bash", bash]])
Exemplo n.º 2
0
def pip(pkg, pyname=None):
    import importlib

    if importlib.util.find_spec(pyname or pkg):
        return

    run_subproc([["xpip", "install", pkg]])
Exemplo n.º 3
0
def conda(args):
    conda = which_conda()
    if len(args) == 0:
        run_subproc([[conda]])
        return

    if args[0] == 'activate':
        activate(args[1], conda)
    elif args[0] == 'deactivate':
        deactivate(conda)
    else:
        run_subproc([[conda] + args])
Exemplo n.º 4
0
def ghq(event):
    cands = run_subproc([['ghq', 'list']],
                        captured='stdout').strip().split('\n')
    result, _ = select(map(lambda s: s.encode(), reversed(cands)),
                       options=["--layout=bottom-up"])

    if len(result) > 0:
        root = run_subproc([["ghq", 'root']], captured="stdout")
        path = os.path.join(root.strip(), result.decode().strip())
        dirstack.cd([path])

    event.current_buffer.validate_and_handle()  # refresh prompt
Exemplo n.º 5
0
def package(pkg, pyname=None):
    import importlib

    if importlib.util.find_spec(pyname or pkg):
        return

    conda = get_conda()
    if conda is None:
        return pip(pkg, pyname)

    prefix = get_conda_prefix()
    run_subproc([[conda, "install", "-yp", prefix, pkg]])
Exemplo n.º 6
0
    def __call__(self, args, stdin=None):
        args = self.parser.parse_args(args)

        if args.action == 'help':
            self.parser.print_help()
            return
        elif args.action == 'remove':
            self.remove(self.pwd())
            return

        data = list(self.load_data())
        if args.subdir_only:
            pwd = self.getpwd()
            # XXX: Is there a better way to detect subpath relationship?
            data = [
                e for e in data if os.path.commonpath((pwd, e.path)) == pwd
            ]
        if args.mode == 'frecency':
            data.sort(reverse=True, key=lambda e: e.frecency)
        elif args.mode == 'rank':
            data.sort(reverse=True, key=lambda e: e.rank)
        elif args.mode == 'time':
            data.sort(reverse=True, key=lambda e: e.time)
        else:
            # argparse should prevent this from happening
            raise RuntimeError("Unknown sort mode: {}".format(args.mode))

        # Actually do search
        pats = list(map(re.compile,
                        args.patterns))  # Used repeatedly, pre-evaluate
        data = list(filter(functools.partial(self._doesitmatch, pats), data))

        if not data and args.action != 'list':
            return "", "No matches found\n", 1

        if args.action == 'cd':
            built_ins.run_subproc([['cd', data[0].path]])
        elif args.action == 'echo':
            return data[0].path + '\n'
        elif args.action == 'list':
            # FIXME: Prefix with sort key
            return '\n'.join(e.path for e in data) + '\n'
Exemplo n.º 7
0
def test_runsubproc_simple(xonsh_builtins, xonsh_execer):
    new_cwd = os.path.dirname(__file__)
    xonsh_builtins.__xonsh_env__['PATH'] = os.path.join(new_cwd, 'bin') + \
        os.pathsep + os.path.dirname(sys.executable)
    xonsh_builtins.__xonsh_env__['XONSH_ENCODING'] = 'utf8'
    xonsh_builtins.__xonsh_env__['XONSH_ENCODING_ERRORS'] = 'surrogateescape'
    xonsh_builtins.__xonsh_env__['XONSH_PROC_FREQUENCY'] = 1e-4
    if ON_WINDOWS:
        pathext = xonsh_builtins.__xonsh_env__['PATHEXT']
        xonsh_builtins.__xonsh_env__['PATHEXT'] = ';'.join(pathext)
        pwd = 'PWD.BAT'
    else:
        pwd = 'pwd'
    out = run_subproc([[pwd]], captured='stdout')
    assert out.rstrip() == new_cwd
Exemplo n.º 8
0
def test_runsubproc_redirect_out_to_file(xonsh_builtins, xonsh_execer):
    xonsh_builtins.__xonsh_env__['XONSH_PROC_FREQUENCY'] = 1e-4
    run_subproc([['pwd', 'out>', 'tttt']], captured='stdout')
    with open('tttt') as f:
        assert f.read().rstrip() == os.getcwd()
    os.remove('tttt')
Exemplo n.º 9
0
def get_conda_envs():
    conda = run_subproc([["which", "--skip-alias", "conda"]],
                        captured="stdout")
    result = run_subproc([[conda, 'env', 'list', '--json']], captured="stdout")
    envs = json.loads(result)["envs"]
    return frozenset(map(os.path.basename, envs))
Exemplo n.º 10
0
def which_conda():
    return run_subproc([["which", "--skip-alias", "conda"]], captured="stdout")