MCPcopy Create free account
hub / github.com/dask/dask / collect_env

Function collect_env

dask/config.py:247–277  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

245
246
247def 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
280def interpret_value(value: str) -> Any:

Callers 4

test_envFunction · 0.90
test_env_special_valuesFunction · 0.90
test_config_inheritanceFunction · 0.90
collectFunction · 0.85

Calls 5

deserializeFunction · 0.85
interpret_valueFunction · 0.85
setClass · 0.85
itemsMethod · 0.45
replaceMethod · 0.45

Tested by 3

test_envFunction · 0.72
test_env_special_valuesFunction · 0.72
test_config_inheritanceFunction · 0.72