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) <noreply@anthropic.com>
This commit is contained in:
test-user
2026-05-25 09:15:55 -07:00
parent 663c8c64ca
commit e8d698814a
@@ -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: