Skip to content

Commit

Permalink
Merge pull request #29 from ericpre/fix_bundle
Browse files Browse the repository at this point in the history
Fix winpython bundle
  • Loading branch information
francisco-dlp authored Jul 6, 2018
2 parents fb6e2fc + 8ead161 commit 167245e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ before_deploy:
- ps: if($Env:PYTHON_VERSION -eq "3.5.x") {$Env:PY_VERSION="3.5.4"} else {$Env:PY_VERSION="3.6.3"}
- ps: if($Env:PYTHON_ARCH -eq "64") {$Env:PYTHON_DIR_NAME="python-"+$Env:PY_VERSION+".amd64"} else {$Env:PYTHON_DIR_NAME="python-"+$Env:PY_VERSION}
# Use hyperspy-bundle tag as version name
- "SET BUNDLE_INST_NAME=HyperSpy-%APPVEYOR_REPO_TAG_NAME%-Bundle-Windows-%PY_VERSION%-%PYTHON_ARCH%bit.exe"
- "ren HyperSpy-%APPVEYOR_REPO_TAG_NAME%-Bundle-Windows-%PYTHON_ARCH%bit.exe %BUNDLE_INST_NAME%"
- "SET BUNDLE_INST_NAME=HyperSpy-Bundle-%APPVEYOR_REPO_TAG_NAME%-%PY_VERSION%-%PYTHON_ARCH%bit.exe"
- "ren HyperSpy-Bundle-%APPVEYOR_REPO_TAG_NAME%-%PYTHON_ARCH%bit.exe %BUNDLE_INST_NAME%"
- "SET HYPERSPY_DIR=%WP_INSTDIR%\\%PYTHON_DIR_NAME%\\Lib\\site-packages\\hyperspy"
- ps: py.test --mpl $Env:HYPERSPY_DIR
- ps: Add-AppveyorMessage "Tests finished! Pushing to GitHub..."
Expand Down
22 changes: 11 additions & 11 deletions hspy_bundle/NSIS_installer_script.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
!include "FileFunc.nsh"
!include "X64.nsh"
!include "__DELETE_MACRO_NAME__.nsh"
!define APPNAME "HyperSpy WinPython Bundle"
!define APPNAME "HyperSpy Bundle"
!define APPVERSION "__VERSION__"
!define ARCHITECTURE "__ARCHITECTURE__"
;!define CL64 1 # Uncomment this line for 64bit
!define WINPYTHON_PATH "__WINPYTHON_PATH__"
!define PYTHON_FOLDER "__PYTHON_FOLDER__"
!define S_NAME "HyperSpy-${APPVERSION}-Bundle-Windows-${ARCHITECTURE}"
!define S_NAME "HyperSpy-Bundle-${APPVERSION}-${ARCHITECTURE}"
!define APP_REL_INSTDIR "${APPNAME} ${APPVERSION}"
!define S_DEFINSTDIR_USER "$LocalAppData\${APP_REL_INSTDIR}"
!define S_DEFINSTDIR_USER "$PROFILE\${APP_REL_INSTDIR}"
!define S_DEFINSTDIR_PORTABLE "$DOCUMENTS\${APP_REL_INSTDIR}"
!ifdef CL64
!define S_DEFINSTDIR_ADMIN "$ProgramFiles64\${APP_REL_INSTDIR}"
Expand Down Expand Up @@ -306,8 +306,7 @@ SectionIn RO
Exec 'cmd.exe /C ""${APP_INSTDIR}\WinPython Command Prompt.exe" "jupyter nbextension enable --py --sys-prefix widgetsnbextension""'
${If} $InstMode = 2
; Create right-click context menu entries for Hyperspy Here
Exec 'cmd.exe /C ""${APP_INSTDIR}\WinPython Command Prompt.exe" jupyter_context-menu_add & exit"'
Sleep 3000
Exec 'cmd.exe /C ""${APP_INSTDIR}\hspy_scripts\jupyter_cm.bat" add"'
${EndIf}

${If} $InstMode <> 1
Expand All @@ -318,9 +317,9 @@ SectionIn RO
CreateShortCut "$SMPROGRAMS\${APPNAME}\Jupyter QtConsole.lnk" "${APP_INSTDIR}\hspy_scripts\jupyter_qtconsole.bat" "$\"%HOMEPATH%$\"" "${APP_INSTDIR}\${PYTHON_FOLDER}\Lib\site-packages\start_jupyter_cm\icons\jupyter-qtconsole.ico" 0
CreateShortCut "$SMPROGRAMS\${APPNAME}\WinPython prompt.lnk" "${APP_INSTDIR}\hspy_scripts\cmd.bat" "" "${APP_INSTDIR}\hspy_scripts\cmd.ico" 0
CreateShortCut "$SMPROGRAMS\${APPNAME}\Python prompt.lnk" "${APP_INSTDIR}\hspy_scripts\python.bat" "" "${APP_INSTDIR}\hspy_scripts\python.ico" 0
CreateShortCut "$SMPROGRAMS\${APPNAME}\Spyder IDE.lnk" "${APP_INSTDIR}\hspy_scripts\spyder.bat" "" "${APP_INSTDIR}\${PYTHON_FOLDER}\Lib\site-packages\spyderlib\windows\spyder.ico" 0
CreateShortCut "$SMPROGRAMS\${APPNAME}\Spyder IDE.lnk" "${APP_INSTDIR}\hspy_scripts\spyder.bat" "" "${APP_INSTDIR}\${PYTHON_FOLDER}\Scripts\spyder.ico" 0
CreateShortCut "$SMPROGRAMS\${APPNAME}\WinPython Control Panel.lnk" "${APP_INSTDIR}\WinPython Control Panel.exe" ""
CreateShortCut "$SMPROGRAMS\${APPNAME}\Uninstall ${APPNAME}.lnk" '"${UNINSTALLER_FULLPATH}"'
CreateShortCut "$SMPROGRAMS\${APPNAME}\Uninstall ${APPNAME}.lnk" "${UNINSTALLER_FULLPATH}" "/MODE=$InstMode"

