Skip to content

Commit

Permalink
Merge pull request #85 from koordinates/remove-import-gpkg
Browse files Browse the repository at this point in the history
Remove import-gpkg command (deprecated since 0.2.0)
  • Loading branch information
craigds authored May 18, 2020
2 parents efa356d + 7ebbb24 commit 1be74d3
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 122 deletions.
1 change: 0 additions & 1 deletion sno/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ def cli(ctx, repo_dir, verbose):
cli.add_command(commit.commit)
cli.add_command(diff.diff)
cli.add_command(fsck.fsck)
cli.add_command(init.import_gpkg)
cli.add_command(init.import_table)
cli.add_command(init.init)
cli.add_command(merge.merge)
Expand Down
34 changes: 0 additions & 34 deletions sno/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,6 @@
from .output_util import dump_json_output


@click.command("import-gpkg", hidden=True)
@click.pass_context
@click.argument("geopackage", type=click.Path(exists=True, dir_okay=False))
@click.argument("table", required=False)
@click.option("--list-tables", is_flag=True)
def import_gpkg(ctx, geopackage, table, list_tables):
"""
Import a GeoPackage to a new repository (deprecated; use 'init')
"""

click.secho(
'"import-gpkg" is deprecated and will be removed in future, use "init" instead',
fg="yellow",
)

repo_path = ctx.obj.repo_path

check_git_user(repo=None)

import_from = ["GPKG", geopackage, None]
if table and not list_tables:
import_from[2] = table

if not list_tables and repo_path:
repo_path.mkdir(exist_ok=True)

ctx.invoke(
init,
directory=str(repo_path),
import_from=tuple(import_from),
do_checkout=False,
)


class ImportPath(click.Path):
def __init__(self, prefixes=("GPKG",), suffix_required=False, **kwargs):
params = {
Expand Down
87 changes: 0 additions & 87 deletions tests/test_init.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import re

import pytest

import apsw
import pygit2

from sno.working_copy import WorkingCopy
Expand Down Expand Up @@ -42,91 +40,6 @@
)


@pytest.mark.slow
@pytest.mark.parametrize(*GPKG_IMPORTS)
def test_import_geopackage(archive, gpkg, table, data_archive, tmp_path, cli_runner):
""" Import the GeoPackage (eg. `kx-foo-layer.gpkg`) into a Sno repository. """
with data_archive(archive) as data:
# list tables
repo_path = tmp_path / "data.sno"
r = cli_runner.invoke(["import-gpkg", f"--list-tables", data / gpkg])
assert r.exit_code == 1, r
lines = r.stdout.splitlines()
assert len(lines) >= 2
assert (
lines[0]
== '"import-gpkg" is deprecated and will be removed in future, use "init" instead'
)
assert lines[1] == f"GeoPackage tables in '{gpkg}':"
assert any(re.match(fr"^{table}\s+- ", l) for l in lines[2:])

# successful import
r = cli_runner.invoke(
[f"--repo={repo_path}", "import-gpkg", data / gpkg, table]
)
assert r.exit_code == 0, r
assert (repo_path / "HEAD").exists()

repo = pygit2.Repository(str(repo_path))
assert repo.is_bare
assert not repo.is_empty

assert repo.head.name == "refs/heads/master"
assert repo.head.shorthand == "master"

# has a single commit
assert len([c for c in repo.walk(repo.head.target)]) == 1

# has no working copy
wc = repo_path / f"{repo_path.stem}.gpkg"
assert not wc.exists()

# existing
r = cli_runner.invoke(
[f"--repo={repo_path}", "import-gpkg", data / gpkg, table]
)
assert r.exit_code == INVALID_OPERATION, r
assert re.search(
r"^Error: Invalid value for directory: \".*\" isn't empty",
r.stderr,
re.MULTILINE,
)


def test_import_geopackage_errors(data_archive, tmp_path, cli_runner):
with data_archive("gpkg-points") as data:
# missing/bad table name
repo_path = tmp_path / "data2.sno"
r = cli_runner.invoke(
[
f"--repo={repo_path}",
"import-gpkg",
data / "nz-pa-points-topo-150k.gpkg",
"some-layer-that-doesn't-exist",
]
)
assert r.exit_code == NO_TABLE, r
assert (
"Feature/Attributes table 'some-layer-that-doesn't-exist' not found in gpkg_contents"
in r.stderr
)

# Not a GeoPackage
db = apsw.Connection(str(tmp_path / "a.gpkg"))
with db:
db.cursor().execute(
"CREATE TABLE mytable (pk INT NOT NULL PRIMARY KEY, val TEXT);"
)

# not a GeoPackage
repo_path = tmp_path / "data3.sno"
r = cli_runner.invoke(
[f"--repo={repo_path}", "import-gpkg", tmp_path / "a.gpkg", "mytable"]
)
assert r.exit_code == NO_IMPORT_SOURCE, r
assert "a.gpkg' doesn't appear to be a valid GeoPackage" in r.stderr


@pytest.mark.slow
@pytest.mark.parametrize(*GPKG_IMPORTS)
def test_init_import_list(
Expand Down

0 comments on commit 1be74d3

Please sign in to comment.