예제 #1
0
def bool(
    env_var: builtins.str,
    default: Optional[builtins.bool] = None,
) -> Optional[builtins.bool]:
    """
    Parse environment variable value into a boolean.

    Args:
        env_var (str): Name of desired environment variable.
        default (bool, optional): Optional fallback value.

    Returns:
        bool (optional): Environment variable typecast into a boolean.

    """
    if env_var.lower() in TRUES:
        return True

    if env_var.lower() in FALSES:
        return False

    raise ValueError(
        f"Invalid boolean value specified: {env_var} "
        "Parsenvy accepts 'true', '1', 'false', and '0' as boolean values."
    )
예제 #2
0
 def __call__(self, string: builtins.str) -> pathlib.Path:
     if not string.endswith(".csv") or not string.isprintable():
         msg = (f"{string} is not a valid path to a csv file.\n"
                "file needs to end with csv and only contain "
                "printable characters.")
         raise argparse.ArgumentTypeError(msg)
     path = pathlib.Path(string)
     return path
예제 #3
0
def set(
    env_var: builtins.str,
    default: Optional[Set[Any]] = None,
) -> Optional[Set[Any]]:
    if env_var is None or env_var == "":
        return default

    return builtins.set(env_var.split(","))
예제 #4
0
def tuple(
    env_var: builtins.str,
    default: Optional[Tuple[Any, ...]] = None,
) -> Optional[Tuple[Any, ...]]:
    if env_var == "":
        return default

    return builtins.tuple(env_var.split(","))
예제 #5
0
def list(
    env_var: builtins.str,
    default: Optional[List[Any]] = None,
) -> Optional[List[Any]]:
    if env_var == "":
        return default

    return env_var.split(",")
예제 #6
0
def list(
    env_var: builtins.str,
    default: Optional[List[Any]] = None,
) -> Optional[List[Any]]:
    """
    Parse environment variable value into a list.

    Args:
        env_var (str): Name of desired environment variable.
        default (List, optional): Optional fallback value.

    Returns:
        List (optional): Environment variable typecast into a list.
    """
    if env_var == "":
        return default

    return env_var.split(",")
예제 #7
0
def tuple(
    env_var: builtins.str,
    default: Optional[Tuple[Any, ...]] = None,
) -> Optional[Tuple[Any, ...]]:
    """
    Parse environment variable value into a tuple.

    Args:
        env_var (str): Name of desired environment variable.
        default (tuple, optional): Optional fallback value.

    Returns:
        tuple (optional): Environment variable typecast into a tuple.

    """
    if env_var == "":
        return default

    return builtins.tuple(env_var.split(","))