support NSIS installer (unfinished), rewrite BUILDING.md

This commit is contained in:
Ian Burgwin 2020-09-18 12:54:47 -07:00
parent d612f08b1c
commit fe796af8d4
9 changed files with 258 additions and 53 deletions

View File

@ -1,29 +1,32 @@
This is still being worked on (as of September 6, 2020). Soon this will build a Windows installer, hopefully. This is still being worked on (as of September 18, 2020).
Python versions 3.6, 3.7, and 3.8 are required. For Windows, 32-bit and 64-bit versions are needed. For macOS, the 10.9 variant is required.
# Windows # Windows
Main build environment: Windows 10, version 1903 x64, Python 3.6.8, 3.7.9, and 3.8.5 32-bit and 64-bit from python.org
## Standalone build with cx\_Freeze ## Standalone build
**This part is going to change a lot! I recognize that this part is a bit of a mess. This is temporary (as of September 6, 2020) for test releases.** This expects Python 3.8 32-bit to be installed.
Install the dependencies: Install the dependencies:
```batch ```batch
py -3.8-32 -m pip install --user pycryptodomex==3.9.8 pyctr==0.4.3 cx-Freeze==6.2 wheel py -3.8-32 -m pip install --user pycryptodomex==3.9.8 pyctr==0.4.3 cx-Freeze==6.2
``` ```
Run the build script: `scripts\make-exe-win.bat` Build the exe:
This will build the exe and package it into a zip. ```batch
scripts\make-exe-win.bat
```
## Wheel build Build the standalone zip:
`scripts\make-wheels-win.bat` - build wheels for 3.6, 3.7, and 3.8, 32-bit and 64-bit ```batch
scripts\make-zip-win.bat
```
## Wheel and source dist build
`py -3 setup.py bdist_wheel` - build multi-platform py3 wheel
`py -3 setup.py sdist` - build source distribution
# macOS # macOS
Main build environment: 10.15.6 Supplemental Update; Python 3.6.8, 3.7.9, and 3.8.5 for macOS 10.9 from python.org
No standalone build yet. No standalone build yet.
## Wheel build ## Wheel and source dist build
`./scripts/make-wheels.sh` - build wheels for 3.6, 3.7, and 3.8 `python3 setup.py bdist_wheel` - build multi-platform py3 wheel
`python3 setup.py sdist` - build source distribution `python3 setup.py sdist` - build source distribution

149
installer.nsi Normal file
View File

