From 495e24b89276f08f5b7fc752d88ec9468d355c7c Mon Sep 17 00:00:00 2001 From: Nourepide Date: Tue, 28 Nov 2023 20:00:53 +0300 Subject: [PATCH] Update a Windows install script for portable. --- install.bat | 110 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 76 insertions(+), 34 deletions(-) diff --git a/install.bat b/install.bat index 9fa39ef..5b56c9f 100644 --- a/install.bat +++ b/install.bat @@ -1,7 +1,16 @@ +0<0# : ^ +''' @echo off +setlocal enabledelayedexpansion REM Save the current directory -set CURRENT_DIR=%cd% +set CURRENT_DIR=!cd! + +REM Initialize a flag for venv activation +set VENV_ACTIVATED=0 + +REM Initialize a variable for the Python executable +set PYTHON_EXECUTABLE=python REM Check if the venv directory exists two levels up if exist "..\..\venv\" ( @@ -13,33 +22,79 @@ if exist "..\..\venv\" ( REM Activate the virtual environment call venv\Scripts\activate + REM Set the flag for venv activation + set VENV_ACTIVATED=1 + REM Go back to the original directory - cd %CURRENT_DIR% + cd !CURRENT_DIR! REM Check if the requirements.txt file exists in the current directory if exist "requirements.txt" ( REM Install dependencies from the requirements.txt file pip install -r requirements.txt + ) else ( + echo Error: requirements.txt not found in the current directory. + ) + ) +) - REM Check if git is installed - where /q git - if %ERRORLEVEL% equ 0 ( - echo Git is installed. +if exist "..\..\..\python_embeded\" ( + REM Go three levels up from the current directory + cd ..\..\.. - REM Check if the current directory is a git repository - if not exist ".git" ( - echo This directory is not a git repository. Initializing a new repository. - git init - git remote add origin https://github.com/Nourepide/ComfyUI-Allor - git pull origin master - ) else ( - echo This directory is already a git repository. - ) - ) else ( - echo Git is not installed. Using GitPython instead. + REM Check if python.exe exists in the python_embedded directory + if exist "python_embeded\python.exe" ( + REM Set the flag for venv activation + set VENV_ACTIVATED=2 - REM Run a Python script that uses GitPython to do the same thing - python -c " + REM Set the Python executable to the python.exe in the python_embedded directory + set PYTHON_EXECUTABLE=!cd!\python_embeded\python.exe + + echo !PYTHON_EXECUTABLE! + + REM Execute python.exe with the specified arguments + call !PYTHON_EXECUTABLE! -s -m pip install -r !CURRENT_DIR!\requirements.txt --no-warn-script-location + + REM Go back to the original directory + cd !CURRENT_DIR! + ) +) + +REM If neither venv nor python_embeded were found, print an error and exit +if !VENV_ACTIVATED! equ 0 ( + echo Error: Neither venv nor python_embeded were found. + exit /b +) + +where /q git +if !ERRORLEVEL! equ 1 ( + echo Git is installed. + + REM Check if the current directory is a git repository + if not exist ".git" ( + echo This directory is not a git repository. Initializing a new repository. + git init + git remote add origin https://github.com/Nourepide/ComfyUI-Allor + git fetch origin main + git reset --hard origin/main + ) else ( + echo This directory is already a git repository. + ) +) else ( + echo Git is not installed. Using GitPython instead. + + REM Run a Python script that uses GitPython to do the same thing + call !PYTHON_EXECUTABLE! %~f0 +) + +REM Deactivate the virtual environment if it was activated +if !VENV_ACTIVATED! equ 1 ( + deactivate +) + +endlocal +exit /b 0 +''' import git from pathlib import Path @@ -49,20 +104,7 @@ if not (Path('.git').exists() or Path('.git').is_dir()): repo = git.Repo.init() origin = repo.create_remote('origin', 'https://github.com/Nourepide/ComfyUI-Allor') origin.fetch() - origin.pull(origin.refs[0].remote_head) + origin_ref = origin.refs[0] + repo.git.reset('--hard', origin_ref.remote_head) else: print('This directory is already a git repository.') -" - ) - - REM Deactivate the virtual environment - deactivate - ) else ( - echo Error: requirements.txt not found in the current directory. - ) - ) else ( - echo Error: activate script not found in the venv directory. - ) -) else ( - echo Error: venv directory not found. -)