mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-10-26 13:16:24 +00:00
configure.py did not parse its arguments, so `--help` printed no usage and ran the bootstrap as a side effect (creating config.yaml, .env and frontend/.env in a fresh checkout), and any unrecognized flag was silently ignored the same way. Parse arguments with argparse before touching the filesystem: --help now prints usage and exits 0, unknown flags exit 2, and the no-argument invocation used by `make configure` is unchanged. Extend the regression tests from #7102 with two offline subprocess cases covering both new behaviors. Fixes #7382
66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Cross-platform config bootstrap script for DeerFlow."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import shutil
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def copy_if_missing(src: Path, dst: Path) -> None:
|
|
if dst.exists():
|
|
return
|
|
if not src.exists():
|
|
raise FileNotFoundError(f"Missing template file: {src}")
|
|
dst.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copyfile(src, dst)
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
parser = argparse.ArgumentParser(
|
|
prog="configure.py",
|
|
description="Cross-platform config bootstrap script for DeerFlow.",
|
|
)
|
|
parser.parse_args(argv)
|
|
|
|
project_root = Path(__file__).resolve().parent.parent
|
|
|
|
existing_config = [
|
|
project_root / "config.yaml",
|
|
project_root / "config.yml",
|
|
project_root / "configure.yml",
|
|
]
|
|
|
|
if any(path.exists() for path in existing_config):
|
|
print(
|
|
"Error: configuration file already exists "
|
|
"(config.yaml/config.yml/configure.yml). Aborting."
|
|
)
|
|
return 1
|
|
|
|
try:
|
|
copy_if_missing(project_root / "config.example.yaml", project_root / "config.yaml")
|
|
copy_if_missing(project_root / ".env.example", project_root / ".env")
|
|
copy_if_missing(
|
|
project_root / "frontend" / ".env.example",
|
|
project_root / "frontend" / ".env",
|
|
)
|
|
except (FileNotFoundError, OSError) as exc:
|
|
print("Error while generating configuration files:")
|
|
print(f" {exc}")
|
|
if isinstance(exc, PermissionError):
|
|
print(
|
|
"Hint: Check file permissions and ensure the files are not "
|
|
"read-only or locked by another process."
|
|
)
|
|
return 1
|
|
|
|
print("Configuration files generated")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|