From 21d51d7f46542446e5fc02ff41c048ac42c4eeaf Mon Sep 17 00:00:00 2001 From: nose Date: Wed, 24 Dec 2025 22:50:50 -0800 Subject: [PATCH] kjf --- readme.md | 2 +- scripts/setup.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index d6df954..550788a 100644 --- a/readme.md +++ b/readme.md @@ -11,7 +11,7 @@ Medios-Macina is a CLI media manager and toolkit focused on downloading, tagging ## Quick start ⚡ -Prefer an automated setup? See `docs/BOOTSTRAP.md` and use `scripts/bootstrap.ps1` (Windows) or `scripts/bootstrap.sh` (Linux/macOS) to create a venv and install the project. Alternatively, run the opinionated helper: `python ./scripts/setup.py` which creates a `.venv` at the repo root, installs dependencies into it, writes convenient `mm` launchers in the project root, and installs a global `mm` shim into your user PATH so you can run `mm` from anywhere. + `docs/BOOTSTRAP.md` and use `scripts/bootstrap.ps1` (Windows) or `scripts/bootstrap.sh` (Linux/macOS) to create a venv and install the project. Alternatively, simply run the opinionated helper: `python ./scripts/setup.py`. By default (no flags), `setup.py` will auto-detect your platform and run the matching bootstrap script in **non-interactive (quiet)** mode so you don't need to run the platform-specific script yourself. Note: the Deno installer can require interactive input on some systems; if the automated Deno install fails, the script will warn and you can install Deno manually by following `docs/BOOTSTRAP.md`. 1. Install Python requirements: diff --git a/scripts/setup.py b/scripts/setup.py index 69fd7b4..1314991 100644 --- a/scripts/setup.py +++ b/scripts/setup.py @@ -8,8 +8,13 @@ downloads Playwright browser binaries by running `python -m playwright install`. By default this script installs **Chromium** only to conserve space; pass `--browsers all` to install all supported engines (chromium, firefox, webkit). +When invoked without any arguments, `setup.py` will automatically select and +run the platform-specific bootstrap helper (`scripts/bootstrap.ps1` on Windows +or `scripts/bootstrap.sh` on POSIX) in **non-interactive (quiet)** mode so a +single `python ./scripts/setup.py` call does the usual bootstrap on your OS. + Usage: - python ./scripts/setup.py # install deps and playwright browsers + python ./scripts/setup.py # install deps and playwright browsers (or run platform bootstrap if no args) python ./scripts/setup.py --skip-deps python ./scripts/setup.py --playwright-only @@ -41,6 +46,59 @@ def run(cmd: list[str]) -> None: subprocess.check_call(cmd) +# Helpers to find shell executables and to run the platform-specific +# bootstrap script (scripts/bootstrap.sh or scripts/bootstrap.ps1). +def _find_powershell() -> str | None: + for name in ("pwsh", "powershell"): + p = shutil.which(name) + if p: + return p + return None + + +def _find_shell() -> str | None: + for name in ("bash", "sh"): + p = shutil.which(name) + if p: + return p + return None + + +def run_platform_bootstrap(repo_root: Path) -> int: + """Run the platform bootstrap script in quiet/non-interactive mode if present. + + Returns the script exit code (0 on success). If no script is present this is a + no-op and returns 0. + """ + ps1 = repo_root / "scripts" / "bootstrap.ps1" + sh_script = repo_root / "scripts" / "bootstrap.sh" + + system = platform.system().lower() + + if system == "windows" and ps1.exists(): + exe = _find_powershell() + if not exe: + print("PowerShell not found; cannot run bootstrap.ps1", file=sys.stderr) + return 1 + cmd = [exe, "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", str(ps1), "-Quiet"] + elif sh_script.exists(): + shell = _find_shell() + if not shell: + print("Shell not found; cannot run bootstrap.sh", file=sys.stderr) + return 1 + # Use -q (quiet) to skip interactive prompts when supported. + cmd = [shell, str(sh_script), "-q"] + else: + # Nothing to run + return 0 + + print("Running platform bootstrap script:", " ".join(cmd)) + rc = subprocess.run(cmd, cwd=str(repo_root)) + if rc.returncode != 0: + print(f"Bootstrap script failed with exit code {rc.returncode}", file=sys.stderr) + return int(rc.returncode or 0) + + def playwright_package_installed() -> bool: try: import playwright # type: ignore @@ -131,6 +189,17 @@ def main() -> int: repo_root = Path(__file__).resolve().parent.parent + # If invoked without any arguments, prefer to delegate to the platform + # bootstrap script (if present). The bootstrap scripts support a quiet/ + # non-interactive mode, which we use so "python ./scripts/setup.py" just + # does the right thing on Windows and *nix without extra flags. + if len(sys.argv) == 1: + rc = run_platform_bootstrap(repo_root) + if rc != 0: + return rc + print("Platform bootstrap completed successfully.") + return 0 + if sys.version_info < (3, 8): print("Warning: Python 3.8+ is recommended.", file=sys.stderr)