-
Notifications
You must be signed in to change notification settings - Fork 76
/
setup.py
192 lines (170 loc) · 5.75 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#
# Copyright 2009 Paul J. Davis <[email protected]>
#
# This file is part of the python-spidermonkey package released
# under the MIT license.
#
"""\
Python/JavaScript bridge module, making use of Mozilla's spidermonkey
JavaScript implementation. Allows implementation of JavaScript classes,
objects and functions in Python, and evaluation and calling of JavaScript
scripts and functions respectively. Borrows heavily from Claes Jacobssen's
Javascript Perl module, in turn based on Mozilla's 'PerlConnect' Perl binding.
""",
# I haven't the sligthest, but this appears to fix
# all those EINTR errors. Pulled and adapted for OS X
# from twisted bug #733
#
# Definitely forgot to comment this out before distribution.
#
# import ctypes
# import signal
# libc = ctypes.CDLL("libc.dylib")
# libc.siginterrupt(signal.SIGCHLD, 0)
import glob
import os
import subprocess as sp
import sys
from distutils.dist import Distribution
import ez_setup
ez_setup.use_setuptools()
from setuptools import setup, Extension
DEBUG = "--debug" in sys.argv
USE_SYSTEM_LIB = "--system-library" in sys.argv
def find_sources(extensions=(".c", ".cpp")):
if USE_SYSTEM_LIB:
return [
fname
for ext in extensions
for fname in glob.glob("spidermonkey/*" + ext)
]
else:
return [
os.path.join(dpath, fname)
for (dpath, dnames, fnames) in os.walk("./spidermonkey")
for fname in fnames
if fname.endswith(extensions)
]
def pkg_config(pkg_name, config=None):
pipe = sp.Popen("pkg-config --cflags --libs %s" % pkg_name,
shell=True, stdout=sp.PIPE, stderr=sp.PIPE)
(stdout, stderr) = pipe.communicate()
if pipe.wait() != 0:
raise RuntimeError("No package configuration found for: %s" % pkg_name)
if config is None:
config = {
"include_dirs": [],
"library_dirs": [],
"libraries": [],
"extra_compile_args": [],
"extra_link_args": []
}
prefixes = {
"-I": ("include_dirs", 2),
"-L": ("library_dirs", 2),
"-l": ("libraries", 2),
"-D": ("extra_compile_args", 0),
"-Wl": ("extra_link_args", 0)
}
for flag in stdout.split():
for prefix in prefixes:
if not flag.startswith(prefix):
continue
# Hack for xulrunner
if flag.endswith("/stable"):
flag = flag[:-6] + "unstable"
name, trim = prefixes[prefix]
config[name].append(flag[trim:])
return config
def nspr_config(config=None):
return pkg_config("nspr", config)
def js_config(config=None):
config = pkg_config("mozilla-js", config)
if "-DJS_THREADSAFE" not in config["extra_compile_args"]:
raise SystemError("Unable to link against a library that was "
"compiled without -DJS_THREADSAFE");
return config
def platform_config():
sysname = os.uname()[0]
machine = os.uname()[-1]
# If we're linking against a system library it should give
# us all the information we need.
if USE_SYSTEM_LIB:
return js_config()
# Build our configuration
config = {
"extra_compile_args": [
"-DJS_THREADSAFE",
"-DPOSIX_SOURCE",
"-D_BSD_SOURCE",
"-Wno-strict-prototypes" # Disable copius JS warnings
],
"include_dirs": [
"spidermonkey/libjs",
"spidermonkey/%s-%s" % (sysname, machine)
],
"library_dirs": [],
"libraries": [],
"extra_link_args": []
}
# Debug builds are useful for finding errors in
# the request counting semantics for Spidermonkey
if DEBUG:
config["extra_compile_args"].extend([
"-UNDEBG",
"-DDEBUG",
"-DJS_PARANOID_REQUEST"
])
if sysname in ["Linux", "FreeBSD"]:
config["extra_compile_args"].extend([
"-DHAVE_VA_COPY",
"-DVA_COPY=va_copy"
])
# Currently no suppot for Win32, patches welcome.
if sysname in ["Darwin", "Linux", "FreeBSD"]:
config["extra_compile_args"].append("-DXP_UNIX")
else:
raise RuntimeError("Unknown system name: %s" % sysname)
return nspr_config(config=config)
Distribution.global_options.append(("debug", None,
"Build a DEBUG version of spidermonkey."))
Distribution.global_options.append(("system-library", None,
"Link against an installed system library."))
setup(
name = "python-spidermonkey",
version = "0.0.9",
license = "MIT",
author = "Paul J. Davis",
author_email = "[email protected]",
description = "JavaScript / Python bridge.",
long_description = __doc__,
url = "http://github.com/davisp/python-spidermonkey",
download_url = "http://github.com/davisp/python-spidermonkey.git",
zip_safe = False,
classifiers = [
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: C',
'Programming Language :: JavaScript',
'Programming Language :: Other',
'Programming Language :: Python',
'Topic :: Internet :: WWW/HTTP :: Browsers',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules',
],
setup_requires = [
'setuptools>=0.6c8',
'nose>=0.10.0',
],
ext_modules = [
Extension(
"spidermonkey",
sources=find_sources(),
**platform_config()
)
],
test_suite = 'nose.collector',
)