Collect config from environment variables This grabs environment variables of the form "DASK_FOO__BAR_BAZ=123" and turns these into config variables of the form ``{"foo": {"bar-baz": 123}}`` It transforms the key and value in the following way: - Lower-cases the key text - Tr
(env: Mapping[str, str] | None = None)
| 245 | |
| 246 | |
| 247 | def collect_env(env: Mapping[str, str] | None = None) -> dict: |
| 248 | """Collect config from environment variables |
| 249 | |
| 250 | This grabs environment variables of the form "DASK_FOO__BAR_BAZ=123" and |
| 251 | turns these into config variables of the form ``{"foo": {"bar-baz": 123}}`` |
| 252 | It transforms the key and value in the following way: |
| 253 | |
| 254 | - Lower-cases the key text |
| 255 | - Treats ``__`` (double-underscore) as nested access |
| 256 | - Calls ``ast.literal_eval`` on the value |
| 257 | |
| 258 | Any serialized config passed via ``DASK_INTERNAL_INHERIT_CONFIG`` is also set here. |
| 259 | |
| 260 | """ |
| 261 | |
| 262 | if env is None: |
| 263 | env = os.environ |
| 264 | |
| 265 | if "DASK_INTERNAL_INHERIT_CONFIG" in env: |
| 266 | d = deserialize(env["DASK_INTERNAL_INHERIT_CONFIG"]) |
| 267 | else: |
| 268 | d = {} |
| 269 | |
| 270 | for name, value in env.items(): |
| 271 | if name.startswith("DASK_"): |
| 272 | varname = name[5:].lower().replace("__", ".") |
| 273 | d[varname] = interpret_value(value) |
| 274 | |
| 275 | result: dict = {} |
| 276 | set(d, config=result) |
| 277 | return result |
| 278 | |
| 279 | |
| 280 | def interpret_value(value: str) -> Any: |