Satisfy the lint gates the macOS work walked past
Import order, a docstring reworded rather than have "macOS" capitalised into something that is not the product's name, two over-long test lines, and _tls_context moved below the logger it uses so the module keeps its shape: docstring, imports, constants, logger, then code. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
9a58bc04bb
commit
2e40603a64
5 files changed
+61
-58
No files matched your search
@@ -78,6 +78,7 @@ def ble_unavailable_reason() -> str | None:
|
||||
"""
|
||||
return _ble_unavailable
|
||||
|
||||
|
||||
#: Default seconds to watch for one *known* companion's advertisement while waiting for it to
|
||||
#: come back (see :func:`find_ble_device`). Deliberately longer than the startup scan: nothing
|
||||
#: is waiting on it, the watch ends the instant the device is heard, and a companion that just
|
||||
|
||||
@@ -58,6 +58,58 @@ from typing import NamedTuple
|
||||
from .. import __version__
|
||||
from ..core.mvt import Layer, decode_tile, dumps_layers, loads_layers
|
||||
|
||||
#: OpenFreeMap planet TileJSON — its ``tiles`` array holds the current versioned template.
|
||||
DEFAULT_TILEJSON_URL = "https://tiles.openfreemap.org/planet"
|
||||
|
||||
#: Sent on every tile request. OpenFreeMap asks for no API key, so the user agent is the
|
||||
#: only thing telling one client from another — which is how an operator reaches whoever is
|
||||
#: costing them bandwidth, and why a stub URL or a version that has drifted is worse than
|
||||
#: none at all. The version is the package's own :data:`~meshterm.__version__` rather than
|
||||
#: an ``importlib.metadata`` lookup: MeshTerm is routinely run straight from a checkout
|
||||
#: (this repo's venv, the PicoCalc's deploy) with no installed distribution to read, so the
|
||||
#: metadata call would be the one that raises, and it would be a second version to keep in
|
||||
#: step with the first. Built once at import because it never changes and cannot fail —
|
||||
#: the tile path is no place to discover either.
|
||||
_USER_AGENT = f"MeshTerm/{__version__} (+https://github.com/jpmartineau/MeshTerm; mesh node map)"
|
||||
|
||||
#: How long a tile the source gave no answer about is left alone before it is asked for
|
||||
#: again. Long enough that a genuinely offline map isn't retrying every visible tile on a
|
||||
#: loop, short enough that a Wi-Fi blip costs a few seconds of missing streets rather than
|
||||
#: the rest of the session. It lives here, beside the source that failed to answer, because
|
||||
#: both surfaces that draw tiles wait out the same cooldown (see
|
||||
#: :meth:`meshterm.ui.map_screen.MapScreen._load` and the minimap's).
|
||||
TILE_RETRY_SECONDS = 20.0
|
||||
|
||||
#: Fallback max tile zoom if the TileJSON doesn't declare one (OpenFreeMap serves 14).
|
||||
_DEFAULT_MAX_ZOOM = 14
|
||||
|
||||
#: HTTP statuses that are the source *answering* "there is no such resource". Everything
|
||||
#: else — 429, 5xx, and every transport error — is the absence of an answer.
|
||||
_ABSENT_STATUSES = frozenset({404, 410})
|
||||
|
||||
#: Ceiling on the decoded sidecar cache. Decoded tiles run ~2.4x the size of the bytes
|
||||
#: they came from, and unlike those bytes they can be rebuilt from what's already on disk,
|
||||
#: so this half of the cache is the half that gets a budget.
|
||||
_DEFAULT_MAX_DECODED_BYTES = 64 * 1024 * 1024
|
||||
|
||||
#: How much must be written before the sidecar budget is checked again. The check walks
|
||||
#: the directory, which is slow on the SD card the PicoCalc runs from.
|
||||
_PRUNE_AFTER_BYTES = 8 * 1024 * 1024
|
||||
|
||||
#: Decoded tiles held in RAM. A viewport spans at most a handful of tiles, so this covers
|
||||
#: the view plus the ring a pan or a zoom step reaches into, and little more — the PicoCalc
|
||||
#: has 100 MB of RAM in total and decoded layers are not small.
|
||||
_MEMO_TILES = 24
|
||||
|
||||
#: How long a failed TileJSON resolve stands before the source will ask again. The PicoCalc
|
||||
#: brings its Wi-Fi up some 40 seconds into the boot, well after the app it was started
|
||||
#: alongside can reach the menu — so "offline" asked once at open is a verdict on the
|
||||
#: *device's boot order*, not on the network, and latching it costs the whole session's
|
||||
#: basemap. Long enough that a genuinely offline session isn't retrying into a void.
|
||||
_RESOLVE_RETRY_SECONDS = 30.0
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
#: Where the operating system keeps its CA bundle, most specific first. Only consulted when
|
||||
#: the default context came up empty (see :func:`_tls_context`) — macOS and Alpine put it at
|
||||
@@ -111,58 +163,6 @@ def _tls_context() -> ssl.SSLContext | None:
|
||||
_log.debug("could not build a TLS context, using urllib's default: %s", exc)
|
||||
return None
|
||||
|
||||
#: OpenFreeMap planet TileJSON — its ``tiles`` array holds the current versioned template.
|
||||
DEFAULT_TILEJSON_URL = "https://tiles.openfreemap.org/planet"
|
||||
|
||||
#: Sent on every tile request. OpenFreeMap asks for no API key, so the user agent is the
|
||||
#: only thing telling one client from another — which is how an operator reaches whoever is
|
||||
#: costing them bandwidth, and why a stub URL or a version that has drifted is worse than
|
||||
#: none at all. The version is the package's own :data:`~meshterm.__version__` rather than
|
||||
#: an ``importlib.metadata`` lookup: MeshTerm is routinely run straight from a checkout
|
||||
#: (this repo's venv, the PicoCalc's deploy) with no installed distribution to read, so the
|
||||
#: metadata call would be the one that raises, and it would be a second version to keep in
|
||||
#: step with the first. Built once at import because it never changes and cannot fail —
|
||||
#: the tile path is no place to discover either.
|
||||
_USER_AGENT = f"MeshTerm/{__version__} (+https://github.com/jpmartineau/MeshTerm; mesh node map)"
|
||||
|
||||
#: How long a tile the source gave no answer about is left alone before it is asked for
|
||||
#: again. Long enough that a genuinely offline map isn't retrying every visible tile on a
|
||||
#: loop, short enough that a Wi-Fi blip costs a few seconds of missing streets rather than
|
||||
#: the rest of the session. It lives here, beside the source that failed to answer, because
|
||||
#: both surfaces that draw tiles wait out the same cooldown (see
|
||||
#: :meth:`meshterm.ui.map_screen.MapScreen._load` and the minimap's).
|
||||
TILE_RETRY_SECONDS = 20.0
|
||||
|
||||
#: Fallback max tile zoom if the TileJSON doesn't declare one (OpenFreeMap serves 14).
|
||||
_DEFAULT_MAX_ZOOM = 14
|
||||
|
||||
#: HTTP statuses that are the source *answering* "there is no such resource". Everything
|
||||
#: else — 429, 5xx, and every transport error — is the absence of an answer.
|
||||
_ABSENT_STATUSES = frozenset({404, 410})
|
||||
|
||||
#: Ceiling on the decoded sidecar cache. Decoded tiles run ~2.4x the size of the bytes
|
||||
#: they came from, and unlike those bytes they can be rebuilt from what's already on disk,
|
||||
#: so this half of the cache is the half that gets a budget.
|
||||
_DEFAULT_MAX_DECODED_BYTES = 64 * 1024 * 1024
|
||||
|
||||
#: How much must be written before the sidecar budget is checked again. The check walks
|
||||
#: the directory, which is slow on the SD card the PicoCalc runs from.
|
||||
_PRUNE_AFTER_BYTES = 8 * 1024 * 1024
|
||||
|
||||
#: Decoded tiles held in RAM. A viewport spans at most a handful of tiles, so this covers
|
||||
#: the view plus the ring a pan or a zoom step reaches into, and little more — the PicoCalc
|
||||
#: has 100 MB of RAM in total and decoded layers are not small.
|
||||
_MEMO_TILES = 24
|
||||
|
||||
#: How long a failed TileJSON resolve stands before the source will ask again. The PicoCalc
|
||||
#: brings its Wi-Fi up some 40 seconds into the boot, well after the app it was started
|
||||
#: alongside can reach the menu — so "offline" asked once at open is a verdict on the
|
||||
#: *device's boot order*, not on the network, and latching it costs the whole session's
|
||||
#: basemap. Long enough that a genuinely offline session isn't retrying into a void.
|
||||
_RESOLVE_RETRY_SECONDS = 30.0
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class _Response(NamedTuple):
|
||||
"""One HTTP GET's outcome: whether the server answered, and what it said.
|
||||
|
||||
@@ -227,7 +227,7 @@ def test_the_connection_is_built_from_this_device_s_own_endpoint(
|
||||
|
||||
|
||||
def test_the_pin_is_withheld_on_macos(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""macOS gets no PIN: handing one over is what *breaks* the connection there.
|
||||
"""No PIN is handed to macOS: supplying one is what *breaks* the connection there.
|
||||
|
||||
``BLEConnection.connect`` responds to a PIN by calling bleak's ``pair()``, and
|
||||
CoreBluetooth has no pairing API — the macOS backend raises outright, whereupon the
|
||||
|
||||
+6
-2
@@ -823,7 +823,9 @@ def test_basemap_finds_a_ca_bundle_when_the_default_store_is_empty(
|
||||
def load_verify_locations(self, cafile=None, capath=None, cadata=None): # type: ignore[override]
|
||||
loaded.append(cafile or "")
|
||||
|
||||
monkeypatch.setattr(ssl, "create_default_context", lambda *a, **k: _EmptyStore(ssl.PROTOCOL_TLS_CLIENT))
|
||||
monkeypatch.setattr(
|
||||
ssl, "create_default_context", lambda *a, **k: _EmptyStore(ssl.PROTOCOL_TLS_CLIENT)
|
||||
)
|
||||
monkeypatch.setattr(basemap_mod, "_CA_BUNDLES", (str(tmp_path / "nope.pem"), str(bundle)))
|
||||
|
||||
basemap_mod._tls_context.cache_clear()
|
||||
@@ -846,7 +848,9 @@ def test_basemap_never_disables_verification(monkeypatch: pytest.MonkeyPatch) ->
|
||||
def get_ca_certs(self, binary_form: bool = False): # type: ignore[override]
|
||||
return []
|
||||
|
||||
monkeypatch.setattr(ssl, "create_default_context", lambda *a, **k: _EmptyStore(ssl.PROTOCOL_TLS_CLIENT))
|
||||
monkeypatch.setattr(
|
||||
ssl, "create_default_context", lambda *a, **k: _EmptyStore(ssl.PROTOCOL_TLS_CLIENT)
|
||||
)
|
||||
monkeypatch.setattr(basemap_mod, "_CA_BUNDLES", ("/nonexistent/ca.pem",))
|
||||
|
||||
basemap_mod._tls_context.cache_clear()
|
||||
|
||||
+1
-3
@@ -1371,9 +1371,7 @@ def test_device_picker_address_lane_is_the_one_that_adapts() -> None:
|
||||
# And where the name cannot fit whatever happens, the address is left whole rather
|
||||
# than ellipsized alongside it -- one cut in the row instead of two.
|
||||
sprawling = [
|
||||
DiscoveredDevice(
|
||||
"/dev/ttyUSB0", product="CP2102 USB to UART Bridge Controller", vid=0x10C4
|
||||
)
|
||||
DiscoveredDevice("/dev/ttyUSB0", product="CP2102 USB to UART Bridge Controller", vid=0x10C4)
|
||||
]
|
||||
name_w, port_w = _lane_widths(sprawling, {})
|
||||
assert port_w == cell_len("/dev/ttyUSB0")
|
||||
|
||||
Reference in new issue
Block a user