@ -0,0 +1,149 @@
; This file is a part of ninfs.
;
; Copyright (c) 2017-2020 Ian Burgwin
; This file is licensed under The MIT License (MIT).
; You can find the full license text in LICENSE.md in the root of this project.
;NSIS Modern User Interface
;Basic Example Script
;Written by Joost Verburg
Unicode True
;--------------------------------
;Include Modern UI
!include "MUI2.nsh"
;--------------------------------
;General
!define REG_ROOT "HKCU"
!define REG_PATH "Software\ninfs"
!define NAME "ninfs ${VERSION}"
;Name and file
Name "${NAME}"
OutFile "dist\ninfs-${VERSION}-win32-installer.exe"
;Default installation folder
InstallDir "$LOCALAPPDATA\ninfs"
;Get installation folder from registry if available
InstallDirRegKey "${REG_ROOT}" "${REG_PATH}" ""
;Request application privileges for Windows Vista
RequestExecutionLevel user
;!include LogicLib.nsh
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "ninfs"
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${REG_ROOT}"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "${REG_PATH}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
;--------------------------------
;Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "LICENSE.md"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
Var StartMenuFolder
!insertmacro MUI_PAGE_STARTMENU "Application" $StartMenuFolder
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Installer Sections
Section "ninfs Application" SecInstall
SectionIn RO
SetOutPath "$INSTDIR"
;ADD YOUR OWN FILES HERE...
File "LICENSE.md"
File "README.md"
File /r "build\exe.win32-3.8\"
;Store installation folder
WriteRegStr HKCU "Software\ninfs" "" $INSTDIR
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
Delete "$SMPROGRAMS\$StartMenuFolder\ninfs*.lnk"
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk" "$OUTDIR\ninfsw.exe" "" "$OUTDIR\lib\ninfs\gui\data\windows.ico"
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" "$OUTDIR\Uninstall.exe"
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section /o "Add to PATH" SecPATH
ExecWait '"$INSTDIR/winpathmodify.exe" add "$INSTDIR"'
SectionEnd
LangString DESC_SecInstall ${LANG_ENGLISH} "The main ninfs application."
LangString DESC_SecPATH ${LANG_ENGLISH} "Add the install directory to PATH for command line use."
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecInstall} $(DESC_SecInstall)
!insertmacro MUI_DESCRIPTION_TEXT ${SecPATH} $(DESC_SecPATH)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Descriptions
; ;Language strings
; LangString DESC_SecDummy ${LANG_ENGLISH} "A test section."
;
; ;Assign language strings to sections
; !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
; !insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
; !insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Uninstaller Section
Section "Uninstall"
!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
Delete "$SMPROGRAMS\$StartMenuFolder\ninfs*.lnk"
Delete "$SMPROGRAMS\$StartMenuFolder\uninstall.lnk"
RMDir "$SMPROGRAMS\$StartMenuFolder"
ExecWait '"$INSTDIR/winpathmodify.exe" remove "$INSTDIR"'
Delete "$INSTDIR\LICENSE.md"
Delete "$INSTDIR\README.md"
Delete "$INSTDIR\api-ms-win-crt-*.dll"
Delete "$INSTDIR\python3.dll"
Delete "$INSTDIR\python38.dll"
Delete "$INSTDIR\vcruntime140.dll"
Delete "$INSTDIR\ninfs.exe"
Delete "$INSTDIR\ninfsw.exe"
RMDir /r "$INSTDIR\lib"
Delete "$INSTDIR\Uninstall.exe"
RMDir "$INSTDIR"
DeleteRegKey /ifempty HKCU "Software\ninfs"
SectionEnd

69
ninfs/winpathmodify.py Normal file
View File

@ -0,0 +1,69 @@
# This file is a part of ninfs.
#
# Copyright (c) 2017-2020 Ian Burgwin
# This file is licensed under The MIT License (MIT).
# You can find the full license text in LICENSE.md in the root of this project.
from ctypes import windll
import winreg
from argparse import ArgumentParser
SendMessageTimeoutW = windll.user32.SendMessageTimeoutW
HWND_BROADCAST = 0xFFFF
WM_WININICHANGE = 0x001A
SMTO_NORMAL = 0
def refresh_environment():
res = SendMessageTimeoutW(HWND_BROADCAST, WM_WININICHANGE, 0, 'Environment', SMTO_NORMAL, 10, 0)
print('SendMessageTimeoutW:', res)
def add(path: str):
k = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', 0, winreg.KEY_ALL_ACCESS)
value, keytype = winreg.QueryValueEx(k, 'Path')
paths: list = value.strip(';').split(';')
if path not in paths:
paths.append(path)
winreg.SetValueEx(k, 'Path', 0, keytype, ';'.join(paths))
winreg.CloseKey(k)
refresh_environment()
def remove(path: str):
k = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', 0, winreg.KEY_ALL_ACCESS)
value, keytype = winreg.QueryValueEx(k, 'Path')
paths: list = value.strip(';').split(';')
try:
paths.remove(path)
except ValueError:
pass
winreg.SetValueEx(k, 'Path', 0, keytype, ';'.join(paths))
winreg.CloseKey(k)
refresh_environment()
if __name__ == '__main__':
parser = ArgumentParser(description=r'Modify Path inside HKCU\Environment')
parser.add_argument('oper', help='Operation (add, remove)')
parser.add_argument('path', help='Path to add or remove')
args = parser.parse_args()
if args.oper == 'add':
add(args.path)
elif args.oper == 'remove':
remove(args.path)

