Use a default .env but tell the user how to create their own.
()
| 15 | |
| 16 | |
| 17 | def default_dotenv_values(): |
| 18 | """Use a default .env but tell the user how to create their own.""" |
| 19 | |
| 20 | env_dir = Path(__file__).parent |
| 21 | env_path = env_dir / ".env" |
| 22 | |
| 23 | if env_path.exists(): |
| 24 | return dotenv_values(env_path) |
| 25 | |
| 26 | with NamedTemporaryFile(mode="w+") as f: |
| 27 | global WARN_ONCE |
| 28 | |
| 29 | # TODO: these should be replaced with a folder in the project's root |
| 30 | f.write("ASTROCLIP_ROOT={ASTROCLIP_ROOT}\n") |
| 31 | f.write('WANDB_ENTITY_NAME="{WANDB_ENTITY_NAME}"\n') |
| 32 | f.flush() |
| 33 | |
| 34 | if WARN_ONCE: |
| 35 | f.seek(0) |
| 36 | warn( |
| 37 | f"No .env file found in {env_dir}. " |
| 38 | "Using default environment variables for rusty. " |
| 39 | f"To suppress this warning, create {env_dir}/.env with, e.g., the following content:\n" |
| 40 | f"{f.read()}" |
| 41 | ) |
| 42 | WARN_ONCE = False |
| 43 | |
| 44 | return dotenv_values(f.name) |
| 45 | |
| 46 | |
| 47 | T = TypeVar("T") |