diff --git a/build_macOS.sh b/build_macOS.sh index e65ac92..2910893 100755 --- a/build_macOS.sh +++ b/build_macOS.sh @@ -9,12 +9,14 @@ VERBOSE=false MAKE_DISK=false KEEP_VENV=false SETUP_ENVIRONMENT=false -while getopts "hvde" OPTION; do +PYINSTALLER=false +while getopts "hvdesp" OPTION; do case "$OPTION" in h) echo "Options:" echo "\t-h Print help (this)" echo "\t-v Verbose output" echo "\t-e Keep Python virtual environment (don't delete)" + echo "\t-p Use PyInstaller to build instead of py2app" echo "\t-s Setup dev environment" echo "\t-d Make disk image (.dmg)" exit 0 @@ -25,6 +27,8 @@ while getopts "hvde" OPTION; do ;; e) KEEP_VENV=true ;; + p) PYINSTALLER=true + ;; s) SETUP_ENVIRONMENT=true ;; *) echo "Incorrect option provided" @@ -37,7 +41,7 @@ done if [ "$SETUP_ENVIRONMENT" = true ] then # Install HomeBrew (only if you don't have it) - #/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # Install Dependencies brew cask install xquartz @@ -72,28 +76,31 @@ then PIP=$(command -v pip) fi -# Precheck for 'restricted' permissions on system Python. See below -# Build will fail if using the system Python and it's restricted -if [ "$(which ${PYTHON})" == "/usr/bin/python" ] +if [ "$PYINSTALLER" = false ] then - if ls -dlO /System/Library/Frameworks/Python.framework | grep 'restricted'> /dev/null + # Precheck for 'restricted' permissions on system Python. See below + # Build will fail if using the system Python and it's restricted + if [ "$(which ${PYTHON})" == "/usr/bin/python" ] then - echo -e "\033[1;31m" - echo " *** *** *** *** *** *** *** *** *** *** *** *** ***" - echo "" - echo " ️You are using the macOS system Python" - echo " and it has the 'restricted' flag set." - echo "" - echo " This causes application packaging to fail." - echo " Please read README.md for details on how to " - echo " resolve this problem." - echo "" - echo " A better choice is to use a 'homebrew' installed" - echo " Python. Please see the README.md for more info." - echo "" - echo " *** *** *** *** *** *** *** *** *** *** *** *** ***" - echo -e "\033[0m" - exit 1 + if ls -dlO /System/Library/Frameworks/Python.framework | grep 'restricted'> /dev/null + then + echo -e "\033[1;31m" + echo " *** *** *** *** *** *** *** *** *** *** *** *** ***" + echo "" + echo " ️You are using the macOS system Python" + echo " and it has the 'restricted' flag set." + echo "" + echo " This causes application packaging to fail." + echo " Please read README.md for details on how to " + echo " resolve this problem." + echo "" + echo " A better choice is to use a 'homebrew' installed" + echo " Python. Please see the README.md for more info." + echo "" + echo " *** *** *** *** *** *** *** *** *** *** *** *** ***" + echo -e "\033[0m" + exit 1 + fi fi fi @@ -119,7 +126,13 @@ echo "Install Dependencies..." ${PIP} install -r requirements.txt echo "Build macOS Application Bundle..." -${PYTHON} py2app_setup.py py2app --packages=PIL +if [ "$PYINSTALLER" = true ] +then + ${PYTHON} -OO -m PyInstaller -y --clean k40_whisperer.spec + rm -rf dist/k40_whisperer +else + ${PYTHON} py2app_setup.py py2app --packages=PIL +fi echo "Copy support files to dist..." cp k40_whisperer_test.svg Change_Log.txt gpl-3.0.txt README_MacOS.md dist @@ -140,8 +153,16 @@ fi if [ "$MAKE_DISK" = true ] then echo "Build macOS Disk Image..." - rm ./K40-Whisperer-${VERSION}.dmg - hdiutil create -fs HFS+ -volname K40-Whisperer-${VERSION} -srcfolder ./dist ./K40-Whisperer-${VERSION}.dmg + + if [ "$PYINSTALLER" = true ] + then + VOLNAME=K40-Whisperer-${VERSION}-pyinstaller + else + VOLNAME=K40-Whisperer-${VERSION} + fi + + rm ${VOLNAME}.dmg + hdiutil create -fs HFS+ -volname ${VOLNAME} -srcfolder ./dist ./K40-Whisperer-${VERSION}.dmg fi echo "Done." \ No newline at end of file diff --git a/k40_whisperer.spec b/k40_whisperer.spec new file mode 100644 index 0000000..c778498 --- /dev/null +++ b/k40_whisperer.spec @@ -0,0 +1,49 @@ +# -*- mode: python -*- +# +# pyinstaller -y --clean k40_whisperer.spec +# python -OO -m PyInstaller -y --clean k40_whisperer.spec +# + +block_cipher = None + +a = Analysis(['k40_whisperer.py'], + pathex=['/Users/houser/Projects/K40_Whisperer'], + binaries=[], + datas=[], + hiddenimports=[], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name='k40_whisperer', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + runtime_tmpdir=None, + console=False + ) +app = BUNDLE(exe, + name='K40 Whisperer.app', + icon='emblem.icns', + bundle_identifier=None, + info_plist={ + 'NSPrincipleClass': 'NSApplication', + 'NSAppleScriptEnabled': False, + 'CFBundleIdentifier': 'com.scorchworks.k40_whisperer', + 'CFBundleName': 'K40 Whisperer', + 'CFBundleDisplayName': 'K40 Whisperer', + 'CFBundleShortVersionString': '0.32' + } + ) diff --git a/requirements.txt b/requirements.txt index 2a9bb95..aafe629 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ lxml pyusb pillow +pyinstaller \ No newline at end of file diff --git a/update_macOS.sh b/update_macOS.sh index efa684b..f8d1b7e 100755 --- a/update_macOS.sh +++ b/update_macOS.sh @@ -128,7 +128,7 @@ sips -s format icns emblem --out emblem.icns # Build macOS application echo "Build macOS Application..." -./build_macOS.sh || exit +./build_macOS.sh -d || exit # Make new patch file echo "Update macOS.patch file..." @@ -138,11 +138,6 @@ do diff -Naur $UPDATE_DIR/$i $i >> macOS-${VERSION}.patch done -# Make macOS Disk Image (.dmg) for distribution -echo "Build macOS Disk Image..." -rm ./K40-Whisperer-${VERSION}.dmg -hdiutil create -fs HFS+ -volname K40-Whisperer-${VERSION} -srcfolder ./dist ./K40-Whisperer-${VERSION}.dmg - if [ ! -z ${CLEAN_SOURCE+x} ] then echo "🧹 Cleaning up downloaded source files..."