Skip to content

Commit

Permalink
Merge branch pyinstaller changes. Use a single branch with options fo…
Browse files Browse the repository at this point in the history
…r build (-p).
  • Loading branch information
stephenhouser committed Dec 10, 2019
1 parent bb3996a commit 3a83496
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 31 deletions.
71 changes: 46 additions & 25 deletions build_macOS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,6 +27,8 @@ while getopts "hvde" OPTION; do
;;
e) KEEP_VENV=true
;;
p) PYINSTALLER=true
;;
s) SETUP_ENVIRONMENT=true
;;
*) echo "Incorrect option provided"
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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."
49 changes: 49 additions & 0 deletions k40_whisperer.spec
Original file line number Diff line number Diff line change
@@ -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'
}
)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
lxml
pyusb
pillow
pyinstaller
7 changes: 1 addition & 6 deletions update_macOS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand All @@ -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..."
Expand Down

0 comments on commit 3a83496

Please sign in to comment.