WriteUninstaller "${UNINSTALLER_FULLPATH}"
WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" DisplayName "${APPNAME}"
Expand Down Expand Up @@ -348,7 +347,7 @@ Function UN.onInit
${EndIf}

#Verify the uninstaller - last chance to back out
MessageBox MB_OKCANCEL "Permanantly remove ${APPNAME}?" IDOK next
MessageBox MB_OKCANCEL "Permanantly remove ${APPNAME} ${APPVERSION}?" IDOK next
Abort
next:
FunctionEnd
Expand All @@ -357,14 +356,15 @@ Section "Uninstall"
; Currently do not create uninstaller for mode 1, so ignore
SetOutPath "$TEMP"
${If} $InstMode = 2
Exec 'cmd.exe /C ""$INSTDIR\WinPython Command Prompt.exe" jupyter_context-menu_remove & exit"'
Sleep 3000
Exec 'cmd.exe /C ""${APP_INSTDIR}\hspy_scripts\jupyter_cm.bat" remove"'
Sleep 3000 ; It needs a bit of time to run before it get deleted...
${EndIf}
!insertmacro __DELETE_MACRO_NAME__ $INSTDIR
DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
# Remove StartMenu entries
Delete "$SMPROGRAMS\${APPNAME}\Jupyter QtConsole.lnk"
Delete "$SMPROGRAMS\${APPNAME}\HyperSpyUI.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Jupyter Notebook.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Jupyter QtConsole.lnk"
Delete "$SMPROGRAMS\${APPNAME}\WinPython prompt.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Python prompt.lnk"
Delete "$SMPROGRAMS\${APPNAME}\Spyder IDE.lnk"
Expand Down
38 changes: 26 additions & 12 deletions hspy_bundle/configure_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
SPYDER_BAT = u"""@echo off
call "%~dp0env.bat"
cd "%HOMEPATH%"
python.exe -m spyderlib.start_app %*
spyder3 %*
"""

Expand All @@ -62,6 +62,14 @@
"""

JUPYTER_CM_BAT = u"""@echo off
call "%~dp0env.bat"
cd "%HOMEPATH%"
if [%1]==[add] cmd.exe /c "jupyter_context-menu_add"
if [%1]==[remove] cmd.exe /c "jupyter_context-menu_remove"
"""


def get_nsis_template_path():
return os.path.join(os.path.abspath(os.path.dirname(__file__)),
Expand All @@ -83,14 +91,19 @@ def get_icon_path():
"hyperspy_bundle_installer.ico")


def get_current_hyperspy_version():
"""Fetch version from pypi."""
import json
from urllib.request import urlopen

js_str = urlopen(
"https://pypi.python.org/pypi/hyperspy/json").read().decode('utf8')
return json.loads(js_str)['info']['version']
def get_default_version_name(date=True):
if date is True:
""" Use the date as default version name"""
import datetime
return datetime.date.today().strftime("%Y.%m.%d")
else:
"""Fetch version from pypi."""
import json
from urllib.request import urlopen

js_str = urlopen(
"https://pypi.python.org/pypi/hyperspy/json").read().decode('utf8')
return json.loads(js_str)['info']['version']


def download_hyperspy_license():
Expand Down Expand Up @@ -250,9 +263,10 @@ def create_hspy_scripts(self):
hspy_scripts)
for f, script in zip(
("jupyter_qtconsole.bat", "jupyter_notebook.bat",
"spyder.bat", "python.bat", "cmd.bat", "hyperspyui.bat"),
"spyder.bat", "python.bat", "cmd.bat", "hyperspyui.bat",
"jupyter_cm.bat"),
(QTCONSOLE_BAT, NOTEBOOK_BAT, SPYDER_BAT, PYTHON_BAT,
CMD_BAT, HSPYUI_BAT)):
CMD_BAT, HSPYUI_BAT, JUPYTER_CM_BAT)):
with io.open(os.path.join(hspy_scripts, f), 'w',
newline='\r\n', errors="ignore") as f:
f.write(script)
Expand Down Expand Up @@ -301,7 +315,7 @@ def patch_start_jupyter_cm(self):
if len(sys.argv) > 3:
version = sys.argv[3]
else:
version = get_current_hyperspy_version()
version = get_default_version_name()
if not os.path.exists('COPYING.txt'):
download_hyperspy_license()
p = HSpyBundleInstaller(bundle_dir, version, arch)
Expand Down

0 comments on commit 167245e

Please sign in to comment.