View File

@ -1,20 +1 @@
for /f "delims=" %%V in ('py -3 -c "from ninfs import __version__; print(__version__)"') do set VERSION=%%V
del ninfs\hac\*.pyd
del ninfs\hac\*.so
del build\ninfs-%VERSION%
py -3.8-32 setup-cxfreeze.py build_ext --inplace
py -3.8-32 setup-cxfreeze.py build_exe py -3.8-32 setup-cxfreeze.py build_exe
del build\exe.win32-3.8\lib\ninfs\hac\*.cpp
del build\exe.win32-3.8\lib\ninfs\hac\*.pyi
del build\exe.win32-3.8\lib\ninfs\hac\*.h
del build\exe.win32-3.8\lib\ninfs\hac\*.dylib
mkdir dist
move build\exe.win32-3.8 build\ninfs-%VERSION%
copy LICENSE.md build\ninfs-%VERSION%
copy README.md build\ninfs-%VERSION%
py -m zipfile -c dist\ninfs-%VERSION%-win32.zip build\ninfs-%VERSION%

View File

@ -0,0 +1,5 @@
for /f "delims=" %%V in ('py -3 -c "from ninfs import __version__; print(__version__)"') do set VERSION=%%V
mkdir dist
"C:\Program Files (x86)\NSIS\makensis.exe" /DVERSION=%VERSION% installer.nsi

View File

@ -1,9 +0,0 @@
@echo off
REM Error checking from: https://stackoverflow.com/questions/734598
for %%A in (32,64) do (
for %%V in (3.6,3.7,3.8) do (
py -%%V-%%A setup.py bdist_wheel
if %errorlevel% neq 0 exit /b %errorlevel%
)
)

View File

@ -1,9 +0,0 @@
#!/bin/sh
# exit on errors
set -e
# build wheels for 3.6 to 3.7
python3.6 setup.py bdist_wheel
python3.7 setup.py bdist_wheel
python3.8 setup.py bdist_wheel

14
scripts/make-zip-win.bat Normal file
View File

@ -0,0 +1,14 @@
for /f "delims=" %%V in ('py -3 -c "from ninfs import __version__; print(__version__)"') do set VERSION=%%V
set OUTDIR=build\zipbuild\ninfs-%VERSION%
mkdir dist
rmdir /s /q build\zipbuild
mkdir %OUTDIR% || exit /b
copy LICENSE.md %OUTDIR% || exit /b
copy README.md %OUTDIR% || exit /b
xcopy /s /e /i /y build\exe.win32-3.8 %OUTDIR% || exit /b
py -m zipfile -c dist\ninfs-%VERSION%-win32.zip %OUTDIR% || exit /b

View File

@ -40,7 +40,6 @@ build_msi_options = {
executables = [ executables = [
Executable('ninfs/_frozen_main.py', Executable('ninfs/_frozen_main.py',
base=None,
targetName='ninfs', targetName='ninfs',
icon='ninfs/gui/data/windows.ico') icon='ninfs/gui/data/windows.ico')
] ]
@ -51,6 +50,9 @@ if sys.platform == 'win32':
targetName='ninfsw', targetName='ninfsw',
icon='ninfs/gui/data/windows.ico')) icon='ninfs/gui/data/windows.ico'))
executables.append(Executable('ninfs/winpathmodify.py',
targetName='winpathmodify'))
# based on https://github.com/Legrandin/pycryptodome/blob/b3a394d0837ff92919d35d01de9952b8809e802d/setup.py # based on https://github.com/Legrandin/pycryptodome/blob/b3a394d0837ff92919d35d01de9952b8809e802d/setup.py
with open('ninfs/__init__.py', 'r', encoding='utf-8') as f: with open('ninfs/__init__.py', 'r', encoding='utf-8') as f:
for line in f: for line in f: