Commit 81da469
authored
feat(python): expand layer management and headless camera API (#1770)
* feat(python): expand layer management and headless camera API
Scripting a map from Python needed a browser round trip or a raw project
dict for common tasks: reordering, duplicating, renaming layers, reading
attribute values, and moving the camera. These now work as plain project
mutations on Map and Layer, and the project authoring helpers are exported
from the top-level package for scripts that never display a widget.
* Address review feedback
- Route Map._resolve_layer through authoring.find_layer so scripting and the
MCP tools agree on what a layer reference means: id first, then exact name,
then case-insensitive, with a duplicated name raising instead of silently
picking one. Now that remove_layer accepts names, an arbitrary pick would
delete the wrong layer.
- Validate duplicate_layer's explicit name against the reserved basemap
pseudo-id, which rename_layer already rejects via update_layer.
- Route set_center through authoring.set_view so a manual recenter clears the
bbox fit_project_bounds recorded, instead of leaving a stale extent behind.
- Make Layer.index raise the documented ValueError for a removed handle rather
than a bare StopIteration, matching the other accessors.
- Add Map.bearing and Map.pitch read properties so every camera setter has a
matching getter.
- Correct the move_layer docstring: negative values follow sequence indexing,
not list.insert semantics.
- Sort __version__ into __all__ (RUF022) and make the README layer-handle
example self-contained.
* Address CodeRabbit review feedback
- Bind the bare `duplicate.index` access to `_` so the statement reads as a
deliberate property evaluation rather than dead code.
- Match on the reserved-name message instead of accepting any ValueError, so
the test cannot pass on an unrelated failure.
* Address Claude review feedback
- Route duplicate_layer through authoring.add_layer instead of reaching into
the private _reject_reserved_name, and reject a blank explicit name rather
than silently substituting the auto-generated one, matching the Map.name
setter.
- Stop deep-copying the whole project in describe(): copy the small summary
instead, which detaches the live mapView it returns without duplicating
every inlined GeoJSON blob to report a feature count.
- Document that remove_layer now raises on an unresolved or ambiguous
reference, where it used to be a silent no-op.
- Cover move_layer's negative-index semantics, which differ from
list.insert(-1, ...) and are easy to reintroduce a bug in.
* Address Claude review feedback
- Strip an explicit duplicate_layer name before storing it, matching the
Map.name setter, so " Clone " does not become a padded name that is
awkward to reference back.
- Document that the copy is appended to the draw order rather than placed
next to its source, which was previously unstated either way.
* Address Claude review feedback
- Sweep credentials from Layer.source and Layer.data. Both hand a layer record
straight to a caller, and a notebook auto-displays whatever a cell returns,
so a source built with request_headers or a signed URL would print its
secrets into an output that often gets committed. Factored the per-layer
sweep redact_credentials already ran into project.redact_layer so the two
paths cannot drift.
- Reject a blank name in rename_layer (and so in the Layer.name setter, which
delegates to it); authoring.update_layer guards only the reserved basemap
pseudo-id. Shares one _clean_layer_name helper with duplicate_layer.
- List the bearing and pitch read properties in the README table.
* Address Claude review feedback
- Redact Map.basemap the way Layer.source is redacted. MapTiler and Stadia put
an API key in the style URL itself, so reading it back in a notebook printed
the key; project.redact_url is the public entry point for the sweep
redact_credentials already applied to that field.
- Document that Layer.data copies an inlined geojson blob whole, and point at
properties()/describe() for the cases a summary covers.
* Address Claude review feedback
Redact URLs in layer_summary and describe_project rather than at the Map.describe
call site. A summary exists to be shown, and both callers show it somewhere
untrusted: a notebook cell that often gets committed, and an MCP tool result that
goes to a model client. Fixing it in authoring.py closes the same gap in the MCP
server's describe_project tool and keeps the one-place-per-change layering the
repo documents.1 parent d8b06e9 commit 81da469
7 files changed
Lines changed: 515 additions & 34 deletions
File tree
- python
- src/geolibre
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
92 | 129 | | |
93 | 130 | | |
94 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
5 | 12 | | |
| 13 | + | |
6 | 14 | | |
7 | 15 | | |
8 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
9 | 28 | | |
10 | 29 | | |
11 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
224 | 227 | | |
225 | 228 | | |
226 | 229 | | |
| |||
239 | 242 | | |
240 | 243 | | |
241 | 244 | | |
242 | | - | |
| 245 | + | |
243 | 246 | | |
244 | 247 | | |
245 | 248 | | |
| |||
257 | 260 | | |
258 | 261 | | |
259 | 262 | | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
260 | 266 | | |
261 | 267 | | |
262 | 268 | | |
| |||
279 | 285 | | |
280 | 286 | | |
281 | 287 | | |
| 288 | + | |
282 | 289 | | |
283 | 290 | | |
284 | 291 | | |
285 | 292 | | |
286 | | - | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
287 | 296 | | |
288 | 297 | | |
289 | 298 | | |
| |||
0 commit comments