comparison env/lib/python3.7/site-packages/virtualenv/config/env_var.py @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
1 from __future__ import absolute_import, unicode_literals
2
3 import os
4
5 from virtualenv.util.six import ensure_str, ensure_text
6
7 from .convert import convert
8
9
10 def get_env_var(key, as_type):
11 """Get the environment variable option.
12
13 :param key: the config key requested
14 :param as_type: the type we would like to convert it to
15 :return:
16 """
17 environ_key = ensure_str("VIRTUALENV_{}".format(key.upper()))
18 if os.environ.get(environ_key):
19 value = os.environ[environ_key]
20 # noinspection PyBroadException
21 try:
22 source = "env var {}".format(ensure_text(environ_key))
23 as_type = convert(value, as_type, source)
24 return as_type, source
25 except Exception: # note the converter already logs a warning when failures happen
26 pass
27
28
29 __all__ = ("get_env_var",)