Пример #1
0
def test_delete_project():
    tmpdir = tempfile.mkdtemp()
    subprocess.run(f"minus80 init --path {tmpdir} bizbaz".split())
    assert FreezableAPI.exists("Project", "bizbaz")
    # Now delete the project
    subprocess.run("minus80 delete  Project.bizbaz --force".split())
    assert not FreezableAPI.exists("Project", "bizbaz")
Пример #2
0
def test_delete_project_bad_tag():
    tmpdir = tempfile.mkdtemp()
    subprocess.run(f"minus80 init --path {tmpdir} bizbaz".split())
    assert FreezableAPI.exists("Project", "bizbaz")
    # Try to delete with tag
    subprocess.run("minus80 delete  Project.bizbaz:v1 --force".split())
    # Now delete the project for real
    subprocess.run("minus80 delete  Project.bizbaz --force".split())
    assert not FreezableAPI.exists("Project", "bizbaz")
Пример #3
0
def freeze(slug):
    # Validate the input
    try:
        dtype, name, tag = FreezableAPI.parse_slug(slug)
        if tag is None:
            raise TagInvalidError()
    except (TagInvalidError, FreezableNameInvalidError):
        click.echo(f'Please provide a valid tag in "{slug}"')
        sys.exit(1)
    # Make sure that the dataset is available
    if not FreezableAPI.exists(dtype, name):
        click.echo(f'"{dtype}.{name}" not in minus80 datasets! '
                   "check available datasets with the ls command")
        sys.exit(1)
    else:
        # Create the minus80
        try:
            dataset = getattr(m80, dtype)(name)
        except Exception as e:  # pragma: no cover
            click.echo(f"Could not build {dtype}.{name}")
            raise e
            sys.exit(1)
        # Freeze with tag
        try:
            dataset.m80.freeze(tag)
            click.echo(click.style("SUCCESS!", fg="green", bold=True))
            sys.exit(0)
        except TagExistsError:
            click.echo(
                f'Tag "{tag}" already exists in the cloud for {dtype}.{name}')
            sys.exit(1)
Пример #4
0
def thaw(slug, force):
    try:
        cwd = Path.cwd().resolve()
    except FileNotFoundError:  # pragma: no cover
        cwd = "/"
    try:
        dtype, name, tag = FreezableAPI.parse_slug(slug)
        if tag is None:
            raise TagInvalidError()
    except (TagInvalidError, FreezableNameInvalidError):
        click.echo(f'Please provide a valid tag in "{slug}"')
        sys.exit(1)
    # Make sure that the dataset is available
    if not FreezableAPI.exists(dtype, name):
        click.echo(f'"{dtype}.{name}" not in minus80 datasets! '
                   "check available datasets with the ls command")
        sys.exit(1)
    else:
        # Create the minus80
        try:
            dataset = getattr(m80, dtype)(name)
        except Exception:  # pragma: no cover
            click.echo(f"Could not build {dtype}.{name}")
        # Freeze with tag
        try:
            dataset.m80.thaw(tag, force=force)
            click.echo(click.style("SUCCESS!", fg="green", bold=True))
            sys.exit(0)
        except TagDoesNotExistError:
            click.echo(f'tag "{tag}" does not exist for {dtype}.{name}')
            sys.exit(1)
        except UnsavedChangesInThawedError as e:
            click.secho(
                'freeze your current changes or use "force" to dispose of '
                "any unsaved changes in current thawed dataset",
                fg="red",
            )
            for status, files in {
                    "Changed": e.changed,
                    "New": e.new,
                    "Deleted": e.deleted,
            }.items():
                for f in files:
                    click.secho(f"    {status}: {f}", fg="yellow")
            sys.exit(1)

    # Warn the user if they are in a directory (cwd) that was deleted
    # in the thaw -- theres nothing we can do about this ...
    if str(cwd).startswith(str(dataset.m80.thawed_dir)):
        click.echo(
            "Looks like you are currently in a directory that was just thawed, "
            "update your current working directory with, e.g.:\n"
            "$ cd `pwd`\n"
            f"$ cd {cwd}")
Пример #5
0
def push(slug):
    """
    \b
    Push a frozen minus80 dataset to the cloud.

    \b
    Positional Arguments:
    <slug> - A slug of a frozen minus80 dataset
    """
    cloud = m80.CloudData()
    try:
        cloud.user
    except UserNotLoggedInError:
        click.secho("Please log in to use this feature")
    try:
        dtype, name, tag = FreezableAPI.parse_slug(slug)
        if tag is None:
            raise TagInvalidError()
    except (TagInvalidError, FreezableNameInvalidError):
        click.echo(f'Please provide a valid tag in "{slug}"')
        return 0
    # Make sure that the dataset is available
    if not FreezableAPI.exists(dtype, name):
        click.echo(f'"{dtype}.{name}" not in minus80 datasets! '
                   "check available datasets with the ls command")
        return 0
    else:
        try:
            # run the push method in an event loop
            asyncio.run(cloud.push(dtype, name, tag))
        except TagDoesNotExistError:
            click.echo(f'tag "{tag}" does not exist for {dtype}.{name}')
        except TagExistsError:
            click.echo(f"Cannot push {dtype}.{name}:{tag} to the cloud.")
            click.echo("The tag already exists there.")
        except TagConflictError:
            click.echo(f"Cannot push {dtype}.{name}:{tag} to the cloud.")
            click.echo("The tag already exists there.")
            click.secho(
                "Warning! The contents of the local tag and the cloud tag differ "
                "Create a tag with a unique name and retry pushing",
                fg="red",
            )
Пример #6
0
def delete(slug, force):
    # Validate the input
    if force is False:  # pragma: no cover
        click.confirm(f'Are you sure you want to delete "{slug}"')
    try:
        dtype, name, tag = FreezableAPI.parse_slug(slug)
        if tag is not None:
            raise TagInvalidError()
    except TagInvalidError:
        click.echo("Cannot delete tags, only entire datasets.")
        sys.exit(1)
    except FreezableNameInvalidError:
        click.echo(
            "Please provide a valid dataset name: <dtype>.<name>. E.g. Project.foobar"
            "Note: do not include tags")
        sys.exit(1)
    # Make sure that the dataset is available
    if not FreezableAPI.exists(dtype, name):
        click.echo(f'"{dtype}.{name}" not in minus80 datasets! '
                   "check available datasets with the ls command")
        sys.exit(1)
    else:
        FreezableAPI.delete(dtype, name)
        sys.exit(0)
Пример #7
0
def test_unavailable_bool(simpleCohort):
    assert FreezableAPI.exists(dtype="Cohort", name="ERROR") == False
Пример #8
0
def test_available_bool(simpleCohort):
    assert FreezableAPI.exists(dtype="Cohort", name="TestCohort") == True