Parse an environment file into a dictionary of key-value pairs. Each line should be formatted as KEY=Value. Lines that are empty or start with '#' are ignored.
(file_path: str)
| 1276 | |
| 1277 | |
| 1278 | def parse_env_file(file_path: str) -> Dict[str, str]: |
| 1279 | """Parse an environment file into a dictionary of key-value pairs. |
| 1280 | |
| 1281 | Each line should be formatted as KEY=Value. |
| 1282 | Lines that are empty or start with '#' are ignored. |
| 1283 | |
| 1284 | """ |
| 1285 | if not file_path: |
| 1286 | return {} |
| 1287 | |
| 1288 | envs = {} |
| 1289 | with open(file_path, "r") as f: |
| 1290 | for line in f: |
| 1291 | line = line.strip() |
| 1292 | if not line or line.startswith("#"): |
| 1293 | continue |
| 1294 | if "=" not in line: |
| 1295 | continue |
| 1296 | key, value = line.split("=", 1) |
| 1297 | envs[key.strip()] = value.strip() |
| 1298 | return envs |
| 1299 | |
| 1300 | |
| 1301 | def parse_size(s: str, target_unit: str) -> int: |
no outgoing calls
no test coverage detected