From be5408c265802a364b485a266abf065113d05bb8 Mon Sep 17 00:00:00 2001 From: tkgstrator Date: Mon, 13 Jul 2026 04:01:39 +0000 Subject: [PATCH] fix(train): load_dotenv override=True so empty devcontainer forwards lose to .env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit devcontainer.json forwards ${localEnv:HF_TOKEN} and ${localEnv:WANDB_API_KEY} from the host, which expand to an empty string when those vars are unset on the host. load_dotenv() with the default override=False then treats the empty string as "already set" and refuses to import the value from .env, leaving HF (unauthenticated) and wandb (skipped) silently broken. Switch the three training entrypoints (train_board_ocr, train_piece, train_detector) to load_dotenv(override=True) so .env wins over empty forwards. Real host values still flow through — override just replaces empties too. Bump version to 0.3.2. Co-Authored-By: Claude Opus 4.8 (1M context) --- mito_train/training/train_board_ocr.py | 4 +++- mito_train/training/train_detector.py | 4 +++- mito_train/training/train_piece.py | 4 +++- pyproject.toml | 2 +- uv.lock | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mito_train/training/train_board_ocr.py b/mito_train/training/train_board_ocr.py index 07b8385..5f9539f 100644 --- a/mito_train/training/train_board_ocr.py +++ b/mito_train/training/train_board_ocr.py @@ -510,7 +510,9 @@ def log_main(msg: str) -> None: def main() -> None: # Pull HF_TOKEN / WANDB_API_KEY / CF_* out of .env into os.environ before # any HF or wandb call resolves credentials. No-op if .env is missing. - load_dotenv() + # override=True so devcontainer.json's ${localEnv:...} forwards that expand + # to an empty string on hosts without those vars don't win over .env. + load_dotenv(override=True) p = argparse.ArgumentParser() p.add_argument("--mode", choices=["smoke", "full"], default="smoke") p.add_argument("--backbone", default="mobilenet_v3_small", diff --git a/mito_train/training/train_detector.py b/mito_train/training/train_detector.py index cd0d953..c539c14 100644 --- a/mito_train/training/train_detector.py +++ b/mito_train/training/train_detector.py @@ -78,7 +78,9 @@ def evaluate(model: nn.Module, loader: DataLoader, device: str) -> dict[str, flo def main() -> None: # Pull HF_TOKEN / WANDB_API_KEY / CF_* out of .env into os.environ before # any wandb or HF call resolves credentials. No-op if .env is missing. - load_dotenv() + # override=True so devcontainer.json's ${localEnv:...} forwards that expand + # to an empty string on hosts without those vars don't win over .env. + load_dotenv(override=True) p = argparse.ArgumentParser() p.add_argument("--train-manifest", type=Path, default=Path("data/detector/train.jsonl")) p.add_argument("--val-manifest", type=Path, default=Path("data/detector/val.jsonl")) diff --git a/mito_train/training/train_piece.py b/mito_train/training/train_piece.py index dd6a5b7..a94013e 100644 --- a/mito_train/training/train_piece.py +++ b/mito_train/training/train_piece.py @@ -223,7 +223,9 @@ def run_manifest(args: argparse.Namespace) -> None: def main() -> None: # Pull WANDB_API_KEY / CF_* / HF_TOKEN out of .env into os.environ before # any wandb or HF call resolves credentials. No-op if .env is missing. - load_dotenv() + # override=True so devcontainer.json's ${localEnv:...} forwards that expand + # to an empty string on hosts without those vars don't win over .env. + load_dotenv(override=True) p = argparse.ArgumentParser() p.add_argument("--mode", choices=["smoke", "manifest"], default="smoke") # smoke-mode args diff --git a/pyproject.toml b/pyproject.toml index 054dfcf..682df05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "mito-train" -version = "0.3.1" +version = "0.3.2" description = "ぴよ将棋OCR 3モデル (board-detector / piece-classifier / hand-classifier) の学習・ONNX出力" requires-python = ">=3.11" dependencies = [ diff --git a/uv.lock b/uv.lock index ac793db..1b87464 100644 --- a/uv.lock +++ b/uv.lock @@ -1119,7 +1119,7 @@ wheels = [ [[package]] name = "mito-train" -version = "0.3.1" +version = "0.3.2" source = { editable = "." } dependencies = [ { name = "albumentations" },