-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
34 lines (25 loc) · 953 Bytes
/
utils.py
File metadata and controls
34 lines (25 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Utility functions for environment variable management.
This module provides helper functions for safely retrieving and validating
environment variables required by the application.
"""
from os import getenv
def require_env(name: str) -> str:
"""
Retrieve and validate a required environment variable.
This function attempts to get an environment variable by name.
If the variable is not set or is empty, it raises a RuntimeError.
Args:
name: The name of the environment variable to retrieve
Returns:
str: The value of the environment variable
Raises:
RuntimeError: If the environment variable is not set or is empty
Example:
>>> steam_path = require_env("steam_path")
>>> # Returns the value if set, raises RuntimeError otherwise
"""
value = getenv(name)
if not value:
raise RuntimeError(f"Environment variable {name} is not set")
return value