Skip to content

Commit b4825a0

Browse files
authored
Merge pull request #307 from zaz/fix-close-terminal
Fix issue where setup script can close the user's terminal
2 parents 8d37acd + 02bcc2c commit b4825a0

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

test/test_uv_env_setup.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Tests for uv_env_setup.sh error handling."""
2+
3+
import subprocess
4+
from pathlib import Path
5+
6+
7+
def test_source_invalid_platform_does_not_kill_shell():
8+
"""Verify sourcing with invalid platform does not kill the shell.
9+
10+
If the script uses bare `exit 1`, sourcing it kills the shell
11+
(subshell exits). If it uses `return 1`, the subshell survives
12+
and the sentinel `STILL_ALIVE` is printed.
13+
"""
14+
script = Path(__file__).parents[1] / "uv_env_setup.sh"
15+
result = subprocess.run(
16+
[
17+
"bash",
18+
"-c",
19+
f"source {script} INVALID 2>/dev/null; echo STILL_ALIVE",
20+
],
21+
capture_output=True,
22+
text=True,
23+
)
24+
assert "STILL_ALIVE" in result.stdout, (
25+
"Shell was killed by `exit 1` instead of `return 1`"
26+
)

uv_env_setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ elif [ "$PLATFORM" == "cu121" ]; then
3030
PYG_URL="https://data.pyg.org/whl/torch-${TORCH_VER}+cu121.html"
3131
else
3232
echo "❌ Error: Invalid platform '$PLATFORM'. Use: cpu, cu118, or cu121."
33-
exit 1
33+
return 1 2>/dev/null || exit 1
3434
fi
3535

3636
echo "⚙️ Updating pyproject.toml..."

0 commit comments

Comments
 (0)