rusackas opened a new pull request, #45607:
URL: https://github.com/apache/superset/pull/45607
### SUMMARY
`Country Map GeoJSON Generator.ipynb` special-cases ~30 countries in one
growing notebook, mixing shared helper functions, per-country correction logic,
and inline `.plot()` previews. #45602 fixed the worst symptom (the whole file
diffing as binary), but a 30-section notebook is still awkward to review a
single-country change in, and painful to resolve real conflicts in.
This is a **prototype**, opened as a draft to validate the idea before
committing to converting the rest: per-country Python scripts instead of
notebook cells, a couple of small shared modules, and an orchestrator CLI.
**Converts 4 of the ~26 special-cased countries** (not all of them - see
Scope below), picked to cover distinct patterns rather than the easy ones:
- `morocco` - external source pinned to a commit, with a regex ISO-code fix
and a validation pass
- `italy` - one notebook section that produces *two* shipped outputs
(`italy_regions`, `italy_regions_and_autonomous_provinces`)
- `latvia` - an external source that can legitimately fail to load.
Deliberately changed from the notebook's behavior: the notebook prints a
warning and silently falls back to uncorrected data on a failed fetch; this
raises instead, so a broken source actually fails the build (matching #45588's
"fail the CI job on a notebook/build error" behavior instead of undermining it)
- `usa` - the classic "flying islands" case (Hawaii/Alaska repositioned),
exercising the one shared geometry helper ported so far (`reposition`)
### Layout
```
superset-frontend/plugins/plugin-chart-country-map/scripts/
build_maps.py # orchestrator CLI
maps/
context.py # BuildContext (Natural Earth data), plot
styles, aliases
data.py # Natural Earth download + load
helpers.py # shared geometry helpers (only `reposition`
so far)
output.py # simplify + save_geojson, ported from the
notebook's own logic
preview.py # --preview: per-country PNG thumbnail + a
contact-sheet grid
countries/
morocco.py, italy.py, latvia.py, usa.py
```
### Validation
Ran `build_maps.py --preview` against live Natural Earth data and the pinned
community sources. Compared every output to what's currently committed under
`src/countries/`:
| output | result |
|---|---|
| `morocco.geojson` | byte-for-byte identical |
| `italy_regions.geojson` | byte-for-byte identical |
| `italy_regions_and_autonomous_provinces.geojson` | byte-for-byte identical
|
| `latvia.geojson` | byte-for-byte identical |
| `usa.geojson` | byte-for-byte identical |
`--preview` also renders a working per-country PNG thumbnail and assembles
them into a contact-sheet grid image - a visual sanity check a reviewer (or
eventually the docs site) can look at without running Python. Alaska/Hawaii
visibly show up repositioned near the mainland in the USA thumbnail, confirming
the `reposition` helper is wired correctly, not just byte-matching by
coincidence.
`mypy`/`ruff`/`ruff-format` pass on the new code (added a `pyproject.toml`
per-file `TID251` ignore for this scripts tree, matching the existing top-level
`scripts/*` exemption, since this is standalone tooling with no `superset`
package import).
### Scope - what this PR deliberately does NOT do
- Doesn't convert the other ~22 special-cased countries, or the ~190 "plain"
countries that don't need a script at all (just a default Natural Earth lookup).
- Doesn't write `countries.ts` or `docs/data/countries.json` yet.
- Doesn't touch or retire the notebook - it stays as the source of truth
until (if) this approach is adopted for everything.
- Doesn't wire this into `update-country-maps.yml` (#45588).
If this pattern looks worth adopting, the follow-up is converting the rest,
building the "plain country" default path and the `countries.ts`/docs-json
writer, and only then retiring the notebook and repointing #45588 at
`build_maps.py`.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (this PR has no UI surface; see Validation above for the
thumbnail/contact-sheet check)
### TESTING INSTRUCTIONS
```
cd superset-frontend/plugins/plugin-chart-country-map/scripts
pip install geopandas shapely matplotlib requests
python3 build_maps.py --preview --out-dir /tmp/maps-out
# compare /tmp/maps-out/*.geojson against src/countries/*.geojson
```
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]