Commit 488f58a
authored
Refactor GeoTIFF Phase 5d: extract _cog_http.py from _reader.py (#2262)
* Refactor GeoTIFF Phase 5d: extract _cog_http.py from _reader.py (#2258)
Move the COG-over-HTTP transport layer (`_parse_cog_http_meta`,
`_read_cog_http`, `_fetch_decode_cog_http_strips`,
`_fetch_decode_cog_http_tiles`) plus the `INITIAL_HTTP_HEADER_BYTES` /
`MAX_HTTP_HEADER_BYTES` constants into a new `_cog_http.py`. `_reader.py`
drops from 1258 to 429 lines.
The public import surface stays intact: `_reader.py` re-exports the
moved names so `from xrspatial.geotiff._reader import _read_cog_http`
and friends keep working unchanged.
`_read_cog_http` resolves `_HTTPSource`, `_parse_cog_http_meta`,
`_fetch_decode_cog_http_tiles`, `_decode_strip_or_tile`, and
`_apply_photometric_miniswhite` through the `_reader` module namespace
at call time so existing tests that
`monkeypatch.setattr(_reader, '_HTTPSource', ...)` (and friends)
continue to intercept the collaborators. `_parse_cog_http_meta` reads
`MAX_HTTP_HEADER_BYTES` and `INITIAL_HTTP_HEADER_BYTES` the same way so
`test_http_meta_buffer_1718`'s cap-shrinking patch keeps working.
Part of #2211.
* Address PR review nits: TYPE_CHECKING import, comments (#2258)
* Move `_HTTPSource` to `TYPE_CHECKING` in `_cog_http.py` so the only
module-level binding of the name is a type annotation; the runtime
collaborator is always `_reader._HTTPSource`.
* Drop direct `_apply_photometric_miniswhite` / `_decode_strip_or_tile`
imports from `_cog_http.py` since both are looked up through `_reader`
at call time. Comment in the import block explains which names from
`_decode` are still used directly.
* Add a module-level note about why `from . import _reader` is lazy
(circular load order) and an index of every name looked up through
the `_reader` namespace for monkeypatch reasons.
* Add a comment in `_parse_cog_http_meta` explaining the one-shot
capture of `INITIAL_HTTP_HEADER_BYTES` / `MAX_HTTP_HEADER_BYTES` is
behaviourally equivalent to the original per-iteration global read
(the constants are never mutated mid-call).
* Add a comment in `__init__.py` explaining why this site imports
`_parse_cog_http_meta` from `_cog_http` directly while
`_backends/dask.py` keeps `_HTTPSource` going through `_reader`.
* Restore module-level _HTTPSource import for type-hint introspection (#2258)
The previous nit-fix commit moved `_HTTPSource` under TYPE_CHECKING,
which broke `typing.get_type_hints()` against `_parse_cog_http_meta`,
`_fetch_decode_cog_http_strips`, and `_fetch_decode_cog_http_tiles`.
The function objects are also re-exported through `_reader`, so the
breakage propagated to `_reader._parse_cog_http_meta` etc. as well.
Nothing in the codebase calls `get_type_hints` on these helpers today,
but the original `_reader.py` carried a real `_HTTPSource` import, so
removing it was a subtle behavioural regression rather than a cleanup.
Restore the runtime import and replace the TYPE_CHECKING block with a
comment that explains why the name lives in the imports but the live
runtime collaborator is always `_reader._HTTPSource`.1 parent 1bbb95f commit 488f58a
4 files changed
Lines changed: 1039 additions & 859 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
217 | 227 | | |
218 | | - | |
219 | 228 | | |
220 | 229 | | |
221 | 230 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | | - | |
| 190 | + | |
191 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
192 | 196 | | |
193 | 197 | | |
194 | 198 | | |
| |||
548 | 552 | | |
549 | 553 | | |
550 | 554 | | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
556 | 558 | | |
557 | 559 | | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
558 | 564 | | |
559 | 565 | | |
560 | 566 | | |
| |||
0 commit comments