Update a KEY=value line in the env file.
(filepath: str, key: str, value: str)
| 21 | |
| 22 | |
| 23 | def _update_env_key(filepath: str, key: str, value: str) -> None: |
| 24 | """Update a KEY=value line in the env file.""" |
| 25 | with open(filepath, "r") as f: |
| 26 | content = f.read() |
| 27 | pattern = rf"^{re.escape(key)}=.*$" |
| 28 | replacement = f"{key}={value}" |
| 29 | content = re.sub(pattern, replacement, content, flags=re.MULTILINE) |
| 30 | with open(filepath, "w") as f: |
| 31 | f.write(content) |
| 32 | |
| 33 | |
| 34 | @app.route("/") |