From 4ddc4cf1f3d70f0a8e7f70f84d5d5383a1eec3b9 Mon Sep 17 00:00:00 2001 From: yusyus Date: Thu, 6 Nov 2025 23:48:07 +0300 Subject: [PATCH] improve: Prompt for venv creation before system install fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Context:** PR #163 fixed critical venv detection bugs but used aggressive --break-system-packages flag as immediate fallback. **Improvement:** Now when no venv is found, the script: 1. Warns user about missing virtual environment 2. Offers to create one automatically (y/n prompt) 3. If yes: Creates venv, activates it, proceeds safely 4. If creation fails: Falls back to system install with warning 5. If no: Proceeds with system install but shows clear warning **Benefits:** - Encourages best practices (venv usage) - Less aggressive about bypassing system protections - Still supports system install when needed - Better user experience with clear choices **Backward Compatibility:** - All three original scenarios still work - Only adds new prompt in "no venv" scenario - Default behavior unchanged for existing venv users 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- setup_mcp.sh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/setup_mcp.sh b/setup_mcp.sh index 510ecae..9cecb84 100755 --- a/setup_mcp.sh +++ b/setup_mcp.sh @@ -46,8 +46,30 @@ elif [[ -d "venv" ]]; then source venv/bin/activate PIP_INSTALL_CMD="pip install" else - echo "No virtual environment found. Using system pip with --user --break-system-packages flags" - PIP_INSTALL_CMD="pip3 install --user --break-system-packages" + echo -e "${YELLOW}⚠${NC} No virtual environment found" + echo "It's recommended to use a virtual environment to avoid conflicts." + echo "" + read -p "Would you like to create one now? (y/n) " -n 1 -r + echo "" + + if [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Creating virtual environment..." + python3 -m venv venv || { + echo -e "${RED}❌ Failed to create virtual environment${NC}" + echo "Falling back to system install..." + PIP_INSTALL_CMD="pip3 install --user --break-system-packages" + } + + if [[ -d "venv" ]]; then + source venv/bin/activate + PIP_INSTALL_CMD="pip install" + echo -e "${GREEN}✓${NC} Virtual environment created and activated" + fi + else + echo "Proceeding with system install (using --user --break-system-packages)..." + echo -e "${YELLOW}Note:${NC} This may override system-managed packages" + PIP_INSTALL_CMD="pip3 install --user --break-system-packages" + fi fi echo "This will install: mcp, requests, beautifulsoup4"