Skip to content

Instantly share code, notes, and snippets.

@rutsky
Last active January 15, 2017 15:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rutsky/9f6e5b84050a31b1c4ef10e3a1d86f51 to your computer and use it in GitHub Desktop.
Single-file buildbot-worker using PyInstaller

Clone gist:

git clone https://gist.github.com/9f6e5b84050a31b1c4ef10e3a1d86f51.git single-file-buildbot-worker
cd single-file-buildbot-worker

Build with:

sudo docker run -ti -v ${PWD}:/src/ --rm python:2.7 /src/build.sh

If all went fine, generated single-file buildbot-worker will be in the current directory.

#!/bin/bash -e
pushd `dirname "$0"`
rm -rf build dist || :
virtualenv /opt/env
source /opt/env/bin/activate
pip install -r requirements.txt
pip install buildbot-worker
# PyInstaller doesn't play nicely with zope.interface
touch /opt/env/lib/python2.7/site-packages/zope/__init__.py
pyinstaller --distpath /opt/dist --workpath /opt/build buildbot_worker_script.spec
cp /opt/dist/buildbot-worker /src/
popd
from buildbot_worker.scripts.runner import run
if __name__ == '__main__':
run()
# -*- mode: python -*-
singlefile = True
hiddenimports = []
# Workaround for "ImportError: The 'packaging' package is required"
# See <https://github.com/pyinstaller/pyinstaller/issues/1791> for details.
# Fixed by pyinstaller 3.2.
#from PyInstaller.utils.hooks import collect_submodules
#hiddenimports.extend(collect_submodules('pkg_resources._vendor'))
# Lazy-imported using reflection in buildbot_worker.scripts.run
hiddenimports.extend([
'buildbot_worker.scripts.start',
'buildbot_worker.scripts.stop',
'buildbot_worker.scripts.create_worker',
'buildbot_worker.scripts.restart',
])
# Lazy-imported using reflection in buildbot_worker.scripts.run
# Fixed by <https://github.com/buildbot/buildbot/pull/2599>
hiddenimports.extend([
'buildbot_worker.commands.fs',
'buildbot_worker.commands.shell',
'buildbot_worker.commands.transfer',
])
# Lazy-loaded too?
hiddenimports.append('buildbot_worker.bot')
block_cipher = None
# PyInstaller doesn't work with Setuptool's entry points:
# <https://github.com/pyinstaller/pyinstaller/issues/305>
a = Analysis(['buildbot_worker_script.py'],
#pathex=['/home/bob/stuff/buildbot/buildbot/worker'],
pathex=['.'],
binaries=None,
datas=None,
hiddenimports=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)
if singlefile:
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='buildbot-worker',
debug=False,
strip=False,
upx=True,
console=True )
else:
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='buildbot-worker',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='buildbot_worker_script')
PyInstaller==3.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment