diff --git a/.github/workflows/build-updater.yml b/.github/workflows/build-updater.yml index b9badc9..ec8a637 100644 --- a/.github/workflows/build-updater.yml +++ b/.github/workflows/build-updater.yml @@ -49,7 +49,7 @@ jobs: detached: true - name: Setup Build Environment - uses: mamba-org/setup-micromamba@v1 + uses: mamba-org/setup-micromamba@v2 with: condarc: | conda_build: diff --git a/README.md b/README.md index d66aa35..c00e719 100644 --- a/README.md +++ b/README.md @@ -9,5 +9,5 @@ It provides a graphical interface and the necessary scripts to perform the updat You can check how the updater looks by running the following command from the root directory of this repo: ```bash -python spyder_updater/start-update.py --update-info-file tests/info-success.json +python src/spyder_updater/start.py --update-info-file src/tests/info-success.json ``` diff --git a/src/spyder_updater/gui/updater.py b/src/spyder_updater/gui/updater.py index 38076fc..2697e4d 100644 --- a/src/spyder_updater/gui/updater.py +++ b/src/spyder_updater/gui/updater.py @@ -389,7 +389,7 @@ def _handle_error(self, error): # ---- Public API # ------------------------------------------------------------------------- - def start_install(self): + def start_install(self, start_spyder: bool): # Install script script_name = 'install.' + ('bat' if os.name == 'nt' else 'sh') script_path = str( @@ -399,14 +399,19 @@ def start_install(self): # Sub command if self._update_info.get("installation_script") is None: # Running the installation scripts - sub_cmd = [script_path, '-i', self.install_file] - if self.update_type != 'major': - # Update with conda - sub_cmd.extend(['-c', self.conda_exec, '-p', self.env_path]) + sub_cmd = [ + script_path, + '-i', self.install_file, + '-c', self.conda_exec, + '-p', self.env_path + ] if self.update_type == 'minor': # Rebuild runtime environment sub_cmd.append('-r') + + if start_spyder: + sub_cmd.append("-s") else: # For testing script = self._update_info["installation_script"] diff --git a/src/spyder_updater/scripts/install.bat b/src/spyder_updater/scripts/install.bat index 9fe4080..5018714 100644 --- a/src/spyder_updater/scripts/install.bat +++ b/src/spyder_updater/scripts/install.bat @@ -8,6 +8,7 @@ IF "%~1"=="-i" set install_file=%~2& SHIFT IF "%~1"=="-c" set conda=%~2& SHIFT IF "%~1"=="-p" set prefix=%~2& SHIFT If "%~1"=="-r" set rebuild=true +if "%~1"=="-s" set start_spyder=true SHIFT GOTO parse @@ -16,24 +17,9 @@ GOTO parse rem Enforce encoding chcp 65001>nul -echo. -echo ========================================================= -echo Updating Spyder -echo ========================================================= -echo. - call :wait_for_spyder_quit - -IF exist "%conda%" IF exist "%prefix%" ( - call :update_subroutine - call :launch_spyder - goto :exit -) - -IF exist "%install_file%" ( - call :install_subroutine - goto :exit -) +call :update_spyder +if "%start_spyder%"=="true" call :launch_spyder :exit exit %ERRORLEVEL% @@ -46,10 +32,10 @@ IF exist "%install_file%" ( timeout /t 1 /nobreak > nul goto loop ) - echo Spyder is quit. + echo Spyder has quit. goto :EOF -:update_subroutine +:update_spyder for %%C in ("%install_file%") do set installer_dir=%%~dpC pushd %installer_dir% @@ -81,30 +67,3 @@ IF exist "%install_file%" ( start "" /B "%shortcut_path%" goto :EOF - -:install_subroutine - echo Installing Spyder from: %install_file% - - rem Uninstall Spyder - for %%I in ("%prefix%\..\..") do set "conda_root=%%~fI" - - echo Install will proceed after the current Spyder version is uninstalled. - start %conda_root%\Uninstall-Spyder.exe - - rem Must wait for uninstaller to appear on tasklist - :wait_for_uninstall_start - tasklist /fi "ImageName eq Un_A.exe" /fo csv 2>NUL | find /i "Un_A.exe">NUL - IF "%ERRORLEVEL%"=="1" ( - timeout /t 1 /nobreak > nul - goto wait_for_uninstall_start - ) - echo Uninstall in progress... - - :wait_for_uninstall - timeout /t 1 /nobreak > nul - tasklist /fi "ImageName eq Un_A.exe" /fo csv 2>NUL | find /i "Un_A.exe">NUL - IF "%ERRORLEVEL%"=="0" goto wait_for_uninstall - echo Uninstall complete. - - start %install_file% - goto :EOF diff --git a/src/spyder_updater/scripts/install.sh b/src/spyder_updater/scripts/install.sh index f354cdf..9d5d66d 100755 --- a/src/spyder_updater/scripts/install.sh +++ b/src/spyder_updater/scripts/install.sh @@ -1,15 +1,25 @@ #!/bin/bash -while getopts "i:c:p:r" option; do +while getopts "i:c:p:rs" option; do case "$option" in (i) install_file=$OPTARG ;; (c) conda=$OPTARG ;; (p) prefix=$OPTARG ;; (r) rebuild=true ;; + (s) start_spyder=true ;; esac done shift $(($OPTIND - 1)) +wait_for_spyder_quit(){ + while [[ $(pgrep spyder 2> /dev/null) ]]; do + echo "Waiting for Spyder to quit..." + sleep 1 + done + + echo "Spyder has quit." +} + update_spyder(){ # Unzip installer file pushd $(dirname $install_file) @@ -53,37 +63,6 @@ launch_spyder(){ fi } -install_spyder(){ - # First uninstall Spyder - uninstall_script="$prefix/../../uninstall-spyder.sh" - if [[ -f "$uninstall_script" ]]; then - echo "Uninstalling Spyder..." - echo "" - $uninstall_script - [[ $? > 0 ]] && return - fi - - # Run installer - [[ "$OSTYPE" = "darwin"* ]] && open $install_file || sh $install_file -} - -cat < /dev/null) ]]; do - echo "Waiting for Spyder to quit..." - sleep 1 -done - -echo "Spyder quit." - -if [[ -e "$conda" && -d "$prefix" ]]; then - update_spyder - launch_spyder -else - install_spyder -fi +wait_for_spyder_quit +update_spyder +[[ "$start_spyder" == "true" ]] && launch_spyder diff --git a/src/spyder_updater/start.py b/src/spyder_updater/start.py index c7cc635..517aff9 100644 --- a/src/spyder_updater/start.py +++ b/src/spyder_updater/start.py @@ -32,6 +32,12 @@ def main(): type=argparse.FileType(), help="Path to file that has the info to update Spyder" ) + parser.add_argument( + "--start-spyder", + action="store_true", + default=False, + help="Start spyder after successfully installing the update." + ) parser.add_argument( "--version", action="store_true", @@ -67,7 +73,7 @@ def main(): # Instantiate updater and start installation updater = Updater(update_info) - updater.start_install() + updater.start_install(args.start_spyder) updater.show() # Start the Qt event loop