forked from seeebek/EliteOCR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·137 lines (122 loc) · 5.37 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# -*- coding: utf-8 -*-
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
from os import listdir, mkdir, rmdir, symlink, unlink
from os.path import isdir, islink, isfile, join
import pkg_resources
import platform
import re
import shutil
from tempfile import gettempdir
# Patch py2app extension loader to work with gevent
import py2app.util
py2app.util.LOADER = """
def __load():
imp = __import__("imp")
os = __import__("os")
sys = __import__("sys")
ext = %r
for path in sys.path:
if not path.endswith('lib-dynload'):
continue
ext_path = os.path.join(path, ext)
if os.path.exists(ext_path):
mod = imp.load_dynamic(__name__, ext_path)
break
else:
raise ImportError(repr(ext) + " not found")
__load()
del __load
"""
# Patch py2app recipe enumerator to skip the sip recipe since it's too enthusiastic - we'll list additional Qt modules explicitly
from py2app import recipes
import py2app.build_app
def iterRecipes(module=recipes):
for name in dir(module):
if name.startswith('_') or name=='sip':
continue
check = getattr(getattr(module, name), 'check', None)
if check is not None:
yield (name, check)
py2app.build_app.iterRecipes = iterRecipes
# Hack to handle Qt image plugins (py2app 0.9 sip recipe puts them under Resources, which makes the app unsignable)
from py2app.build_app import PLUGIN_SUFFIXES
PLUGIN_SUFFIXES['.dylib'] = 'qt_plugins/imageformats'
qt_conf = join(gettempdir(), 'qt.conf')
f = open(qt_conf, 'wt')
f.write('[Paths]\nPlugins = Library/qt_plugins\n')
f.close()
VERSION = re.search(r'^appversion\s*=\s*"(.+)"', file('EliteOCR.py').read(), re.MULTILINE).group(1)
APP = ['EliteOCR.py']
DATA_FILES = []
OPTIONS = {'semi_standalone': True,
'site_packages': False,
'iconfile': 'EliteOCR.icns',
'optimize': 2,
'resources': [qt_conf, # http://doc.qt.io/qt-4.8/qt-conf.html
'plugins', # for TD_Export
'translations', 'letters.xml', 'numbers.xml', 'station.xml', 'help', 'commodities.json',
('trainingdata', ['trainingdata/base_training_data.pck', 'trainingdata/README'])
],
'includes': ['PyQt4.QtNetwork'],
'include_plugins': ['/Developer/Applications/Qt/plugins/imageformats/libqgif.dylib', '/Developer/Applications/Qt/plugins/imageformats/libqico.dylib'],
'excludes': ['PIL', 'setuptools', 'matplotlib', 'wx', # random modules that tend to get picked up
'threadworker', 'update', 'updateUI'], # windows-specific source files
'plist': {
'CFBundleName': 'EliteOCR',
'CFBundleIdentifier': 'com.seeebek.eliteOCR', # matches what QSettings stores
'CFBundleShortVersionString': VERSION,
'CFBundleVersion': VERSION,
'LSArchitecturePriority': ['x86_64'], # python exe is fat, but our Frameworks and dylds currently aren't
'LSMinimumSystemVersion': '.'.join(platform.mac_ver()[0].split('.')[:2]), # minimum version = build version
'NSHumanReadableCopyright': u'© 2014 Sebastian Kaminski',
},
'graph': True, # output dependency graph in dist
}
if isdir('/Library/Frameworks/Sparkle.framework'):
OPTIONS['frameworks'] = OPTIONS.get('frameworks', []) + ['Sparkle.framework']
OPTIONS['plist'].update({
'SUEnableAutomaticChecks': False, # we check explitly on startup
'SUAllowsAutomaticUpdates': False,
'SUFeedURL': 'http://eliteocr.sourceforge.net/appcast.xml',
'SUScheduledCheckInterval': 24*60*60,
})
else:
print "Building without Sparkle update support"
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
# Fix up Qt frameworks for codesigning
# https://blog.qt.io/blog/2014/10/29/an-update-on-os-x-code-signing/
root = 'dist/EliteOCR.app/Contents/Frameworks'
for thing in listdir(root):
if not thing.endswith('.framework'):
continue
# Make Resources and executable point to Current version
# https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/FrameworkAnatomy.html
if not(isdir(join(root, thing, 'Versions', 'Current', 'Resources'))):
mkdir(join(root, thing, 'Versions', 'Current', 'Resources'))
if islink(join(root, thing, 'Resources')):
unlink(join(root, thing, 'Resources'))
symlink(join('Versions', 'Current', 'Resources'), join(root, thing, 'Resources'))
fmwk = thing.split('.')[0]
if islink(join(root, thing, fmwk)):
unlink(join(root, thing, fmwk))
symlink(join('Versions', 'Current', fmwk), join(root, thing, fmwk))
# Move Info.plist and QtThing.prl to Resources
if isfile(join(root, thing, 'Contents', 'Info.plist')):
shutil.move(join(root, thing, 'Contents', 'Info.plist'), join(root, thing, 'Resources'))
rmdir(join(root, thing, 'Contents')) # should be empty
if isfile(join(root, thing, fmwk+'.prl')):
shutil.move(join(root, thing, fmwk+'.prl'), join(root, thing, 'Resources'))
# Remove "4.0" version links
for link in listdir(join(root, thing, 'Versions')):
if '.' in link:
unlink(join(root, thing, 'Versions', link))