From 889ff59c2477d6341b0e68fada0e9073c14411cf Mon Sep 17 00:00:00 2001 From: Sagar Gupta Date: Mon, 10 Aug 2026 07:54:37 +0530 Subject: [PATCH] fix: clear the last 4 SonarCloud findings on main setup.sh had never been scanned before, so newer rules surfaced on it: - pip installs use --only-binary :all: so no setup scripts run from source distributions (shell:S8541). - npm install uses --ignore-scripts (shell:S6505). Mirror the same flags in setup.bat for consistency; Sonar does not analyse .bat files, but the two scripts should not drift. Also finish python:S5778 in test_make_prediction_scaler_error: hoisting the array was not enough because the DummyModel() and BadScaler() constructors inside the pytest.raises block also count as throwing invocations. Both are now built beforehand so only make_prediction can raise. --- setup.bat | 9 +++++---- setup.sh | 9 +++++---- tests/test_predict.py | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/setup.bat b/setup.bat index 83bd68e..a002254 100644 --- a/setup.bat +++ b/setup.bat @@ -17,17 +17,18 @@ REM Activate virtual environment echo 🔧 Activating virtual environment... call venv\Scripts\activate.bat -REM Install Python dependencies +REM Install Python dependencies. --only-binary keeps pip from running setup +REM scripts out of source distributions. echo 📚 Installing Python dependencies... -python -m pip install --upgrade pip -pip install -r requirements.txt +python -m pip install --upgrade --only-binary :all: pip +pip install --only-binary :all: -r requirements.txt REM Check if Node.js is installed node --version >nul 2>&1 if %errorlevel% equ 0 ( echo 🌐 Setting up React frontend... cd client - npm install + npm install --ignore-scripts cd .. ) else ( echo ⚠️ Node.js not found. Frontend setup skipped. diff --git a/setup.sh b/setup.sh index cd5565b..6c53b52 100644 --- a/setup.sh +++ b/setup.sh @@ -20,16 +20,17 @@ else source venv/bin/activate fi -# Install Python dependencies +# Install Python dependencies. --only-binary keeps pip from running setup +# scripts out of source distributions. echo "📚 Installing Python dependencies..." -pip install --upgrade pip -pip install -r requirements.txt +pip install --upgrade --only-binary :all: pip +pip install --only-binary :all: -r requirements.txt # Check if Node.js is installed for frontend if command -v node &> /dev/null; then echo "🌐 Setting up React frontend..." cd client - npm install + npm install --ignore-scripts cd .. else echo "⚠️ Node.js not found. Frontend setup skipped." diff --git a/tests/test_predict.py b/tests/test_predict.py index ef00386..de369ab 100644 --- a/tests/test_predict.py +++ b/tests/test_predict.py @@ -59,8 +59,9 @@ def predict(self, x, verbose=0): return np.array([[0.0]]) arr = np.array([[1800, 500, 8000, 6.25, 45, 6.2, 160.0]]) + model, scaler = DummyModel(), BadScaler() with pytest.raises(HTTPException) as exc_info: - make_prediction(DummyModel(), BadScaler(), arr) + make_prediction(model, scaler, arr) assert exc_info.value.status_code == 500