Skip to content

Commit

Permalink
bump: version 0.7.0 → 0.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Apr 11, 2024
1 parent 9c5e301 commit 70eb07d
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 14 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 0.7.1 (2024-04-11)

### Fix

- update entities registration form to include status field
- remove usage of requests from validate.py in prep for dep removal

### Refactor

- remove missed print statements from OdkCentralAsync

## 0.7.0 (2024-04-03)

### Feat
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

PACKAGE := org.osm_fieldwork.py
NAME := osm-fieldwork
VERSION := 0.7.0
VERSION := 0.7.1

# All python source files
FILES := $(wildcard ./osm_fieldwork/*.py)
Expand Down
2 changes: 1 addition & 1 deletion osm_fieldwork/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.0"
__version__ = "0.7.1"
19 changes: 11 additions & 8 deletions osm_fieldwork/basemapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,20 @@ def makeBbox(
return bbox


def tileid_from_y_tile(filepath: Union[Path | str]):
def tileid_from_tms_path(filepath: Union[Path, str]):
"""Helper function to get the tile id from a tile in z/x/y directory structure.
Args:
filepath (Union[Path, str]): The path to the y tile in /z/x/y.jpg structure.
"""
# Get final two dirs + tile filename
parts = list(Path(filepath).parts[-3:])
# strip extension from y tile filename
parts[-1] = str(Path(parts[-1]).stem)
z, x, y = map(int, parts)
# Extract the final 3 parts from the TMS file path
zxy_path = Path(filepath).parts[-3:]
# Extract filename without extension
y_tile_filename = Path(zxy_path[-1]).stem
# If filename contains a dot, take the part before the dot as 'y'
y = int(y_tile_filename.split(".")[0]) if "." in y_tile_filename else int(y_tile_filename)
# Extract z and x values
z, x = map(int, zxy_path[:-1])
return zxy_to_tileid(z, x, y)


Expand Down Expand Up @@ -379,7 +382,7 @@ def tile_dir_to_pmtiles(outfile: str, tile_dir: str, bbox: tuple, attribution: s

for tile_path in tile_dir.rglob("*"):
if tile_path.is_file():
tile_id = tileid_from_y_tile(tile_path)
tile_id = tileid_from_tms_path(tile_path)

with open(tile_path, "rb") as tile:
writer.write_tile(tile_id, tile.read())
Expand Down Expand Up @@ -415,7 +418,7 @@ def create_basemap_file(
zooms="12-17",
outdir=None,
source="esri",
):
) -> None:
"""Create a basemap with given parameters.
Args:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pythonpath = "osm_fieldwork"

[tool.commitizen]
name = "cz_conventional_commits"
version = "0.7.0"
version = "0.7.1"
version_files = [
"pyproject.toml:version",
"osm_fieldwork/__version__.py",
Expand Down
42 changes: 40 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import pytest

# from pyxform.xls2xform import xls2xform_convert
from osm_fieldwork.OdkCentral import OdkAppUser, OdkForm, OdkProject
from osm_fieldwork.OdkCentral import OdkAppUser, OdkEntity, OdkForm, OdkProject

logging.basicConfig(
level="DEBUG",
Expand Down Expand Up @@ -152,7 +152,45 @@ def odk_form_cleanup(odk_form):
# After yield is test cleanup

# Delete form
success = xform.deleteForm(odk_id, "test_form")
success = xform.deleteForm(odk_id, form_name)
assert success


@pytest.fixture(scope="function")
def odk_entity(project_details) -> tuple:
"""Get entity for a project."""
odk_id = project_details.get("id")
entity = OdkEntity(
url="https://proxy",
user="test@hotosm.org",
passwd="Password1234",
)
return odk_id, entity


@pytest.fixture(scope="function")
def odk_entity_cleanup(odk_form, odk_entity):
"""Get Entity for project, with automatic cleanup after."""
odk_id, xform = odk_form
test_xform = testdata_dir / "buildings_entity_registration.xls"

# Create form
# FIXME not creating form correctly
form_name = xform.createForm(odk_id, str(test_xform), publish=True)

# Create entity
odk_id, entity = odk_entity
entity_json = entity.createEntity(odk_id, "buildings", "test entity", {"osm_id": "1", "geometry": "test"})
entity_uuid = entity_json.get("uuid")

# Before yield is used in tests
yield odk_id, "buildings", entity
# After yield is test cleanup

# Delete form
success = entity.deleteEntity(odk_id, "buildings", entity_uuid)
success = xform.deleteForm(odk_id, form_name)

assert success


Expand Down
25 changes: 24 additions & 1 deletion tests/test_basemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
import logging
import os
import shutil
from pathlib import Path

from osm_fieldwork.basemapper import BaseMapper
from pmtiles.reader import MemorySource
from pmtiles.reader import Reader as PMTileReader

from osm_fieldwork.basemapper import BaseMapper, create_basemap_file
from osm_fieldwork.sqlite import DataFile

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -66,5 +70,24 @@ def test_create():
assert hits == 2


def test_pmtiles():
"""Test PMTile creation via helper function."""
create_basemap_file(
boundary="-4.730494 41.650541 -4.725634 41.652874",
outfile=f"{rootdir}/../test.pmtiles",
zooms="12-14",
outdir=f"{rootdir}/../",
source="esri",
)
tiles = Path(f"{rootdir}/../test.pmtiles")
assert tiles.exists()
# Test reading
with open(tiles, "rb") as pmtile_file:
data = pmtile_file.read()
pmtile = PMTileReader(MemorySource(data))
assert pmtile.header().get("tile_data_length") == 75524
assert len(pmtile.metadata().keys()) == 1


if __name__ == "__main__":
test_create()

0 comments on commit 70eb07d

Please sign in to comment.