| import os | |
| def resolve_with_base_env(path: str, env_name: str) -> str: | |
| """ | |
| If `env_name` is set and `path` is NOT absolute, NOT a URL/scheme, | |
| and does not already exist locally, prepend the `env_name` directory. | |
| If the resulting path does not exist, return the base environment directory instead. | |
| Otherwise return `path` unchanged. | |
| """ | |
| base = os.getenv(env_name, "").strip() | |
| if not base: | |
| return path | |
| if os.path.isabs(path): | |
| return path | |
| if os.path.exists(path): | |
| return path | |
| candidate = os.path.join(base.rstrip("/"), path.lstrip("/")) | |
| if os.path.exists(candidate): | |
| return candidate | |
| else: | |
| raise FileNotFoundError | |