Skip to content

Commit dc9f37c

Browse files
committed
Add requirement checks and installation in launchers
1 parent 667c7da commit dc9f37c

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

OpCore-Simplify.bat

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,56 @@ if /i "!just_installing!" == "TRUE" (
299299
)
300300
exit /b
301301

302+
:checkrequirements
303+
REM Check and install Python requirements
304+
set "requirements_file=!thisDir!requirements.txt"
305+
if not exist "!requirements_file!" (
306+
echo Warning: requirements.txt not found. Skipping dependency check.
307+
exit /b 0
308+
)
309+
echo Checking Python dependencies...
310+
"!pypath!" -m pip --version > nul 2>&1
311+
set "pip_check_error=!ERRORLEVEL!"
312+
if not "!pip_check_error!" == "0" (
313+
echo Warning: pip is not available. Attempting to install pip...
314+
"!pypath!" -m ensurepip --upgrade > nul 2>&1
315+
set "ensurepip_error=!ERRORLEVEL!"
316+
if not "!ensurepip_error!" == "0" (
317+
echo Error: Could not install pip. Please install pip manually.
318+
exit /b 1
319+
)
320+
)
321+
REM Try to import key packages to check if they're installed
322+
"!pypath!" -c "import PyQt6; import qfluentwidgets" > nul 2>&1
323+
set "import_check_error=!ERRORLEVEL!"
324+
if not "!import_check_error!" == "0" (
325+
echo Installing required packages from requirements.txt...
326+
"!pypath!" -m pip install --upgrade -r "!requirements_file!"
327+
set "pip_install_error=!ERRORLEVEL!"
328+
if not "!pip_install_error!" == "0" (
329+
echo.
330+
echo Error: Failed to install requirements. Please install them manually:
331+
echo !pypath! -m pip install -r !requirements_file!
332+
echo.
333+
echo Press [enter] to exit...
334+
pause > nul
335+
exit /b 1
336+
)
337+
echo Requirements installed successfully.
338+
) else (
339+
echo All requirements are already installed.
340+
)
341+
exit /b 0
342+
302343
:runscript
303344
REM Python found
304345
cls
346+
REM Check and install requirements before running the script
347+
call :checkrequirements
348+
set "req_check_error=!ERRORLEVEL!"
349+
if not "!req_check_error!" == "0" (
350+
exit /b 1
351+
)
305352
set "args=%*"
306353
set "args=!args:"=!"
307354
if "!args!"=="" (

OpCore-Simplify.command

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,42 @@ prompt_and_download() {
283283
done
284284
}
285285

286+
check_and_install_requirements() {
287+
local python="$1"
288+
local requirements_file="$dir/requirements.txt"
289+
290+
# Check if requirements.txt exists
291+
if [ ! -f "$requirements_file" ]; then
292+
echo "Warning: requirements.txt not found. Skipping dependency check."
293+
return 0
294+
fi
295+
296+
# Check if pip is available
297+
if ! "$python" -m pip --version > /dev/null 2>&1; then
298+
echo "Warning: pip is not available. Attempting to install pip..."
299+
if ! "$python" -m ensurepip --upgrade > /dev/null 2>&1; then
300+
echo "Error: Could not install pip. Please install pip manually."
301+
return 1
302+
fi
303+
fi
304+
305+
# Check if requirements are installed by trying to import key packages
306+
echo "Checking Python dependencies..."
307+
if ! "$python" -c "import PyQt6; import qfluentwidgets" > /dev/null 2>&1; then
308+
echo "Installing required packages from requirements.txt..."
309+
if ! "$python" -m pip install --upgrade -r "$requirements_file"; then
310+
echo "Error: Failed to install requirements. Please install them manually:"
311+
echo " $python -m pip install -r $requirements_file"
312+
return 1
313+
fi
314+
echo "Requirements installed successfully."
315+
else
316+
echo "All requirements are already installed."
317+
fi
318+
319+
return 0
320+
}
321+
286322
main() {
287323
local python= version=
288324
# Verify our target exists
@@ -310,6 +346,11 @@ main() {
310346
prompt_and_download
311347
return 1
312348
fi
349+
# Check and install requirements before running the script
350+
if ! check_and_install_requirements "$python"; then
351+
echo "Failed to install requirements. Exiting."
352+
exit 1
353+
fi
313354
# Found it - start our script and pass all args
314355
"$python" "$dir/$target" "${args[@]}"
315356
}

0 commit comments

Comments
 (0)