MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / bool_env

Function bool_env

imperative/python/megengine/xla/lib/config.py:24–42  ·  view source on GitHub ↗

Read an environment variable and interpret it as a boolean. True values are (case insensitive): 'y', 'yes', 't', 'true', 'on', and '1'; false values are 'n', 'no', 'f', 'false', 'off', and '0'. Args: varname: the name of the variable default: the default boolean value

(varname: str, default: bool)

Source from the content-addressed store, hash-verified

22
23
24def bool_env(varname: str, default: bool) -> bool:
25 """Read an environment variable and interpret it as a boolean.
26
27 True values are (case insensitive): 'y', 'yes', 't', 'true', 'on', and '1';
28 false values are 'n', 'no', 'f', 'false', 'off', and '0'.
29
30 Args:
31 varname: the name of the variable
32 default: the default boolean value
33 Raises: ValueError if the environment variable is anything else.
34 """
35 val = os.getenv(varname, str(default))
36 val = val.lower()
37 if val in ("y", "yes", "t", "true", "on", "1"):
38 return True
39 elif val in ("n", "no", "f", "false", "off", "0"):
40 return False
41 else:
42 raise ValueError(f"invalid truth value {val!r} for environment {varname!r}")
43
44
45def int_env(varname: str, default: int) -> int:

Callers 3

define_bool_stateMethod · 0.85
config.pyFile · 0.85
xla_bridge.pyFile · 0.85

Calls 1

strFunction · 0.85

Tested by

no test coverage detected