Ejemplo n.º 1
0
 def dir_rplugin(self, rplugin: DirRplugin) -> Do:
     venv = yield venv_from_rplugin(rplugin)
     python_exe = venv.meta.python_executable
     bin_path = venv.meta.bin_path
     plugin_path = Path(rplugin.spec) / rplugin.name / '__init__.py'
     yield start_python_rplugin_host(rplugin, python_exe, bin_path,
                                     plugin_path, List(rplugin.spec))
Ejemplo n.º 2
0
def extract(match: Match) -> Generator:
    path = yield match.group('path')
    lnum = yield match.group('lnum')
    lnum_i = yield parse_int(lnum)
    col = match.group('col') // parse_int
    error = yield match.group('error')
    yield Right((Path(path), lnum_i, col, error))
Ejemplo n.º 3
0
 def wrap(*a, **kw):
     cProfile.runctx('f(*a, **kw)',
                     dict(),
                     dict(f=f, a=a, kw=kw),
                     filename=fname)
     stats = pstats.Stats(fname)
     stats.sort_stats(sort).print_stats(30)
     Path(fname).unlink()
Ejemplo n.º 4
0
def single_venv_config(name: str, spec: str,
                       **extra_vars: Any) -> Tuple[Rplugin, Venv, TestConfig]:
    rplugin = simple_rplugin(name, spec)
    dir = temp_dir('rplugin', 'venv')
    vars = Map(chromatin_venv_dir=str(dir))**Map(extra_vars)
    conf = lens.basic.state_ctor.set(LogBufferEnv.cons)(chromatin_config)
    venv = Venv(
        rplugin.name,
        VenvMeta(name, dir / name, Right(Path('/dev/null')),
                 Right(Path('/dev/null'))))
    return rplugin, venv, TestConfig.cons(
        conf,
        vars=vars,
        io_interpreter=single_venv_io_interpreter(venv),
        logger=buffering_logger,
        function_handler=test_function_handler(exists=1),
        command_handler=test_command_handler(),
    )
Ejemplo n.º 5
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.º 6
0
 def _clean_done(self, a):
     proc = a.proc
     if proc.done.value:
         self._update_id(a.monitor.id, downloading=False)
         if proc.fail.value:
             self._fail(a.monitor, proc.link, proc.error.value)
         else:
             path = Path(proc.file_path.value.decode())
             return self._check_download(a.monitor, proc.link,
                                         proc.size.value,
                                         proc.file_size.value, path)
Ejemplo n.º 7
0
def setup(path: Union[str, Path]) -> None:
    ''' Use the supplied path to initialise the tests base dir.
    If _path is a file, its dirname is used.
    '''
    if not isinstance(path, Path):
        path = Path(path)
    if not path.is_dir():
        path = path.parent
    global __base_dir__
    __base_dir__ = path
    container = str(pkg_dir())
    if container not in sys.path:
        sys.path.insert(0, container)
        env['PYTHONPATH'] = '{}:{}'.format(container, env['PYTHONPATH'] | '')
Ejemplo n.º 8
0
 def dir(self, meta: DirVenvRplugin) -> List[str]:
     req = Path(meta.dir) / 'requirements.txt'
     return List('-r', str(req))
Ejemplo n.º 9
0
def update_for(path: Path, files: Files) -> Files:
    return files if path in files else files + (path, Lists.lines(path.read_text()))
Ejemplo n.º 10
0
 def hackage(self, rplugin: HackageRplugin) -> NvimIO[ActiveRplugin]:
     return activate_cabal_plugin(rplugin, Path.home())
Ejemplo n.º 11
0
 def file(path: Path) -> List[str]:
     return Lists.lines(path.read_text())
Ejemplo n.º 12
0
 def stackage(self, rplugin: StackageRplugin) -> NvimIO[ActiveRplugin]:
     return activate_stack_plugin(rplugin, Path.home())
Ejemplo n.º 13
0
class TmuxIOToTmuxIOState(ToTmuxIOState, tpe=TmuxIO):

    @tc_prop
    def tmux(self, fa: TmuxIO[A]) -> TS[S, A]:
        return TS.lift(fa)

    @tc_prop
    def state(self, fa: TmuxIO[A]) -> TS[S, A]:
        return self.tmux(fa)
