Skip to content

Commit

Permalink
add PyInstaller hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
nchammas committed Jan 31, 2016
1 parent 64bea5c commit d4de211
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ venv/
flintrock-logo/
.hypothesis/
*.prf
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ python:
- "3.5"
install:
- "pip install -r requirements/developer.pip"
- "curl -L -o pandoc.deb https://github.com/jgm/pandoc/releases/download/1.16.0.2/pandoc-1.16.0.2-1-amd64.deb && sudo dpkg -i pandoc.deb"
script:
- "py.test ./tests/test_static.py"
- "py.test ./tests/test_flintrock.py"
- "py.test ./tests/test_pyinstaller_packaging.py"
addons:
artifacts:
paths:
- "dist/*.zip"
s3_region: "us-east-1"
9 changes: 8 additions & 1 deletion flintrock/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
import os
import posixpath
import shlex
import sys
import time

# Flintrock modules
from .exceptions import SSHError, NodeError
from .ssh import get_ssh_client, ssh_check_output, ssh

THIS_DIR = os.path.dirname(os.path.realpath(__file__))
FROZEN = getattr(sys, 'frozen', False)

if FROZEN:
THIS_DIR = sys._MEIPASS
else:
THIS_DIR = os.path.dirname(os.path.realpath(__file__))

SCRIPTS_DIR = os.path.join(THIS_DIR, 'scripts')


Expand Down
7 changes: 6 additions & 1 deletion flintrock/flintrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
from flintrock import __version__
from .services import HDFS, Spark # TODO: Remove this dependency.

THIS_DIR = os.path.dirname(os.path.realpath(__file__))
FROZEN = getattr(sys, 'frozen', False)

if FROZEN:
THIS_DIR = sys._MEIPASS
else:
THIS_DIR = os.path.dirname(os.path.realpath(__file__))


def format_message(*, message: str, indent: int=4, wrap: int=70):
Expand Down
8 changes: 7 additions & 1 deletion flintrock/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
from .core import FlintrockCluster
from .ssh import ssh_check_output

THIS_DIR = os.path.dirname(os.path.realpath(__file__))
FROZEN = getattr(sys, 'frozen', False)

if FROZEN:
THIS_DIR = sys._MEIPASS
else:
THIS_DIR = os.path.dirname(os.path.realpath(__file__))

SCRIPTS_DIR = os.path.join(THIS_DIR, 'scripts')


Expand Down
30 changes: 30 additions & 0 deletions generate-standalone-package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import platform
import shutil
import subprocess

from flintrock import __version__ as flintrock_version

THIS_DIR = os.path.dirname(os.path.realpath(__file__))

if __name__ == '__main__':
operating_system = platform.system()
machine_type = platform.machine()

subprocess.run([
'pyinstaller',
'--noconfirm',
'--name', 'flintrock',
'--additional-hooks-dir', '.',
'standalone.py'],
check=True)

shutil.make_archive(
base_name=os.path.join(
THIS_DIR, 'dist',
'flintrock-{v}-{os}-{m}'.format(
v=flintrock_version,
os=operating_system,
m=machine_type)),
format='zip',
root_dir=os.path.join(THIS_DIR, 'dist', 'flintrock'))
5 changes: 5 additions & 0 deletions hook-flintrock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
datas=[
('flintrock/scripts', './scripts'),
('flintrock/templates', './templates'),
('flintrock/config.yaml.template', './'),
]
1 change: 1 addition & 0 deletions requirements/maintainer.pip
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
wheel >= 0.26.0
twine >= 1.6.4
pypandoc >= 1.1.2
PyInstaller >= 3.1
5 changes: 4 additions & 1 deletion requirements/user.pip
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# NOTE: Run pip from Flintrock's root directory, not from the directory containing
# this file.

# Due to: https://github.com/pyinstaller/pyinstaller/issues/1781
setuptools >= 19.0, <= 19.2

# NOTE: The `-e .` syntax lets us reuse the requirements already specified under
# `install_requires` in setup.py.
# See: https://caremad.io/2013/07/setup-vs-requirement/
setuptools >= 18.8.1
-e .
11 changes: 11 additions & 0 deletions standalone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
A standalone script for use by PyInstaller.
Users should not be running this script.
"""

import sys
from flintrock.flintrock import main

if __name__ == '__main__':
sys.exit(main())
20 changes: 20 additions & 0 deletions tests/test_pyinstaller_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import glob
import subprocess
import sys

# External modules
import pytest


@pytest.mark.skipif(sys.version_info < (3, 5), reason="Python 3.5+ is required")
def test_pyinstaller_packaging():
subprocess.run(
['pip', 'install', '-r', 'requirements/maintainer.pip'],
check=True)
subprocess.run(
['python', 'generate-standalone-package.py'],
check=True)
subprocess.run(
['./dist/flintrock/flintrock'],
check=True)
assert glob.glob('./dist/*.zip')

0 comments on commit d4de211

Please sign in to comment.