Skip to content

utils

get_environment_variable(name)

Retrieves the value of the specified environment variable.

Parameters:

Name Type Description Default
name str

The name of the environment variable.

required

Returns:

Type Description
str

The value of the environment variable.

Raises: EnvironmentError: If the environment variable is not set.

Source code in src/ariadne/utils/utils.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def get_environment_variable(name: str) -> str:
    """Retrieves the value of the specified environment variable.

    Args:
        name: The name of the environment variable.

    Returns:
        The value of the environment variable.
    Raises:
        EnvironmentError: If the environment variable is not set.
    """

    value = os.getenv(name)
    if value is None:
        raise EnvironmentError(f"Environment variable '{name}' is not set.")
    return value

get_project_root()

Returns the path to the project root directory.

Assumes this file is at src/ariadne/utils/config.py, so the root is 3 levels up.

Source code in src/ariadne/utils/utils.py
21
22
23
24
25
26
27
28
def get_project_root() -> Path:
    """Returns the path to the project root directory.

    Assumes this file is at src/ariadne/utils/config.py,
    so the root is 3 levels up.
    """

    return Path(__file__).resolve().parent.parent.parent.parent

resolve_path(path)

If the path is relative, makes it absolute by prepending the project root.

Parameters:

Name Type Description Default
path str

The file path to resolve.

required

Returns: The absolute file path as a string.

Source code in src/ariadne/utils/utils.py
49
50
51
52
53
54
55
56
57
58
59
60
61
def resolve_path(path: str) -> str:
    """If the path is relative, makes it absolute by prepending the project root.

    Args:
        path: The file path to resolve.
    Returns:
        The absolute file path as a string.
    """

    p = Path(path)
    if not p.is_absolute():
        p = get_project_root() / p
    return str(p.resolve())