|
17 | 17 | import cruft |
18 | 18 | import typer |
19 | 19 | from cookiecutter.utils import work_in |
| 20 | +from dotenv import load_dotenv |
20 | 21 | from typer.models import OptionInfo |
21 | 22 |
|
22 | 23 |
|
23 | 24 | REPO_FOLDER: Path = Path(__file__).resolve().parent.parent |
24 | 25 |
|
25 | 26 |
|
| 27 | +def _load_env() -> None: |
| 28 | + """Load environment variables from .env and .env.local (if present). |
| 29 | +
|
| 30 | + .env.local takes precedence over .env for any overlapping variables. |
| 31 | + """ |
| 32 | + env_file: Path = REPO_FOLDER / ".env" |
| 33 | + env_local_file: Path = REPO_FOLDER / ".env.local" |
| 34 | + |
| 35 | + if env_file.exists(): |
| 36 | + load_dotenv(env_file) |
| 37 | + |
| 38 | + if env_local_file.exists(): |
| 39 | + load_dotenv(env_local_file, override=True) |
| 40 | + |
| 41 | + |
| 42 | +# Load environment variables at module import time |
| 43 | +_load_env() |
| 44 | + |
| 45 | + |
26 | 46 | FolderOption: partial[OptionInfo] = partial( |
27 | 47 | typer.Option, dir_okay=True, file_okay=False, resolve_path=True, path_type=Path |
28 | 48 | ) |
@@ -66,14 +86,17 @@ def run_command(command: str, *args: str, ignore_error: bool = False) -> Optiona |
66 | 86 |
|
67 | 87 | def require_clean_and_up_to_date_repo() -> None: |
68 | 88 | """Checks if the repo is clean and up to date with any important branches.""" |
| 89 | + main_branch: str = os.getenv("COOKIECUTTER_ROBUST_PYTHON_MAIN_BRANCH", "main") |
| 90 | + develop_branch: str = os.getenv("COOKIECUTTER_ROBUST_PYTHON_DEVELOP_BRANCH", "develop") |
| 91 | + |
69 | 92 | git("fetch") |
70 | 93 | git("status", "--porcelain") |
71 | | - if not is_branch_synced_with_remote("develop"): |
72 | | - raise ValueError("develop is not synced with origin/develop") |
73 | | - if not is_branch_synced_with_remote("main"): |
74 | | - raise ValueError("main is not synced with origin/main") |
75 | | - if not is_ancestor("main", "develop"): |
76 | | - raise ValueError("main is not an ancestor of develop") |
| 94 | + if not is_branch_synced_with_remote(develop_branch): |
| 95 | + raise ValueError(f"{develop_branch} is not synced with origin/{develop_branch}") |
| 96 | + if not is_branch_synced_with_remote(main_branch): |
| 97 | + raise ValueError(f"{main_branch} is not synced with origin/{main_branch}") |
| 98 | + if not is_ancestor(main_branch, develop_branch): |
| 99 | + raise ValueError(f"{main_branch} is not an ancestor of {develop_branch}") |
77 | 100 |
|
78 | 101 |
|
79 | 102 | def is_branch_synced_with_remote(branch: str) -> bool: |
|
0 commit comments