Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PyInstaller build scripts #313

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ cookies.txt
.idea/
.cache/
htmlcov/
pyinstaller/hangups.spec
19 changes: 19 additions & 0 deletions pyinstaller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# CentOS 6 (for glibc forward-compatibility) with Python 3.5 and PyInstaller

FROM centos:6
MAINTAINER Tom Dryer <[email protected]>

RUN yum install -y curl gcc make openssl-devel

RUN curl -LO https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tgz && \
tar -xzf Python-3.5.3.tgz && \
cd Python-3.5.3 && \
./configure --enable-shared --enable-ipv6 --enable-optimizations && \
make && \
make install && \
cd .. && \
rm -rf Python-3.5.3 Python-3.5.3.tgz

ENV LD_LIBRARY_PATH /usr/local/lib

RUN /usr/local/bin/pip3 install pyinstaller
36 changes: 36 additions & 0 deletions pyinstaller/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
SCRIPT_PATH=wrapper.py
DIST_PATH=dist
WORK_PATH=build
APP_NAME=hangups
VERSION=$(shell grep -E --only-matching "[0-9.]+" ../hangups/version.py)
DIST_NAME=${APP_NAME}-${VERSION}-linux-x86_64
SUDO_USER?=${USER}

DOCKER_VOLUME=/opt/build
DOCKER_TAG=pyinstaller

pyinstaller:
pyinstaller \
--hidden-import=pkg_resources \
--clean \
--strip \
--noconfirm \
--workpath "${WORK_PATH}" \
--distpath "${DIST_PATH}" \
--name "${APP_NAME}" \
"${SCRIPT_PATH}"
"${DIST_PATH}/${APP_NAME}/${APP_NAME}" --version
rm -rf "${DIST_PATH}/${DIST_NAME}"
mv "${DIST_PATH}/${APP_NAME}" "${DIST_PATH}/${DIST_NAME}"
tar -zcvf "${DIST_PATH}/${DIST_NAME}.tar.gz" --directory "${DIST_PATH}" "${DIST_NAME}"

docker-pyinstaller:
docker build -t "${DOCKER_TAG}" .
docker run --rm --volume "${realpath ..}:${DOCKER_VOLUME}" --workdir "${DOCKER_VOLUME}" \
"${DOCKER_TAG}" bash -c "pip3 install . && make --directory pyinstaller"
chown --recursive "${SUDO_USER}:${SUDO_USER}" "${DIST_PATH}"

clean:
rm -rf "${WORK_PATH}" "${APP_NAME}.spec" "${DIST_PATH}/${DIST_NAME}" "${DIST_PATH}/${APP_NAME}"

.PHONY: pyinstaller docker-pyinstaller clean
30 changes: 30 additions & 0 deletions pyinstaller/wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Wrapper script to fix aiohttp certificate validation.

PyInstaller bundles OpenSSL with hangups. The path that OpenSSL searches for CA
certificates is set at compile time, so to make hangups portable between Linux
distributions we need to use the SSL_CERT_FILE or SSL_CERT_PATH environment
variables to override it.

Set SSL_CERT_FILE to the CA certificates bundled by requests. This allows
aiohttp to validate certificates.
"""

import os
import sys

import hangups.ui.__main__


def main():
cert_file = os.path.join(sys._MEIPASS, 'requests', 'cacert.pem')
actual_cert_file = os.environ.setdefault('SSL_CERT_FILE', cert_file)
try:
open(actual_cert_file)
except FileNotFoundError as e:
sys.exit('Failed to find CA certificates: {}'.format(e))

hangups.ui.__main__.main()


if __name__ == '__main__':
main()