'''

extra_import = List(
    'import abc',
    'from amino.tc.base import TypeClass, tc_prop',
    'from amino.state import State, EitherState',
    'from chiasma.tmux import Tmux',
    'from amino import IO, Maybe, Either',
    'from amino.func import CallByName',
    '''E = TypeVar('E')''',
)
pkg = Path(__file__).absolute().parent.parent
task = state_task('TmuxIO',
                  'chiasma.io.compute',
                  meta_extra=meta_extra,
                  ctor_extra=meta_extra,
                  extra_import=extra_import,
                  extra=extra)
outpath = pkg / 'chiasma' / 'io' / f'state.py'

codegen_write(task, outpath).fatal
Ejemplo n.º 14
0
 def local_path(self):
     path = Path(self.canonical_name) / 's{}'.format(self.season)
     if self.extension == 'srt':
         path = path / 'sub'
     return path / self.filename
Ejemplo n.º 15
0
 def hs_dir(self, a: HsDirRplugin) -> Maybe[InstallableRplugin]:
     return Just(InstallableRplugin(HsInstallableRplugin(HsStackDirRplugin(Path(a.spec))), a))
Ejemplo n.º 16
0
def temp_path(*components: str) -> Path:
    dir = _check()
    return Path(dir, '_temp', *components)
Ejemplo n.º 17
0
from typing import Any

from amino import Path, List, IO, do, Do, Nil
from amino.meta.gen import codegen, CodegenTask, codegen_write

here = Path(__file__).absolute().parent
template_path = here.parent.parent / 'templates' / 'state.py'


def state_task(
    tpe: str,
    path: str,
    tvar: List[str] = Nil,
    class_extra: str = '',
    meta_extra: str = '',
    ctor_extra: str = '',
    extra_import: List[str] = Nil,
    extra: str = '',
) -> CodegenTask:
    tpar = tvar.map(lambda a: f'{a}, ').mk_string('')
    tvars = tvar.map(lambda a: f'{a} = TypeVar(\'{a}\')').join_lines
    tpe_import = f'from {path} import {tpe}'
    subs = List(
        (r'\bF\[', f'{tpe}[{tpar}'),
        (r'\bF\b', tpe),
        ('StateT\[', f'{tpe}State[{tpar}'),
        ('StateT', f'{tpe}State'),
        ('{tpar}', tpar),
        ('{tvar}', tvars),
        ('{f_import}', tpe_import),
        ('{class_extra}', class_extra),
Ejemplo n.º 18
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.º 19
0
def default_venv_dir() -> Do:
    xdg_cache_path = xdg_cache_home.value / Path | (Path.home() / '.cache')
    venv_dir = xdg_cache_path / 'chromatin' / 'venvs'
    yield Try(venv_dir.mkdir, parents=True, exist_ok=True).lmap(lambda a: create_venv_dir_error(venv_dir))
    yield Right(venv_dir)
Ejemplo n.º 20
0
 def directory(self) -> Expectation:
     plugins_dir = rplugin_dir(name)
     plugin_dir = Path(plugins_dir) / name
     spec = f'dir:{plugin_dir}'
     rplugin, venv, conf = single_venv_config(name, spec)
     return unit_test(conf, directory_spec, spec)
Ejemplo n.º 21
0
def which(name: str) -> Do:
    exe = yield IO.delay(shutil.which, name)
    return Path(exe)
Ejemplo n.º 22
0
 def dir(self, a: DirRplugin) -> Maybe[InstallableRplugin]:
     return Just(InstallableRplugin(VenvRplugin(DirVenvRplugin(Path(a.spec))), a))
Ejemplo n.º 23
0
def fixture_path(*components: str) -> Path:
    dir = _check()
    return Path(dir, '_fixtures', *components)
Ejemplo n.º 24
0
 def venv(self) -> Expectation:
     p = Path('/')
     rplugin = simple_rplugin('spec', 'name')
     venv = Venv(rplugin, VenvMeta(rplugin.name, p, Right(p), Right(p)))
     return k(dump_json(venv)).must(be_right)