Skip to content

Commit 29ab4f8

Browse files
docs(src): expand Google-style docstrings for training utils env module (#131)
- expand require_env docstring with Args, Returns, Raises sections - expand set_env_defaults docstring with Args and preservation semantics - document empty-string edge case in require_env - use collections.abc.Mapping for Python 3.11+ alignment - align docstring spacing with metrics.py reference convention 📝 - Generated by Copilot
1 parent cab59e6 commit 29ab4f8

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/training/utils/env.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,40 @@
33
from __future__ import annotations
44

55
import os
6-
from typing import Mapping
6+
from collections.abc import Mapping
77

88

99
def require_env(name: str, *, error_type: type[Exception] = RuntimeError) -> str:
10-
"""Return the value of *name* or raise when missing."""
10+
"""Return the value of an environment variable or raise when missing.
1111
12+
Both unset and empty-string values are treated as missing.
13+
14+
Args:
15+
name: Environment variable name to look up.
16+
error_type: Exception class to raise on missing value.
17+
18+
Returns:
19+
Non-empty string value of the environment variable.
20+
21+
Raises:
22+
error_type: When *name* is unset or empty.
23+
"""
1224
value = os.environ.get(name)
1325
if not value:
14-
raise error_type(f"Environment variable {name} is required for Azure ML bootstrap")
26+
raise error_type(
27+
f"Environment variable {name} is required for Azure ML bootstrap"
28+
)
1529
return value
1630

1731

1832
def set_env_defaults(defaults: Mapping[str, str]) -> None:
19-
"""Set default values for environment variables that may be unset."""
33+
"""Populate environment variables with defaults for keys not already set.
34+
35+
Existing values are preserved. Only missing keys receive the
36+
provided default via ``os.environ.setdefault``.
2037
38+
Args:
39+
defaults: Mapping of variable names to default string values.
40+
"""
2141
for key, default_value in defaults.items():
2242
os.environ.setdefault(key, default_value)

0 commit comments

Comments
 (0)