Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactorings and a bunch of small changes as well as lint cli start #10

Merged
merged 26 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 80 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 39 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "pyutiles"
version = "0.2.0"
edition = "2021"
version.workspace = true
include = ["src/**/*", "Cargo.toml", "LICENSE", "README.md"]
license = "MIT OR Apache-2.0"
edition.workspace = true
license.workspace = true
authors.workspace = true

[[bin]]
name = "utiles"
Expand All @@ -29,9 +30,43 @@ opt-level = 0
[profile.release]
opt-level = 3
strip = true
lto = true

[dev-dependencies]
pyo3 = { version = "0.20.0", features = ["auto-initialize"] }
pyo3= { workspace = true , features = ["auto-initialize"] }

[build-dependencies]
pyo3-build-config.workspace = true

[workspace]
resolver = "2"
members = [
"crates/utiles",
"crates/utilesqlite",
"crates/utiles-cli"
]

[workspace.package]
edition = "2021"
version = "0.2.0"
homepage = "https://github.com/jessekrubin/utiles"
documentation = "https://github.com/jessekrubin/utiles"
repository = "https://github.com/jessekrubin/utiles"
authors = ["Jesse K. Rubin <[email protected]>"]
license = "MIT OR Apache-2.0"

[workspace.dependencies]
anyhow = "1.0.75"
fast_hilbert = "2.0.0"
geo-types = "0.7.9"
geojson = "0.24.1"
pyo3 = "0.20.0"
pyo3-build-config = "0.20.0"
rusqlite = { version = "0.29.0", features = ["bundled", "vtab", "blob"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.96"
thiserror = "1.0.50"
tilejson = "0.3.2"
tokio = { version = "1.33.0", features = ["full"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.17", features = ["serde", "serde_json", "env-filter"] }
90 changes: 84 additions & 6 deletions bench/test_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import mercantile
import pytest
from pytest_benchmark.fixture import BenchmarkFixture
from pmtiles.tile import zxy_to_tileid, tileid_to_zxy

import utiles

Expand All @@ -29,12 +30,6 @@
)


# @pytest.mark.parametrize(
# "tile",
# [
# pytest.param(t, id=str(t)) for t in TEST_TILES
# ],
# )
@tile_pytest_params
@pytest.mark.parametrize(
"func",
Expand Down Expand Up @@ -175,3 +170,86 @@ def test_feature(
) -> None:
"""Get feature of tile"""
benchmark(func, mercantile.Tile(1, 2, 3))


# ===================================================================
# PMTILES ~ PMTILES ~ PMTILES ~ PMTILES ~ PMTILES ~ PMTILES ~ PMTILES
# ===================================================================
def _ut_xyz2pmtileid(x: int, y: int, z: int) -> int:
return utiles.pmtileid(x, y, z)


def _pm_xyz2pmtileid(x: int, y: int, z: int) -> int:
return zxy_to_tileid(z, x, y)


def _ut_pmtileid2xyz(tileid: int) -> Tuple[int, int, int]:
return utiles.from_pmtileid(tileid)


def _pm_pmtileid2xyz(tileid: int) -> Tuple[int, int, int]:
return tileid_to_zxy(tileid)


def test_xyz2pmtileid_eq():
for tile in TEST_TILES:
x, y, z = tile
pmtileid_from_pmtiles = zxy_to_tileid(
z,
x,
y,
)
pmtileid_from_utiles = utiles.pmtileid(x, y, z)
assert pmtileid_from_pmtiles == pmtileid_from_utiles

# round trip
(x, y, z) = _ut_pmtileid2xyz(pmtileid_from_utiles)
zxy_from_pmtiles = tileid_to_zxy(pmtileid_from_pmtiles)
assert (z, x, y) == zxy_from_pmtiles


@pytest.mark.benchmark(
group="xyz2pmtile",
)
@pytest.mark.parametrize(
"tile",
[pytest.param(t, id=str(t)) for t in TEST_TILES],
)
@pytest.mark.parametrize(
"func",
[
pytest.param(_pm_xyz2pmtileid, id="pmtiles"),
pytest.param(_ut_xyz2pmtileid, id="utiles"),
],
)
def test_xyz2pmtileid(
tile: Tuple[int, int, int],
func: Callable[[int, int, int], List[str]],
benchmark: BenchmarkFixture,
) -> None:
"""Get feature of tile"""
benchmark(func, *tile)


@pytest.mark.benchmark(
group="pmtile2xyz",
)
@pytest.mark.parametrize(
"tile",
[pytest.param(t, id=str(t)) for t in TEST_TILES],
)
@pytest.mark.parametrize(
"func",
[
pytest.param(tileid_to_zxy, id="pmtiles"),
pytest.param(utiles.pmtileid2xyz, id="utiles"),
],
)
def test_pmtileid2xyz(
tile: Tuple[int, int, int],
func: Callable[[int, int, int], List[str]],
benchmark: BenchmarkFixture,
) -> None:
"""Get feature of tile"""
pmid = utiles.pmtileid(*tile)
benchmark(func, pmid)
Loading