From 7e4d1de4947ebd2e36143197931eee31fbf6db94 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Fri, 20 Nov 2026 12:11:26 -0700 Subject: [PATCH] Make the monthly place check download every outline again instead of reusing the first-run files --- .github/workflows/places.yml | 10 ++-------- CHANGELOG.md | 2 +- docs/audit.md | 2 +- tools/place_trails.py | 20 +++++++++++++++++++- tools/tests/test_place_trails.py | 29 +++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 11 deletions(-) diff --git a/.github/workflows/places.yml b/.github/workflows/places.yml index 3ce0436..8ba1c3c 100644 --- a/.github/workflows/places.yml +++ b/.github/workflows/places.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 228e49f..020f4b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/audit.md b/docs/audit.md index 114c19d..0573b63 100644 --- a/docs/audit.md +++ b/docs/audit.md @@ -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; diff --git a/tools/place_trails.py b/tools/place_trails.py index 8e51ae5..f9529eb 100644 --- a/tools/place_trails.py +++ b/tools/place_trails.py @@ -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) diff --git a/tools/tests/test_place_trails.py b/tools/tests/test_place_trails.py index 3392ed0..3f0855e 100644 --- a/tools/tests/test_place_trails.py +++ b/tools/tests/test_place_trails.py @@ -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):