fix(산림 조각): 원자료 지문을 경로 · 크기로 바꿈 — 수정 시각 뺌 (PLAN 632-0 · 요구 542)
git 으로 옮겨도 지문이 같아 데스크탑에서 올린 색인 · 조각을 그대로 씀. 새 지문: forest_road 3f4fcf3e · eco_forest 1d125434 · forest_soil a9a02742 시험: 같은 내용 · 다른 시각 = 같은 지문 · 크기 바뀜 = 다른 지문. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015uTVHHoPiWty5oQce1oAXD
This commit is contained in:
@@ -149,18 +149,17 @@ def sources(name: str) -> list[Path]:
|
||||
|
||||
@functools.cache
|
||||
def _stamp(name: str) -> str | None:
|
||||
"""원자료 지문(SHP · DBF 크기 · 수정 시각) — 없으면 None.
|
||||
ponytail: 프로세스마다 한 번 셈 · 원자료를 바꾸면 서버를 다시 켬."""
|
||||
"""원자료 지문(SHP · DBF 상대 경로 · 크기) — 없으면 None.
|
||||
ponytail: 수정 시각 뺌(git 으로 옮기면 시각이 달라짐) · 원자료가 바뀌면 크기도 바뀐다는 전제 —
|
||||
같은 크기로 내용만 바뀐 것은 못 알아봄(그때는 `RULE_VERSION` 을 올림) ·
|
||||
프로세스마다 한 번 셈 · 원자료를 바꾸면 서버를 다시 켬."""
|
||||
files = sources(name)
|
||||
if not files:
|
||||
return None
|
||||
parts = []
|
||||
for shp in files:
|
||||
for path in (shp, shp.with_suffix(".dbf")):
|
||||
stat = path.stat()
|
||||
parts.append(
|
||||
f"{path.relative_to(DATA_ROOT).as_posix()}:{stat.st_size}:{stat.st_mtime_ns}"
|
||||
)
|
||||
parts.append(f"{path.relative_to(DATA_ROOT).as_posix()}:{path.stat().st_size}")
|
||||
return hashlib.sha1("\n".join(parts).encode()).hexdigest()[:8]
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
import io
|
||||
import logging
|
||||
import math
|
||||
import os
|
||||
|
||||
import geopandas as gpd
|
||||
import mapbox_vector_tile
|
||||
@@ -143,6 +144,19 @@ def test_empty_tile_saved_and_second_is_file(data, monkeypatch):
|
||||
assert vt.ensure_tile("forest_road", *tile) == first
|
||||
|
||||
|
||||
def test_stamp_path_and_size_only(data):
|
||||
"""지문 = 경로 · 크기 — 시각만 달라지면 같고 크기가 바뀌면 다름(PLAN 632-0)."""
|
||||
shp = data / "data_forest" / "임도망도" / "시험도" / "1.shp"
|
||||
before = vt._stamp("forest_road")
|
||||
os.utime(shp, ns=(1_000_000_000, 1_000_000_000))
|
||||
vt._stamp.cache_clear()
|
||||
assert vt._stamp("forest_road") == before
|
||||
with shp.with_suffix(".dbf").open("ab") as fp:
|
||||
fp.write(b"\0")
|
||||
vt._stamp.cache_clear()
|
||||
assert vt._stamp("forest_road") != before
|
||||
|
||||
|
||||
def test_range_and_unknown(data):
|
||||
with pytest.raises(KeyError):
|
||||
vt.ensure_tile("forest_road", 7, 0, 0)
|
||||
|
||||
Reference in New Issue
Block a user