codekingpro/portable-devtools
114k
1from __future__ import annotations2 3from contextlib import suppress4 5from .convert import convert6 7 8def get_env_var(key, as_type, env):9 """10 Get the environment variable option.11 12 :param key: the config key requested13 :param as_type: the type we would like to convert it to14 :param env: environment variables to use15 :return:16 """17 environ_key = f"VIRTUALENV_{key.upper()}"18 if env.get(environ_key):19 value = env[environ_key]20 21 with suppress(Exception): # note the converter already logs a warning when failures happen22 source = f"env var {environ_key}"23 as_type = convert(value, as_type, source)24 return as_type, source25 return None26 27 28__all__ = [29 "get_env_var",30]31 