def test_image_repo_parsing_errors(pg_repo_local): repo = Repository("test", "pg_mount") assert ImageType(get_image=True, default="latest")("test/pg_mount")[1] == repo.images["latest"] assert ( ImageType(get_image=True, default="latest")("test/pg_mount:00000000")[1] == repo.images["00000000"] ) with pytest.raises(ImageNotFoundError): ImageType(get_image=True, default="latest")("test/pg_mount:doesnt_exist") with pytest.raises(RepositoryNotFoundError): ImageType(get_image=True, default="latest")("test/doesntexist:latest") with pytest.raises(RepositoryNotFoundError): RepositoryType(exists=True)("test/doesntexist")
def test_image_spec_parsing(): assert ImageType()("test/pg_mount") == (Repository("test", "pg_mount"), "latest") assert ImageType(default="HEAD")("test/pg_mount") == (Repository("test", "pg_mount"), "HEAD") assert ImageType()("test/pg_mount:some_tag") == (Repository("test", "pg_mount"), "some_tag") assert ImageType()("pg_mount") == (Repository("", "pg_mount"), "latest") assert ImageType()("pg_mount:some_tag") == (Repository("", "pg_mount"), "some_tag") assert ImageType(default="HEAD")("pg_mount:some_tag") == ( Repository("", "pg_mount"), "some_tag", )
import io import logging from itertools import islice import click from splitgraph.commandline.common import ImageType, RepositoryType, ResettableStream @click.group(name="csv") def csv_group(): """Import/export Splitgraph images in CSV format.""" @click.command(name="export") @click.argument("image_spec", type=ImageType(default=None)) @click.argument("query") @click.option( "-f", "--file", type=click.File("w"), default="-", help="File name to export to, default stdout.", ) @click.option( "-l", "--layered", help="Don't materialize the tables, use layered querying instead.", is_flag=True, default=False, )
""" sgr commands related to sharing and downloading images. """ import sys import click from splitgraph.commandline.common import RepositoryType, ImageType, JsonType from splitgraph.config import CONFIG, REMOTES from splitgraph.config.config import get_from_subsection @click.command(name="pull") @click.argument("repository_or_image", type=ImageType(repository_exists=True, default=None)) @click.option( "-d", "--download-all", is_flag=True, help="Download all objects immediately instead of on checkout.", ) @click.option( "-f", "--overwrite-object-meta", help="Overwrite metadata for existing objects", is_flag=True, ) @click.option("-t", "--tags", help="Overwrite tags for pulled image/repo",
""" sgr commands related to creating and checking out images """ import sys from collections import defaultdict import click from splitgraph.commandline.common import ImageType, RepositoryType, JsonType, remote_switch_option from splitgraph.config import get_singleton, CONFIG from splitgraph.exceptions import TableNotFoundError @click.command(name="checkout") @click.argument("image_spec", type=ImageType(default="HEAD", get_image=True)) @click.option("-f", "--force", help="Discard all pending changes to the schema", is_flag=True, default=False) @click.option("-u", "--uncheckout", help="Delete the checked out copy instead", is_flag=True, default=False) @click.option( "-l", "--layered", help="Don't materialize the tables, use layered querying instead.", is_flag=True, default=False,
} config_path = patch_and_save_config(CONFIG, config_patch) if not skip_inject: inject_config_into_engines(CONFIG["SG_ENGINE_PREFIX"], config_path) @click.command("curl", context_settings=dict(ignore_unknown_options=True)) @click.option("--remote", default="data.splitgraph.com", help="Name of the remote registry to use.") @click.option("-t", "--request-type", default="postgrest", type=click.Choice(["postgrest", "splitfile"])) @click.argument("image", type=ImageType(default="latest")) @click.argument("request_params", type=str, default="") # This is kind of awkward: we want to support not passing in any request params to default # them to / but also want to be able to support multiple curl args which click doesn't let # us do (click.argument with nargs=-1 makes "request_params" consume the first arg even # if we use the posix standard separator --). @click.option("-c", "--curl-args", type=str, multiple=True, help="Extra arguments to be passed to curl") def curl_c(remote, request_type, image, request_params, curl_args): """ Query a Splitgraph REST API. This is a thin wrapper around curl that performs an HTTP request to Splitgraph Cloud to
"""Command line tools for building Splitgraph images from Singer taps, including using Splitgraph as a Singer target.""" import click from splitgraph.commandline.common import ImageType from splitgraph.hooks.data_source.base import prepare_new_image @click.group(name="singer") def singer_group(): """Build Splitgraph images from Singer taps.""" @click.command(name="target") @click.argument("image", type=ImageType(default="latest", repository_exists=False)) @click.option("-d", "--delete-old", is_flag=True, help="Delete the old image at the end of ingestion") @click.option( "-f", "--failure", type=click.Choice(["keep-both", "delete-old", "delete-new"]), help="What to do in case of a failure.", default="delete-new", ) def singer_target(image, delete_old, failure): """ Singer target that loads data into Splitgraph images. This will read data from the stdin from a Singer-compatible tap and load it into