# type: ignore

from invoke import task, Collection

from . import check, doc, lint, test, types


@task
def clean(ctx, full=False):
    """Delete all the standard build and validate artifacts."""
    if full:
        ctx.run('git clean -dfX')
    else:
        anywhere = ['__pycache__']
        top_level = [
            '.coverage',
            '.mypy_cache',
            '.pytest_cache',
            'dist',
            '*.egg-info']
        for name in anywhere:
            for path in ['pysasl', 'test']:
                ctx.run('find {} -name {} | xargs rm -rf'.format(path, name))
        for name in top_level:
            ctx.run('rm -rf {}'.format(name))


@task(check.check_venv)
def install(ctx, dev=True, update=False):
    """Install the library and all development tools."""
    choice = 'dev' if dev else 'all'
    if update:
        ctx.run('pip install -U -r requirements-{}.txt'.format(choice))
    else:
        ctx.run('pip install -r requirements-{}.txt'.format(choice))


@task(test.all, types.all, lint.all)
def validate(ctx):
    """Run all tests, type checks, and linters."""
    del ctx


ns = Collection(clean, install)
ns.add_task(validate, default=True)
ns.add_collection(check)
ns.add_collection(test)
ns.add_collection(types)
ns.add_collection(lint)
ns.add_collection(doc)

ns.configure({
    'check_import': True,
    'check_venv': True,
    'run': {
        'echo': True,
        'pty': True,
    }
})
