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

+2 -8
View File
@@ -1,7 +1,7 @@
name: Places
# The monthly check that every record's places still match the published outlines. It downloads
# the current outlines, measures every track again and fails with the list of differences.
# every outline again (no cache is kept between runs, and --refresh clears any there is), measures every track again and fails with the list of differences.
on:
schedule:
- cron: "0 6 1 * *"
@@ -15,11 +15,5 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: actions/cache@v4
with:
path: ~/.cache/longhikes-places
key: places-outlines-${{ github.run_id }}
restore-keys: |
places-outlines-
- run: pip install -r tools/place_trails.requirements.txt
- run: python tools/place_trails.py --check
- run: python tools/place_trails.py --check --refresh
+1 -1
View File
@@ -6,7 +6,7 @@
- The Places page lists them in three new sections. A state's page links to the parks, ranges and wilderness areas in it, and a trail's page links to each place it is in. A nested range also counts for the range around it, so a Teton Range trail is on the Rocky Mountains page too. Typing a place's name in search finds its trails.
- A trail is in a place when at least a mile of its track lies inside the place's published outline. For the 124 trails that have a track this was measured against the outlines. For the 99 that have none it comes from a page that names the trail in the place: 93 of them are placed in this way, and 6 are in none. In all, 187 trails are in at least one place and 36 are in none.
- Park outlines are from the National Park Service, Land Resources Division (public domain) and, for Canada, Environment and Climate Change Canada's CPCAD (Open Government Licence, Canada). Wilderness outlines are from Wilderness Connect, University of Montana (public domain). Range outlines are from the GMBA Mountain Inventory v2 (Snethlage et al. 2022, CC BY 4.0). `SOURCES.md` has the terms.
- For contributors: every trail now carries its places, the date they were checked and, for a trail with a track, which track was measured (`places_checked`, `places_track` and `[[place]]` in the trail's file; `places.toml` holds the places). `tools/place_trails.py` measures and writes them, the validator fails a trail with no check date or with a track changed since, and a monthly workflow re-measures every track against the current outlines. `docs/audit.md` is the new checklist for the monthly audit, with a step to look again at each place that rests on a page.
- For contributors: every trail now carries its places, the date they were checked and, for a trail with a track, which track was measured (`places_checked`, `places_track` and `[[place]]` in the trail's file; `places.toml` holds the places). `tools/place_trails.py` measures and writes them, the validator fails a trail with no check date or with a track changed since, and a monthly workflow downloads every outline again and re-measures every track against it (`--check --refresh`; the workflow keeps no cache). `docs/audit.md` is the new checklist for the monthly audit, with a step to look again at each place that rests on a page.
## 2026-11-20 - Every season now says where it came from
+1 -1
View File
@@ -15,7 +15,7 @@ down the list in order and stop at the first step that fails.
`OK history`. A changed fact needs a new history entry.
5. **Run both test suites.** `python3 -m unittest discover tools/tests` and
`python3 -m unittest discover -s web/tests` must both pass.
6. **Check the places.** `python3 tools/place_trails.py --check` downloads the current outlines,
6. **Check the places.** `python3 tools/place_trails.py --check --refresh` downloads every outline again (without `--refresh` it reuses the files already in the cache, which are the ones first downloaded),
measures every track again and prints each difference from the records, one per line:
- a place gained or lost by a trail: re-run `place_trails.py propose`, read the line, and
apply it only when the new outline is right;
+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):