File size: 2,037 Bytes
c6dda10
aba2c64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Mapbox Static Images metadata only — runtime fetch has been removed."""

from __future__ import annotations

import os

MAPBOX_STYLE = "mapbox/satellite-v9"
MAPBOX_STATIC_BASE = "https://api.mapbox.com/styles/v1"
MAPBOX_ATTRIBUTION = "© Mapbox © OpenStreetMap © Maxar"


def mapbox_style() -> str:
    return (
        os.environ.get("NUTONIC_MAPBOX_STATIC_STYLE") or os.environ.get("MAPBOX_STATIC_STYLE") or MAPBOX_STYLE
    ).strip()


def mapbox_static_base() -> str:
    return (
        os.environ.get("NUTONIC_MAPBOX_STATIC_BASE")
        or os.environ.get("MAPBOX_STATIC_BASE")
        or MAPBOX_STATIC_BASE
    ).strip().rstrip("/")


def mapbox_attribution() -> str:
    return (
        os.environ.get("NUTONIC_MAPBOX_ATTRIBUTION")
        or os.environ.get("MAPBOX_ATTRIBUTION")
        or MAPBOX_ATTRIBUTION
    ).strip()


def mapbox_timeout_seconds() -> float:
    return _env_float(
        "NUTONIC_MAPBOX_TIMEOUT_SECONDS",
        "MAPBOX_TIMEOUT_SECONDS",
        default=120.0,
        minimum=1.0,
    )


def mapbox_retry_count() -> int:
    return _env_int("NUTONIC_MAPBOX_RETRY_COUNT", "MAPBOX_RETRY_COUNT", default=1, minimum=0)


def mapbox_source_metadata() -> dict[str, str]:
    return {
        "provider": "mapbox",
        "style": mapbox_style(),
        "static_base": mapbox_static_base(),
        "attribution": mapbox_attribution(),
    }


def _env_float(*names: str, default: float, minimum: float) -> float:
    for name in names:
        raw = os.environ.get(name)
        if raw is None or not raw.strip():
            continue
        try:
            return max(minimum, float(raw.strip()))
        except ValueError:
            return default
    return default


def _env_int(*names: str, default: int, minimum: int) -> int:
    for name in names:
        raw = os.environ.get(name)
        if raw is None or not raw.strip():
            continue
        try:
            return max(minimum, int(raw.strip()))
        except ValueError:
            return default
    return default