Put a placed range's parents in the registry when apply writes it
Records never store parents, so apply left Rocky Mountains and the other great systems out of places.toml while a child's within named them. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2fbce06f42
commit
246e2938f2
2 files changed
+39
-2
No files matched your search
+21
-2
@@ -1020,6 +1020,26 @@ def apply(proposal_path, root, today, exclude=frozenset()):
|
||||
if v.get("within"):
|
||||
entry["within"] = list(v["within"])
|
||||
entries.append(entry)
|
||||
# a parent range (within) is in the registry though no record names it: records never
|
||||
# store parents, and the build closes membership over within
|
||||
todo = [("range", w) for x in entries for w in (x.get("within") or ())]
|
||||
have = {(x["kind"], x["slug"]) for x in entries}
|
||||
while todo:
|
||||
k = todo.pop()
|
||||
if k in have:
|
||||
continue
|
||||
v = per_place.get(f"{k[0]}/{k[1]}")
|
||||
if v is None:
|
||||
raise ValueError(f"{k[0]}/{k[1]} is the parent of a placed range but was not measured")
|
||||
have.add(k)
|
||||
entry = {"slug": v["slug"], "kind": v["kind"], "name": v["name"], "where": v["where"],
|
||||
"source": v["source"], "source_id": v["source_id"],
|
||||
"source_version": versions.get(v["source"], ""), "box": v["box"]}
|
||||
if v.get("within"):
|
||||
entry["within"] = list(v["within"])
|
||||
todo.extend(("range", w) for w in v["within"])
|
||||
entries.append(entry)
|
||||
parent_keys = set(have)
|
||||
# keep registry entries a record still names (stated placements apply never
|
||||
# touches), and every within parent of a kept entry
|
||||
import build_index
|
||||
@@ -1032,8 +1052,7 @@ def apply(proposal_path, root, today, exclude=frozenset()):
|
||||
for e in registry_entries(root):
|
||||
if (e.get("kind"), e.get("slug")) not in have:
|
||||
entries.append(e)
|
||||
parents = {("range", s) for x in entries for s in (x.get("within") or [])}
|
||||
entries = [e for e in entries if (e["kind"], e["slug"]) in still_named | parents]
|
||||
entries = [e for e in entries if (e["kind"], e["slug"]) in still_named | parent_keys]
|
||||
write_registry(root, entries)
|
||||
return written
|
||||
|
||||
|
||||
@@ -479,6 +479,24 @@ class ApplyTest(unittest.TestCase):
|
||||
self.assertEqual(reg[0]["source_version"], "2026-11-20")
|
||||
self.assertEqual(reg[0]["box"], [-110.0, 43.0, -109.0, 44.0])
|
||||
|
||||
def test_the_registry_holds_the_parent_of_a_named_range_though_no_record_names_it(self):
|
||||
big = outline("range", "R0", "Big Range", Polygon([(-111, 42), (-108, 42), (-108, 45), (-111, 45)]))
|
||||
big.path = "World > Big Range"
|
||||
small = outline("range", "R1", "Small Range", Polygon([(-110, 43), (-109, 43), (-109, 44), (-110, 44)]))
|
||||
small.path = "World > Big Range > Small Range"
|
||||
small.within = ("big-range",)
|
||||
track = LineString([(-109.5, 43.2), (-109.5, 43.29)])
|
||||
p = P.propose([rec("aa", ["WY"], track), rec("bb", ["WY"], track), rec("cc", ["WY"], track)],
|
||||
[big, small])
|
||||
p.versions = {"nps": "2026-11-20"}
|
||||
d = os.path.join(self.root, "out2")
|
||||
P.render_proposal(p, os.path.join(d, "proposal.md"))
|
||||
P.apply(os.path.join(d, "proposal.json"), self.root, "2026-11-20")
|
||||
self.assertEqual([pl["slug"] for pl in read_toml(self.trail_toml("aa"))["place"]], ["small-range"])
|
||||
reg = {e["slug"]: e for e in read_toml(os.path.join(self.root, "places.toml"))["place"]}
|
||||
self.assertEqual(set(reg), {"big-range", "small-range"})
|
||||
self.assertEqual(reg["small-range"]["within"], ["big-range"])
|
||||
|
||||
def test_a_reviewed_where_in_the_registry_survives_a_rerun(self):
|
||||
P.apply(self.pjson, self.root, "2026-11-20")
|
||||
path = os.path.join(self.root, "places.toml")
|
||||
|
||||
Reference in new issue
Block a user