Skip to content

Commit

Permalink
Merge pull request #22339 from mrclary/recreate-runtime
Browse files Browse the repository at this point in the history
PR: Recreate Spyder runtime environment on minor updates (Installers)
  • Loading branch information
ccordoba12 authored Aug 15, 2024
2 parents f3a0a76 + 27651b6 commit e6ec310
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
4 changes: 2 additions & 2 deletions installers-conda/build_installers.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@
indent4 = partial(indent, prefix=" ")

base_specs = {
"python": f"={PY_VER}",
"python": "=3.11.9",
"conda": "=24.5.0",
"menuinst": "=2.1.0",
"mamba": "",
"mamba": "=1.5.8",
}
rt_specs = {
"python": f"={PY_VER}",
Expand Down
19 changes: 15 additions & 4 deletions spyder/plugins/updatemanager/scripts/install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ IF "%~1"=="" GOTO endparse
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

SHIFT
GOTO parse
:endparse
Expand Down Expand Up @@ -56,10 +58,19 @@ exit %ERRORLEVEL%
pushd %installer_dir%

echo Updating Spyder base environment...
%conda% update -n base -y --file conda-base-win-64.lock

echo Updating Spyder runtime environment...
%conda% update -p %prefix% -y --file conda-runtime-win-64.lock
%conda% update --name base --yes --file conda-base-win-64.lock

if "%rebuild%"=="true" (
echo Rebuilding Spyder runtime environment...
%conda% remove --prefix %prefix% --all --yes
mkdir %prefix%\Menu
echo. > "%prefix%\Menu\conda-based-app"
set conda_cmd=create
) else (
echo Updating Spyder runtime environment...
set conda_cmd=update
)
%conda% %conda_cmd% --prefix %prefix% --yes --file conda-runtime-win-64.lock

echo Cleaning packages and temporary files...
%conda% clean --yes --packages --tempfiles %prefix%
Expand Down
20 changes: 15 additions & 5 deletions spyder/plugins/updatemanager/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

unset HISTFILE # Do not write to history with interactive shell

while getopts "i:c:p:" option; do
while getopts "i:c:p:r" option; do
case "$option" in
(i) install_file=$OPTARG ;;
(c) conda=$OPTARG ;;
(p) prefix=$OPTARG ;;
(r) rebuild=true ;;
esac
done
shift $(($OPTIND - 1))
Expand All @@ -20,10 +21,19 @@ update_spyder(){
[[ "$(arch)" = "arm64" ]] && os=${os}-arm64 || os=${os}-64

echo "Updating Spyder base environment..."
$conda update -n base -y --file "conda-base-${os}.lock"

echo "Updating Spyder runtime environment..."
$conda update -p $prefix -y --file "conda-runtime-${os}.lock"
$conda update --name base --yes --file "conda-base-${os}.lock"

if [[ -n "$rebuild" ]]; then
echo "Rebuilding Spyder runtime environment..."
$conda remove --prefix $prefix --all --yes
mkdir -p $prefix/Menu
touch $prefix/Menu/conda-based-app
conda_cmd=create
else
echo "Updating Spyder runtime environment..."
conda_cmd=update
fi
$conda $conda_cmd --prefix $prefix --yes --file "conda-runtime-${os}.lock"

echo "Cleaning packages and temporary files..."
$conda clean --yes --packages --tempfiles $prefix
Expand Down
34 changes: 27 additions & 7 deletions spyder/plugins/updatemanager/widgets/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ def __init__(self, parent):
self.installer_path = None
self.installer_size_path = None

# Type of Spyder update. It can be "major", "minor" or "micro"
self.update_type = None

# ---- General

def set_status(self, status=NO_STATUS):
Expand Down Expand Up @@ -230,12 +233,16 @@ def _process_check_update(self):

def _set_installer_path(self):
"""Set the temp file path for the downloaded installer."""
major_update = (
parse(__version__).major < parse(self.latest_release).major
)
if parse(__version__).major < parse(self.latest_release).major:
self.update_type = 'major'
elif parse(__version__).minor < parse(self.latest_release).minor:
self.update_type = 'minor'
else:
self.update_type = 'micro'

mach = platform.machine().lower().replace("amd64", "x86_64")

if major_update or not is_conda_based_app():
if self.update_type == 'major' or not is_conda_based_app():
if os.name == 'nt':
plat, ext = 'Windows', 'exe'
if sys.platform == 'darwin':
Expand All @@ -250,6 +257,8 @@ def _set_installer_path(self):
self.installer_path = osp.join(dirname, fname)
self.installer_size_path = osp.join(dirname, "size")

logger.info(f"Update type: {self.update_type}")

# ---- Download Update

def _verify_installer_path(self):
Expand All @@ -259,9 +268,14 @@ def _verify_installer_path(self):
):
with open(self.installer_size_path, "r") as f:
size = int(f.read().strip())
return size == osp.getsize(self.installer_path)

update_downloaded = size == osp.getsize(self.installer_path)
else:
return False
update_downloaded = False

logger.debug(f"Update already downloaded: {update_downloaded}")

return update_downloaded

def start_update(self):
"""
Expand Down Expand Up @@ -428,10 +442,14 @@ def start_install(self):

# Sub command
sub_cmd = [tmpscript_path, '-i', self.installer_path]
if self.installer_path.endswith('.zip'):
if self.update_type != 'major':
# Update with conda
sub_cmd.extend(['-c', find_conda(), '-p', sys.prefix])

if self.update_type == 'minor':
# Rebuild runtime environment
sub_cmd.append('-r')

# Final command assembly
if os.name == 'nt':
cmd = ['start', '"Update Spyder"'] + sub_cmd
Expand All @@ -456,6 +474,8 @@ def start_install(self):
cmd = [program['cmd'], program['exe-opt']] + sub_cmd
break

logger.debug(f"""Update command: "{' '.join(cmd)}" """)

subprocess.Popen(' '.join(cmd), shell=True)


Expand Down

0 comments on commit e6ec310

Please sign in to comment.