Skip to content

Commit

Permalink
[#408] Small reduction in bloat on Mac OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
quicklizard99 committed Dec 15, 2016
1 parent 30df8da commit 0190758
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 44 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ MANIFEST
*spec
!inselect.spec
!read_barcodes.spec
!segment.spec
*tar.gz
*dmg
.directory
Expand Down
25 changes: 21 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,32 @@ echo Wheel build
mv dist/inselect-*.whl .

if [[ "$OSTYPE" == "darwin"* ]]; then
# Modules to be excluded - .spec files read this env var
# See https://github.com/pyinstaller/pyinstaller/wiki/Recipe-remove-tkinter-tcl
# for details of excluding all of the tcl, tk, tkinter shat
export EXCLUDE_MODULES="2to3 elementtree FixTk PIL._imagingtk ssl tcl tk _tkinter tkinter Tkinter"

# Scripts that have additional requirements in their own spec files
for script in inselect read_barcodes segment; do
for script in inselect read_barcodes; do
pyinstaller --clean $script.spec
done

# Scripts for which the .spec file can be generated
for script in export_metadata ingest save_crops; do
# Format excludes for pyinstaller command line
export EXCLUDE_MODULES=`python -c "print(' '.join('--exclude-module {0}'.format(e) for e in '$EXCLUDE_MODULES'.split(' ')))"`

# export_metadata uses neither cv2 nor numpy
pyinstaller --onefile --exclude-module cv2 --exclude-module numpy \
$EXCLUDE_MODULES inselect/scripts/export_metadata.py

pyinstaller --onefile $EXCLUDE_MODULES \
--hidden-import sklearn.neighbors.typedefs \
--hidden-import sklearn.neighbors.dist_metrics \
inselect/scripts/segment.py

# Other scripts
for script in ingest save_crops; do
rm -rf $script.spec
pyinstaller --onefile --hidden-import numpy inselect/scripts/$script.py
pyinstaller --onefile $EXCLUDE_MODULES inselect/scripts/$script.py
done

# Add a few items to the PropertyList file generated by PyInstaller
Expand Down
9 changes: 7 additions & 2 deletions inselect.spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- mode: python -*-
import os
import sys

from pathlib import Path
Expand All @@ -8,7 +9,12 @@ from pyzbar import pyzbar

block_cipher = None

# See https://github.com/pyinstaller/pyinstaller/wiki/Recipe-remove-tkinter-tcl
# for details of excluding all of the tcl, tk, tkinter shat
sys.modules['FixTk'] = None


print(os.getenv('EXCLUDE_MODULES', []).split(' '))
a = Analysis(
['inselect/scripts/inselect.py'],
pathex=[str(Path('.').absolute())],
Expand All @@ -19,7 +25,7 @@ a = Analysis(
hiddenimports=['sklearn.neighbors.typedefs'],
hookspath=[],
runtime_hooks=[],
excludes=[],
excludes=os.getenv('EXCLUDE_MODULES', []).split(' '),
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher
Expand All @@ -32,7 +38,6 @@ a.binaries += TOC([
for dep in pylibdmtx.EXTERNAL_DEPENDENCIES + pyzbar.EXTERNAL_DEPENDENCIES
])


ICON = 'icons/inselect.icns'

pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
Expand Down
4 changes: 3 additions & 1 deletion read_barcodes.spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- mode: python -*-
import os

from pathlib import Path

from pylibdmtx import pylibdmtx
Expand All @@ -15,7 +17,7 @@ a = Analysis(
hiddenimports=['numpy'],
hookspath=[],
runtime_hooks=[],
excludes=[],
excludes=os.getenv('EXCLUDE_MODULES', []).split(' '),
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher
Expand Down
36 changes: 0 additions & 36 deletions segment.spec

This file was deleted.

0 comments on commit 0190758

Please sign in to comment.