Skip to content

Commit

Permalink
Merge pull request #161 from mrclary/menuinst-v1
Browse files Browse the repository at this point in the history
Include a menuinst v1 spec file in case users have not updated to menuinst v2 in their base env
  • Loading branch information
ccordoba12 authored Mar 12, 2024
2 parents 4aa2397 + f5f0560 commit b53e887
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
6 changes: 6 additions & 0 deletions recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ for /f "delims=" %%i in (%RECIPE_DIR%\spyder-menu.json) do (
echo !s:__PKG_MAJOR_VER__=%PKG_MAJOR_VER%!>> %MENU_DIR%\spyder-menu.json
)

for /f "delims=" %%i in (%RECIPE_DIR%\spyder-menu-v1.json) do (
set s=%%i
set s=!s:__PKG_VERSION__=%PKG_VERSION%!
echo !s:__PKG_MAJOR_VER__=%PKG_MAJOR_VER%!>> %MENU_DIR%\spyder-menu-v1.json.bak
)

del %SCRIPTS%\spyder_win_post_install.py
del %SCRIPTS%\spyder.bat
del %SCRIPTS%\spyder
44 changes: 37 additions & 7 deletions recipe/post-link.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,57 @@
setlocal ENABLEDELAYEDEXPANSION

set menudir=%PREFIX%\Menu
set menu=%menudir%\spyder-menu.json
set logfile=%PREFIX%\.messages.txt

rem Check for conda-based install
if exist "%menudir%\conda-based-app" (
:: Installed in installer environment, abridge shortcut name
rem Abridge shortcut name
call :patch " ^({{ ENV_NAME }}^)="

rem Nothing more to do for conda-based install
goto :exit
)

if exist "%PREFIX%\condabin\" if exist "%PREFIX%\envs\" (
:: Installed in a base environment, use distribution name
call :patch "ENV_NAME=DISTRIBUTION_NAME"
rem Check for CONDA_PYTHON_EXE
if not exist "%conda_python_exe%" (
rem CONDA_PYTHON_EXE environment variable does not exist.
rem v1 type shortcuts will not work
goto :base_env
)

rem Check menuinst version
for /F "tokens=*" %%i in (
'%conda_python_exe% -c "import menuinst; print(int(menuinst.__version__[0]) < 2)"'
) do (
if "%%~i"=="True" call :use_menu_v1
)

:base_env
if exist "%PREFIX%\condabin\" if exist "%PREFIX%\envs\" (
rem Installed in a base environment, use distribution name
call :patch "ENV_NAME=DISTRIBUTION_NAME"
)
goto :exit

:exit
exit /b %errorlevel%
exit /b %errorlevel%

:patch
set menu=%menudir%\spyder-menu.json
set tmpmenu=%menudir%\spyder-menu-tmp.json
set findreplace=%~1
for /f "delims=" %%a in (%menu%) do (
set s=%%a
echo !s:%findreplace%!>> "%tmpmenu%"
)
move /y "%tmpmenu%" "%menu%"
goto :exit
goto :eof

:use_menu_v1
copy /y "%menudir%\spyder-menu-v1.json.bak" "%menu%"

rem Notify user
echo. >> %logfile%
echo Warning: Using menuinst v1 >> %logfile%
echo Please update to menuinst v2 in the base environment and reinstall Spyder >> %logfile%
goto :eof
6 changes: 3 additions & 3 deletions recipe/post-link.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash
set -e

[[ $(sed --version 2>/dev/null) ]] && opts=("-i" "-E") || opts=("-i" "" "-E")
[[ $(sed --version 2>/dev/null) ]] && opts=("-i" "-E") || opts=("-i" "''" "-E")
menu="${PREFIX}/Menu/spyder-menu.json"

if [[ -f "${PREFIX}/Menu/conda-based-app" ]]; then
# Installed in installer environment, abridge shortcut name
sed "${opts[@]}" "s/ \(\{\{ ENV_NAME \}\}\)//g" $menu
sed ${opts[@]} "s/ \(\{\{ ENV_NAME \}\}\)//g" $menu
elif [[ -d "${PREFIX}/condabin" && -d "${PREFIX}/envs" ]]; then
# Installed in a base environment, use distribution name
sed "${opts[@]}" "s/ENV_NAME/DISTRIBUTION_NAME/g" $menu
sed ${opts[@]} "s/ENV_NAME/DISTRIBUTION_NAME/g" $menu
fi
12 changes: 12 additions & 0 deletions recipe/spyder-menu-v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"menu_name": "${DISTRIBUTION_NAME} spyder",
"menu_items":
[
{
"name": "Spyder __PKG_MAJOR_VER__",
"pywscript": "${PYTHON_SCRIPTS}/spyder-script.py",
"workdir": "${PERSONALDIR}/Python Scripts",
"icon": "${MENU_DIR}/spyder.ico"
}
]
}

0 comments on commit b53e887

Please sign in to comment.