Skip to content

util

Utility functions for the package.

Classes:

Name Description
GetEnvError

Exception raised when an environment variable is not found.

Timer

A context manager for measuring the execution time of a code block.

Functions:

Name Description
get_env

Get the value of an environment variable.

GetEnvError

Bases: Exception

Exception raised when an environment variable is not found.

Timer

A context manager for measuring the execution time of a code block.

get_env

get_env(variable: str) -> str

Get the value of an environment variable.

Parameters:

Name Type Description Default
variable str

The name of the environment variable to retrieve.

required

Returns:

Name Type Description
value str

The value of the environment variable, if found.

Raises:

Type Description
GetEnvError

If the environment variable is not found.

Source code in src/firebirdsql_run/util.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def get_env(variable: str) -> str:
    """Get the value of an environment variable.

    Args:
        variable: The name of the environment variable to retrieve.

    Returns:
        value: The value of the environment variable, if found.

    Raises:
        GetEnvError: If the environment variable is not found.
    """
    if value := getenv(variable):
        return value

    msg = f"Please setup {variable} in environment variables."
    raise GetEnvError(msg)