Ejemplo n.º 1
0
def venv_package_status_site(venv: Venv, site: Path, req_spec: str) -> Do:
    ws = yield IO.delay(pkg_resources.WorkingSet, [site])
    req = yield IO.delay(pkg_resources.Requirement, req_spec)
    return Maybe.check(ws.by_key.get(req.key)).cata_strict(
        lambda a: VenvPackageExistent(venv, a),
        VenvPackageAbsent(venv),
    )
Ejemplo n.º 2
0
    def _lookup(self, data):
        def check(resp):
            return (IO.failed('no release found') if resp == -1 else IO.pure(
                (resp, self.rest)))

        return IO.delay(self.client.get, '{}_id'.format(self._type),
                        body=data) // check
Ejemplo n.º 3
0
def find_interpreter(spec: str) -> Do:
    path = Path(spec)
    exists = yield IO.delay(path.exists)
    venv = env.get('VIRTUAL_ENV').get_or_strict('[no venv]')
    yield (
        IO.pure(path)
        if exists else
        virtualenv_interpreter(venv, spec)
    )
Ejemplo n.º 4
0
def check_venv(base_dir: Path, plugin: Rplugin) -> Do:
    dir = base_dir / plugin.name
    pip = dir / 'bin' / 'pip'
    exists = yield IO.delay(pip.exists)
    return (
        venv_present(dir, plugin)
        if exists else
        VenvAbsent(plugin)
    )
Ejemplo n.º 5
0
 def list_shows(self, cmd):
     regex = cmd.args.head | ''
     def output(matches):
         if matches:
             for id, description in matches:
                 i = ColorString('#{}'.format(id), term.green)
                 d = ColorString(description, term.yellow)
                 yield '{}: {}'.format(i, d)
         else:
             yield 'No matching show found.'
     return (IO.delay(self.client.get, 'show', body=dict(regex=regex)) /
             output / List.wrap)
Ejemplo n.º 6
0
    def help(self, cmd):
        if self.doc:
            maxlen = len(max(self.doc.keys(), key=len))
            pad = lambda s: s.ljust(maxlen)

            def output():
                yield 'Available commands:'
                data = List.wrap(self.doc.items()).sort_by(_[0])
                for name, (param_desc, desc) in data:
                    yield ''
                    yield '{}    {}'.format(pad(name), param_desc)
                    yield '  {}'.format(desc)

            return IO.delay(output) / '\n'.join
        else:
            return IO.failed('no doc for client')
Ejemplo n.º 7
0
def venv_site(venv: Venv) -> Do:
    lib_dir = venv.meta.dir / 'lib'
    libs = yield IO.delay(lib_dir.glob, 'python3.?')
    lib = Lists.wrap(libs).head.to_either(f'no python dirs in {lib_dir}')
    return lib.map(lambda a: a / 'site-packages')
Ejemplo n.º 8
0
def create_dir(dir: Path) -> IO[None]:
    return IO.delay(dir.mkdir, parents=True, exist_ok=True)
Ejemplo n.º 9
0
def child_pids(pid: int) -> Do:
    proc = yield IO.delay(Process, pid)
    children = yield IO.delay(proc.children, recursive=True)
    yield IO.delay(Lists.wrap(children).map, lambda a: a.pid)
Ejemplo n.º 10
0
def codegen(task: CodegenTask) -> Do:
    template_path = yield IO.delay(task.template.absolute)
    template_code = yield IO.delay(template_path.read_text)
    replaced = task.subs.fold_left(template_code)(
        lambda z, a: re.sub(a[0], a[1], z))
    return task.imports.cat(replaced).join_lines
Ejemplo n.º 11
0
 def create_episode(self, cmd):
     series, season, episode = cmd.args
     data = dict(episode=episode)
     path = 'series/{}/seasons/{}/episodes'.format(series, season)
     return IO.delay(self.client.post, path, body=data)
Ejemplo n.º 12
0
def virtualenv_interpreter(venv: str, executable: str) -> Do:
    path_s = yield IO.from_either(env.get('PATH'))
    path = Lists.split(path_s, ':')
    clean_path = path.filter_not(lambda a: a.startswith(venv))
    candidate = yield IO.delay(shutil.which, executable, path=clean_path.mk_string(':'))
    return Path(candidate)
Ejemplo n.º 13
0
def pane_dir(pane: P) -> Do:
    ui_pane = yield TmuxIO.from_either(UiPane.e_for(pane))
    yield (ui_pane.cwd(pane) / TmuxIO.pure).get_or(lambda: TmuxIO.from_io(IO.delay(Path.cwd)))
Ejemplo n.º 14
0
def clear_cache() -> Do:
    yield IO.delay(shutil.rmtree, str(venvs_path), ignore_errors=True)
    yield create_dir(venvs_path)
Ejemplo n.º 15
0
 def delay(f: Callable[..., A], *a: Any, **kw: Any) -> 'IOState[S, A]':
     return IOState.lift(IO.delay(f, *a, **kw))
Ejemplo n.º 16
0
 def io(i, body):
     return IO.delay(meth(self.client),
                     '{}/{}{}'.format(self._type, i, sub),
                     body=body)
Ejemplo n.º 17
0
def which(name: str) -> Do:
    exe = yield IO.delay(shutil.which, name)
    return Path(exe)
Ejemplo n.º 18
0
 def to_io(fa: 'TmuxIO[A]', tmux: Tmux) -> Do:
     result = yield IO.delay(fa.run, tmux)
     yield IO.from_either(result.to_either)
Ejemplo n.º 19
0
def mkdir(path: Path) -> IO[None]:
    return IO.delay(path.mkdir, parents=True, exist_ok=True)
Ejemplo n.º 20
0
 def subfps(self, cmd):
     series, season, episode, subfps = cmd.args
     data = dict(subfps=subfps)
     path = 'series/{}/seasons/{}/episodes/{}'.format(
         series, season, episode)
     return IO.delay(self.client.put, path, body=data)
Ejemplo n.º 21
0
def remove_dir(dir: Path) -> Do:
    exists = yield IO.delay(dir.exists)
    yield IO.delay(shutil.rmtree, dir) if exists else IO.pure(None)
Ejemplo n.º 22
0
def codegen_write(task: CodegenTask, outpath: Path) -> Do:
    code = yield codegen(task)
    yield IO.delay(outpath.write_text, code)
    return code
Ejemplo n.º 23
0
 def cleanup(a: Any) -> Do:
     yield IO.delay(tmux_proc.kill).recover(const(None))
     yield IO.delay(tmux_proc.wait).recover(const(None))
     yield IO.delay(kill_server().result, tmux).recover(const(None))