forked from davisp/python-spidermonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
98 lines (85 loc) · 3.01 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
"""\
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.
""",
import os
import subprocess as sp
import sys
import ez_setup
ez_setup.use_setuptools()
from setuptools import setup, Extension
def find_sources(extensions=[".c", ".cpp"]):
ret = []
for dpath, dnames, fnames in os.walk("./spidermonkey"):
for fname in fnames:
if os.path.splitext(fname)[1] in extensions:
ret.append(os.path.join(dpath, fname))
return ret
def nspr_config():
pipe = sp.Popen("nspr-config --cflags --libs",
shell=True, stdout=sp.PIPE, stderr=sp.PIPE)
(stdout, stderr) = pipe.communicate()
if pipe.wait() != 0:
raise RuntimeError("Failed to get nspr config.")
bits = stdout.split()
ret = {"include_dirs": [], "library_dirs": [], "libraries": []}
prfx = {"-I": "include_dirs", "-L": "library_dirs", "-l": "libraries"}
for b in bits:
ret[prfx[b[:2]]].append(b[2:])
return ret
def platform_config():
sysname = os.uname()[0]
machine = os.uname()[-1]
config = nspr_config()
config["include_dirs"].append("spidermonkey/%s-%s" % (sysname, machine))
config["extra_compile_args"] = [
"-DJS_THREADSAFE",
"-DPOSIX_SOURCE",
"-D_BSD_SOURCE",
"-Wno-strict-prototypes"
]
if sysname in ["Darwin", "Linux"]:
config["extra_compile_args"].append("-DXP_UNIX")
else:
raise RuntimeError("Unknown system name: %s" % sysname)
return config
setup(
name = "python-spidermonkey",
version = "0.0.2",
license = "MIT",
author = "Paul J. Davis",
author_email = "paul.joseph.davis@gmail.com",
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',
],
ext_modules = [
Extension(
"spidermonkey",
sources=find_sources(),
**platform_config()
)
],
test_suite = 'nose.collector',
)