From e8d698814a44c5747a69ba9b2a6cc609094e694c Mon Sep 17 00:00:00 2001 From: test-user Date: Mon, 25 May 2026 09:15:55 -0700 Subject: [PATCH] fix(cli): re-exec via -m instead of a repr(sys.argv) -c string Based on #9 by @eskibars. Replaces the os.execl(..., "-c", repr-string) restart (used after the CUDA-torch auto-install) with os.execv -m, so we no longer build an exec string from repr(sys.argv). Forwards sys.argv[1:] only: under -m Python sets argv[0] to the module path, so passing the full argv would re-inject the program name as a spurious Click argument. Verified: python -m remove_ai_watermarks.cli --version works; test_cli green. Closes #9 Co-Authored-By: Claude Opus 4.7 (1M context) --- src/remove_ai_watermarks/noai/watermark_remover.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/remove_ai_watermarks/noai/watermark_remover.py b/src/remove_ai_watermarks/noai/watermark_remover.py index 1b40a74..503ce56 100644 --- a/src/remove_ai_watermarks/noai/watermark_remover.py +++ b/src/remove_ai_watermarks/noai/watermark_remover.py @@ -176,8 +176,11 @@ def _reinstall_torch_cuda_and_restart() -> None: return os.environ[_CUDA_FIX_ENV_KEY] = "1" - restart_code = f"import sys; sys.argv = {sys.argv!r}; from remove_ai_watermarks.cli import main; sys.exit(main())" - os.execl(sys.executable, sys.executable, "-c", restart_code) + # Re-exec via ``-m`` rather than building a ``-c`` string from repr(sys.argv). + # ``-m`` makes Python set argv[0] to the module path, so forward only the + # actual args (sys.argv[1:]); passing the full argv would re-inject the + # program name as a spurious first argument to Click. + os.execv(sys.executable, [sys.executable, "-m", "remove_ai_watermarks.cli", *sys.argv[1:]]) def _ensure_watermark_deps() -> None: