Switch from py2app to PyInstaller

This commit is contained in:
Micah Lee 2016-04-10 14:20:18 -07:00
parent 3b638cfd99
commit 00d1e29333
7 changed files with 71 additions and 66 deletions

View file

@ -38,41 +38,20 @@ There is a PKBUILD available [here](https://aur.archlinux.org/packages/onionshar
Install Xcode from the Mac App Store. Once it's installed, run it for the first time to set it up. Install Xcode from the Mac App Store. Once it's installed, run it for the first time to set it up.
Install the [latest Python 3.x from python.org](https://www.python.org/downloads/). If you use the built-in version of python that comes with OS X, your .app might not run on other people's computers. If you don't already have it installed, install [Homebrew](http://brew.sh/).
Download and install Qt5 from https://www.qt.io/download-open-source/. I downloaded `qt-unified-mac-x64-2.0.2-2-online.dmg`. There's no need to login to a Qt account during installation. Make sure you install the latest Qt 5.x for clang. Install some dependencies using Homebrew:
Download the source code for [SIP](http://www.riverbankcomputing.co.uk/software/sip/download) and [PyQt](http://www.riverbankcomputing.co.uk/software/pyqt/download5). I downloaded `sip-4.17.tar.gz` and `PyQt-gpl-5.5.1.tar.gz`.
Now extract the source code:
```sh ```sh
tar xvf sip-4.17.tar.gz brew install python3 pyqt5 qt5
tar xvf PyQt-gpl-5.5.1.tar.gz
``` ```
Compile SIP: Install some dependencies using pip3:
```sh ```sh
cd sip-4.17 sudo pip3 install pyinstaller flask stem
python3 configure.py --arch x86_64
make
sudo make install
sudo make clean
``` ```
Compile PyQt:
```sh
cd ../PyQt-gpl-5.5.1
python3 configure.py --qmake ~/Qt/5.5/clang_64/bin/qmake --sip /Library/Frameworks/Python.framework/Versions/3.5/bin/sip --disable=QtPositioning
make
sudo make install
sudo make clean
```
Finally, install some dependencies using pip3: `sudo pip3 install py2app flask stem`
Get the source code: Get the source code:
```sh ```sh

View file

@ -9,7 +9,7 @@ rm -rf $ROOT/dist &>/dev/null 2>&1
# build the .app # build the .app
echo Building OnionShare.app echo Building OnionShare.app
python3 setup.py py2app pyinstaller install/pyinstaller-osx.spec
if [ "$1" = "--sign" ]; then if [ "$1" = "--sign" ]; then
SIGNING_IDENTITY_APP="Developer ID Application: Micah Lee" SIGNING_IDENTITY_APP="Developer ID Application: Micah Lee"

View file

@ -0,0 +1,53 @@
# -*- mode: python -*-
block_cipher = None
a = Analysis(
['osx_scripts/onionshare-gui'],
pathex=['.'],
binaries=None,
datas=[
('../images/*', 'images'),
('../locale/*', 'locale'),
('../onionshare/*.html', 'html'),
('../version', '.')
],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(
a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
exclude_binaries=True,
name='onionshare_gui',
debug=False,
strip=False,
upx=True,
console=False)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='onionshare_gui')
app = BUNDLE(
coll,
name='OnionShare.app',
icon='install/onionshare.icns',
bundle_identifier='com.micahflee.onionshare',
info_plist={
'NSHighResolutionCapable': 'True'
})

View file

@ -26,15 +26,6 @@ def get_platform():
""" """
return platform.system() return platform.system()
if get_platform() == 'Darwin':
# this is hacky, but it ultimate ends up returning the absolute path to
# OnionShare.app/Contents/Resources, based on the location of helpers.py
helpers_path = os.path.realpath(os.path.abspath(inspect.getfile(inspect.currentframe())))
osx_resources_dir = os.path.dirname(os.path.dirname(helpers_path))
else:
osx_resources_dir = None
def get_onionshare_dir(): def get_onionshare_dir():
""" """
Returns the OnionShare directory. Returns the OnionShare directory.
@ -45,6 +36,14 @@ def get_onionshare_dir():
onionshare_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) onionshare_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
return onionshare_dir return onionshare_dir
def get_osx_resource_path(filename):
"""
Returns the path a resource file in a frozen PyInstall app
"""
if get_platform() == 'Darwin':
# Resource path from frozen PyInstaller app
# https://pythonhosted.org/PyInstaller/#run-time-information
return os.path.join(os.path.join(os.path.dirname(sys._MEIPASS), 'Resources'), filename)
def get_html_path(filename): def get_html_path(filename):
""" """
@ -52,7 +51,7 @@ def get_html_path(filename):
""" """
p = get_platform() p = get_platform()
if p == 'Darwin': if p == 'Darwin':
prefix = os.path.join(osx_resources_dir, 'html') prefix = get_osx_resource_path('html')
else: else:
prefix = get_onionshare_dir() prefix = get_onionshare_dir()
return os.path.join(prefix, filename) return os.path.join(prefix, filename)
@ -66,7 +65,7 @@ def get_version():
if p == 'Linux': if p == 'Linux':
version_filename = os.path.join(sys.prefix, 'share/onionshare/version') version_filename = os.path.join(sys.prefix, 'share/onionshare/version')
elif p == 'Darwin': elif p == 'Darwin':
version_filename = os.path.join(osx_resources_dir, 'version') version_filename = get_osx_resource_path('version')
else: else:
version_filename = os.path.join(os.path.dirname(get_onionshare_dir()), 'version') version_filename = os.path.join(os.path.dirname(get_onionshare_dir()), 'version')
return open(version_filename).read().strip() return open(version_filename).read().strip()

View file

@ -36,7 +36,7 @@ def load_strings(default="en"):
if p == 'Linux': if p == 'Linux':
locale_dir = os.path.join(sys.prefix, 'share/onionshare/locale') locale_dir = os.path.join(sys.prefix, 'share/onionshare/locale')
elif p == 'Darwin': elif p == 'Darwin':
locale_dir = os.path.join(helpers.osx_resources_dir, 'locale') locale_dir = helpers.get_osx_resource_path('locale')
else: else:
locale_dir = os.path.join(os.path.dirname(helpers.get_onionshare_dir()), 'locale') locale_dir = os.path.join(os.path.dirname(helpers.get_onionshare_dir()), 'locale')

View file

@ -44,7 +44,7 @@ def get_image_path(filename):
if p == 'Linux': if p == 'Linux':
prefix = os.path.join(sys.prefix, 'share/onionshare/images') prefix = os.path.join(sys.prefix, 'share/onionshare/images')
elif p == 'Darwin': elif p == 'Darwin':
prefix = os.path.join(helpers.osx_resources_dir, 'images') prefix = locale_dir = helpers.get_osx_resource_path('images')
else: else:
prefix = os.path.join(os.path.dirname(get_onionshare_gui_dir()), 'images') prefix = os.path.join(os.path.dirname(get_onionshare_gui_dir()), 'images')
return os.path.join(prefix, filename) return os.path.join(prefix, filename)

View file

@ -96,32 +96,6 @@ if system == 'Linux':
] ]
) )
elif system == 'Darwin':
setup(
name='OnionShare',
version=version,
description=description,
long_description=long_description,
app=['install/osx_scripts/onionshare-gui'],
data_files=[
('images', images),
('locale', locale),
('html', ['onionshare/index.html', 'onionshare/404.html']),
('', ['version'])
],
options={
'py2app': {
'argv_emulation': True,
'iconfile': 'install/onionshare.icns',
'extra_scripts': ['install/osx_scripts/onionshare'],
'includes': [
'PyQt5', 'PyQt5.QtCore', 'PyQt5.QtGui', 'PyQt5.QtWidgets',
'jinja2', 'jinja2.ext', 'jinja2.ext.autoescape', 'sip']
}
},
setup_requires=['py2app', 'flask', 'stem'],
)
elif system == 'Windows': elif system == 'Windows':
import py2exe import py2exe
setup( setup(