Skip to content

env

dev_tool.tools.env

log = logging.getLogger(__name__) module-attribute

get_env_variables

A function that checks which environment variables are not set.

Parameters:

  • variables (list[str] | tuple[str, ...]) –

    The list of environment variables to check.

Returns:

  • list[str]

    A list of variables that are not set.

Source code in dev_tool/tools/env.py
def get_env_variables(variables: list[str] | tuple[str, ...]) -> list[str]:
    """
    A function that checks which environment variables are not set.

    :param variables: The list of environment variables to check.
    :return: A list of variables that are not set.
    """

    return [
        variable
        for variable in variables
        if variable not in os.environ
    ]

is_in_env_variables

A function that checks if all specified environment variables are set.

Parameters:

  • variables (list[str] | tuple[str, ...]) –

    The list of environment variables to check.

  • suppress (bool, default: False ) –

    A flag indicating whether to suppress warning messages.

Returns:

  • bool

    True if all variables are set, False otherwise.

Source code in dev_tool/tools/env.py
def is_in_env_variables(variables: list[str] | tuple[str, ...], suppress: bool = False) -> bool:
    """
    A function that checks if all specified environment variables are set.

    :param variables: The list of environment variables to check.
    :param suppress: A flag indicating whether to suppress warning messages.
    :return: True if all variables are set, False otherwise.
    """

    unset = get_env_variables(variables)

    if len(unset) > 0:
        message = f'The following environment variables are not set: {unset}'

        if not suppress:
            CONTEXT.notification.warning_text(message)
            log.exception(message)

        return False

    return True