refactor: remove env.py module and update plan

- Delete env.py module (functionality moved or no longer needed)
- Update docs/plan.md to reflect Milestone 2 completion
- Clean up constants.py by removing unused environment-related constants
This commit is contained in:
2026-10-04 14:07:29 +08:00
parent d2cf059337
commit 4bc7012e77
3 changed files with 73 additions and 118 deletions
+2 -3
View File
@@ -20,11 +20,10 @@ Work on ONE milestone at a time. Each milestone is one branch (`milestone/NN-nam
- [x] Verify: create `.venv`, upgrade pip, `pip install -e ".[dev]"`
- [x] Save plan and milestones in `docs/plan.md`
## Milestone 2 - Core auction logic and env loader (`milestone/02-core-logic`)
## Milestone 2 - Core auction logic (`milestone/02-core-logic`)
- [x] `auction.py` (Doxygen comments): `add_bid`, `find_winner` (uses `max(bids, key=bids.get)`, `ValueError` on empty)
- [x] `env.py`: stdlib `.env` loader (no python-dotenv); does not override existing environment variables
- [x] `tests/test_auction.py` (`.env` loader is for private use and intentionally not tested)
- [x] `tests/test_auction.py`
- Verify: `pytest` passes
## Milestone 3 - CLI program (`milestone/03-cli`)
-6
View File
@@ -11,12 +11,6 @@ YES_ANSWERS = ("yes", "y")
## Answers accepted as "no" when asking for more bidders.
NO_ANSWERS = ("no", "n")
## Path of the file holding environment variables (tokens).
ENV_FILE = ".env"
## Name of the environment variable holding the Gitea token.
GITEA_TOKEN_ENV_VAR = "GITEA_TOKEN"
## Prompt asking for the bidder's name.
PROMPT_NAME = "What is your name? "
-38
View File
@@ -1,38 +0,0 @@
"""! @file env.py
@brief Minimal `.env` file loader using only the standard library.
"""
import os
from pathlib import Path
def parse_env(text: str) -> dict[str, str]:
"""! @brief Parse `KEY=VALUE` lines.
@param text Contents of a `.env` file. Blank lines and `#` comments are ignored.
@return Dictionary of parsed variables; surrounding quotes are stripped.
"""
values: dict[str, str] = {}
for line in text.splitlines():
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
key, value = line.split("=", 1)
value = value.strip()
if len(value) >= 2 and value[0] == value[-1] and value[0] in "\"'":
value = value[1:-1]
values[key.strip()] = value
return values
def load_env(path: str | Path) -> dict[str, str]:
"""! @brief Load a `.env` file into `os.environ` without overriding existing variables.
@param path Path to the `.env` file; a missing file is not an error.
@return Dictionary of the variables read from the file.
"""
file = Path(path)
if not file.is_file():
return {}
values = parse_env(file.read_text(encoding="utf-8"))
for key, value in values.items():
os.environ.setdefault(key, value)
return values