Make the monthly place check download every outline again instead of reusing the first-run files

This commit is contained in:
swaits committed 2026-11-20 12:11:26 -07:00
1 parent 5fcbf5e2d9
commit 7e4d1de494
5 files changed
+52 -11

No files matched your search

+19 -1
View File
@@ -255,6 +255,20 @@ def fetch(source, cache):
return dest, date.today().isoformat()
def clear_cache(cache):
"""Delete every cached source file so the next fetch downloads it again. fetch() keeps
a cached file for good; --refresh is how the monthly check measures against the outlines
as published today, not the ones first downloaded."""
gone = []
for src in SOURCES.values():
dest = os.path.join(cache, src.filename)
if os.path.isfile(dest):
os.remove(dest)
gone.append(src.filename)
_GMBA_CACHE.clear()
return gone
def _union_geoms(geoms):
shapely = _need_shapely()
g = shapely.union_all(list(geoms))
@@ -1206,7 +1220,9 @@ Subcommands:
candidates [--out DIR] [--allowlist FILE] GMBA ranges 3+ tracks cross, not allow-listed
apply PROPOSAL.json [--exclude FILE] write the records and places.toml
stated ... / stamp ... hand placements for trackless trails
--check re-measure and list every difference
--check [--refresh] re-measure and list every difference;
--refresh downloads every outline again first
(the monthly workflow always passes it)
Cache: $PLACES_CACHE, default $XDG_CACHE_HOME/longhikes-places.
"""
@@ -1224,6 +1240,8 @@ def main(argv=None):
return 0
_need_shapely()
cmd = argv[0]
if "--refresh" in argv:
clear_cache(cache_dir())
if cmd == "propose":
allow = load_allowlist(_opt(argv, "--allowlist", default_allowlist_path()))
outlines = catalogue(cache_dir(), allow)
+29
View File
@@ -394,6 +394,35 @@ def read_toml(path):
return _tomllib.load(f)
@unittest.skipUnless(HAVE, "shapely (the .venv-places venv) is not installed")
class RefreshTest(unittest.TestCase):
def test_fetch_keeps_a_cached_file_and_clear_cache_makes_the_next_fetch_download(self):
with tempfile.TemporaryDirectory() as cache:
src = P.SOURCES["gmba-v2"]
dest = os.path.join(cache, src.filename)
with open(dest, "w") as f:
f.write("old")
calls = []
real = P._download
P._download = lambda url, d: (calls.append(url), open(d, "w").write("new"))
try:
P.fetch(src, cache)
self.assertEqual(calls, [])
self.assertEqual(P.clear_cache(cache), [src.filename])
P.fetch(src, cache)
finally:
P._download = real
self.assertEqual(len(calls), 1)
with open(dest) as f:
self.assertEqual(f.read(), "new")
def test_the_monthly_workflow_checks_against_fresh_outlines(self):
with open(os.path.join(ROOT, ".github", "workflows", "places.yml")) as f:
text = f.read()
self.assertIn("place_trails.py --check --refresh", text)
self.assertNotIn("actions/cache", text)
@unittest.skipUnless(HAVE, "shapely (the .venv-places venv) is not installed")
class ApplyTest(unittest.TestCase):
def setUp(self):