mirror of
https://github.com/vale981/ray
synced 2025-03-05 18:11:42 -05:00

This adds "environments" to the release package that can be used to configure some environment variables. These variables will be loaded either by an `--env` argument or a `env` definition in the test definition and can be used to e.g. run release tests on staging.
31 lines
814 B
Python
31 lines
814 B
Python
import os
|
|
from typing import Dict
|
|
|
|
from ray_release.exception import ReleaseTestConfigError
|
|
|
|
DEFAULT_ENVIRONMENT = "prod"
|
|
|
|
|
|
def load_environment(environment_name: str) -> Dict[str, str]:
|
|
this_dir = os.path.dirname(__file__)
|
|
env_file = os.path.join(this_dir, "environments", f"{environment_name}.env")
|
|
|
|
if not os.path.exists(env_file):
|
|
raise ReleaseTestConfigError(
|
|
f"Unknown environment with name: {environment_name}"
|
|
)
|
|
|
|
env = {}
|
|
with open(env_file, "r") as f:
|
|
for line in f.readlines():
|
|
if not line:
|
|
continue
|
|
key, val = line.strip().split("=", maxsplit=1)
|
|
env[key] = val.strip('"')
|
|
|
|
return env
|
|
|
|
|
|
def populate_os_env(env: Dict[str, str]) -> None:
|
|
for k, v in env.items():
|
|
os.environ[k] = v
|