Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Automatically launch Spyder after installation (Installers) #21084

Merged
merged 12 commits into from
Jul 5, 2023
Merged
2 changes: 1 addition & 1 deletion .github/workflows/installers-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ jobs:

shortcut_path=$HOME/.local/share/applications/spyder_spyder.desktop
if [[ -e $shortcut_path ]]; then
echo "\nContents of" $HOME/.local/spyder-* :
echo -e "\nContents of" $HOME/.local/spyder-* :
ls -al $HOME/.local/spyder-*
echo -e "\nContents of ${shortcut_path}:"
cat $shortcut_path
Expand Down
1 change: 1 addition & 0 deletions installers-conda/build_installers.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def _definitions():
),
"check_path_length": False,
"installer_type": "exe",
"post_install": str(RESOURCES / "post-install.bat"),
}
)

Expand Down
28 changes: 28 additions & 0 deletions installers-conda/resources/post-install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
:: This script launches Spyder after install
@echo off

echo %PREFIX% | findstr /b "%USERPROFILE%" > nul && (
set shortcut_root=%APPDATA%
) || (
set shortcut_root=%ALLUSERSPROFILE%
)
set shortcut="%shortcut_root%\Microsoft\Windows\Start Menu\Programs\spyder\Spyder.lnk"

set tmpdir=%TMP%\spyder
set launch_script=%tmpdir%\launch_script.bat

mkdir %tmpdir% 2> nul
(
echo @echo off
echo :loop
echo tasklist /fi "ImageName eq Spyder-*" /fo csv 2^>NUL ^| findstr /r "Spyder-.*-Windows-x86_64.exe"^>NUL
echo if "%%errorlevel%%"=="0" ^(
echo timeout /t 1 /nobreak ^> nul
echo goto loop
echo ^) else ^(
echo start "" /B %shortcut%
echo exit
echo ^)
) > %launch_script%

C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle hidden -Command "& {Start-Process -FilePath %launch_script% -NoNewWindow}"
89 changes: 60 additions & 29 deletions installers-conda/resources/post-install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
#!/bin/bash -i
mrclary marked this conversation as resolved.
Show resolved Hide resolved
set -e
mrclary marked this conversation as resolved.
Show resolved Hide resolved
unset HISTFILE

echo "*** Running post install script for ${INSTALLER_NAME} ..."

Expand Down Expand Up @@ -63,20 +64,32 @@ add_alias() (

# ----
echo "Creating uninstall script..."
cat <<EOF > ${u_spy_exe}
cat <<END > ${u_spy_exe}
#!/bin/bash

echo "You are about to uninstall Spyder."
echo "If you proceed, aliases will be removed from ~/.bashrc (if present)"
echo "and the following will be removed:"
echo " ${shortcut_path}"
echo " ${PREFIX}"
echo ""
echo "Do you wish to continue?"
read -p " [yes|NO]: " confirm
if [[ \$confirm != [yY] && \$confirm != [yY][eE][sS] ]]; then
echo "Uninstall aborted."
exit 1
while getopts "f" option; do
case "\$option" in
(f) force=true ;;
esac
done
shift \$((\$OPTIND - 1))

if [[ -z \$force ]]; then
cat <<EOF
You are about to uninstall Spyder.
If you proceed, aliases will be removed from ${shell_init}
(if present) and the following will be removed:
${shortcut_path}
${PREFIX}

Do you wish to continue?
EOF
read -p " [yes|NO]: " confirm
confirm=\$(echo \$confirm | tr '[:upper:]' '[:lower:]')
if [[ ! "\$confirm" =~ ^y(es)?$ ]]; then
echo "Uninstall aborted."
exit 1
fi
fi

if [[ \$OSTYPE = "darwin"* ]]; then
Expand All @@ -96,7 +109,7 @@ rm -rf ${shortcut_path}
rm -rf ${PREFIX}

echo "Spyder successfully uninstalled."
EOF
END
chmod u+x ${u_spy_exe}

# ----
Expand All @@ -106,37 +119,55 @@ if [[ -n "$shell_init" ]]; then
fi

# ----
if [[ $OSTYPE = "linux"* ]]; then
if [[ "$OSTYPE" = "linux"* ]]; then
cat <<EOF

###############################################################################
# !!! IMPORTANT !!!
###############################################################################
Spyder can be launched by standard methods in Gnome and KDE desktop
environments. Additionally, Spyder can be launched in Gtk-based desktop
environments (e.g. Xfce) from the command line:

$ gtk-launch spyder

Spyder can also be launched from the command line for all Linux variants by:
environments. It can also be launched from the command line on all Linux
distros with the command:

$ spyder

To uninstall Spyder, run the following from the command line:

$ uninstall-spyder

#####################
# !!! IMPORTANT !!! #
#####################

The spyder and uninstall-spyder commands will only be available in new shell
sessions. To make them available in this session you must source your .bashrc
file with:
These commands will only be available in new shell sessions. To make them
available in this session, you must source your $shell_init file with:

$ source ~/.bashrc
$ source $shell_init

###############################################################################

EOF
fi

echo "*** Post install script for ${INSTALLER_NAME} complete"

# ----
[[ -n "$CI" ]] && exit 0 # Running in CI, don't launch Spyder

echo "Launching Spyder now..."
if [[ "$OSTYPE" = "darwin"* ]]; then
mrclary marked this conversation as resolved.
Show resolved Hide resolved
tmp_dir=${SHARED_INSTALLER_TEMP}/spyder
launch_script=${tmp_dir}/post-install-launch.sh
echo "Creating post-install launch script ..."
mkdir -p $tmp_dir
cat <<EOF > $launch_script
#!/bin/bash
while pgrep -fq Installer.app; do
sleep 1
done
open -a $shortcut_path
EOF
chmod +x $launch_script

nohup $launch_script &>/dev/null &
elif [[ -n "$(which gtk-launch)" ]]; then
gtk-launch $(basename $shortcut_path)
else
nohup $spy_exe &>/dev/null &
fi