-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsetup.py
109 lines (91 loc) · 2.65 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
import sys
from jcc import cpp
options = {
'include': ('org.eclipse.osgi.jar', 'tika-app-1.0.jar',
'log4j.properties.jar'),
'jar': ('tika-parsers-1.0.jar', 'tika-core-1.0.jar',),
'package': ('org.xml.sax',),
'python': 'tika',
'version': '1.0',
'reserved': ('asm',),
'classes': ('java.io.File', 'java.io.FileInputStream',
'java.io.StringBufferInputStream'),
}
import sys
import os.path
jcc_args = []
for dir in sys.path:
probe_dir = os.path.join(dir, 'jcc')
if os.path.exists(probe_dir):
print "Found jcc library at: %s" % probe_dir
jcc_args = [os.path.join(probe_dir, 'nonexistent-argv-0')]
break
if not jcc_args:
raise Exception("tika library not found in sys.path: %s" % sys.path)
for k, v in options.iteritems():
if k == 'classes':
jcc_args.extend(v)
elif hasattr(v, '__iter__'):
for value in v:
jcc_args.append('--%s' % k)
jcc_args.append(value)
else:
jcc_args.append('--%s' % k)
jcc_args.append(v)
setup_args = []
egg_info_mode = False
maxheap = '64m'
i = 1
while i < len(sys.argv):
arg = sys.argv[i]
if arg == 'install':
jcc_args.append('--install')
elif arg == 'build':
jcc_args.append('--build')
elif arg == '-c':
# forwarded_args.append(arg)
pass
elif arg == 'egg_info':
jcc_args.append('--egg-info')
elif arg == '--vmarg':
jcc_args.append(arg)
i += 1
jcc_args.append(sys.argv[i])
elif arg == '--maxheap':
i += 1
maxheap = sys.argv[i]
else:
setup_args.append(arg)
"""
elif arg == '--single-version-externally-managed':
forwarded_args.append(arg)
elif arg == '--egg-base' or arg == '--record':
forwarded_args.append(arg)
forward_next_arg = True
else:
raise NotImplementedError("Unknown argument: %s" % arg)
"""
i += 1
for extra_arg in setup_args:
jcc_args.append('--extra-setup-arg')
jcc_args.append(extra_arg)
jcc_args.extend(['--maxheap', maxheap])
# monkey patch to send extra args to distutils
# import setuptools
# old_setup = setuptools.setup
"""
from distutils.core import setup as old_setup
def new_setup(**attrs):
attrs['script_args'].extend(forwarded_args)
print "running setup %s" % attrs['script_args']
old_setup(**attrs)
def new_compile(**kwargs):
print "changing jccPath from %s to %s" % (kwargs['jccPath'],
jcc.__path__)
kwargs['jccPath'] = jcc.__path__
kwargs['setup_func'] = new_setup
from jcc.python import compile
compile(**kwargs, new_setup)
"""
print "jcc_args = %s" % jcc_args
cpp.jcc(jcc_args)