-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
170 lines (150 loc) · 5.56 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
#!/usr/bin/env python
import sys
import os
import subprocess
from glob import glob
from distutils.core import Command
from setuptools import setup, Extension
class TestCommand(Command):
"""Hack for setup.py with implicit build_ext -i
"""
user_options = []
def initialize_options(self):
self.rootdir = os.getcwd()
def finalize_options(self):
pass
def remove_ext(self):
"""Remove extensions
All Python 2.x versions share the same library name. Remove the
file to fix version mismatch errors.
"""
for fname in os.listdir(self.rootdir):
if fname.endswith(("so", "dylib", "pyd", "sl")):
os.unlink(os.path.join(self.rootdir, fname))
def get_lib_dirs(self):
"""Get version, platform and configuration dependend lib dirs
Distutils caches the build command object on the distribution object.
We can retrieve the object to retrieve the paths to the directories
inside the build directory.
"""
build = self.distribution.command_obj["build"]
builddirs = set()
for attrname in 'build_platlib', 'build_lib', 'build_purelib':
builddir = getattr(build, attrname, None)
if not builddir:
continue
builddir = os.path.abspath(os.path.join(self.rootdir, builddir))
if not os.path.isdir(builddir):
continue
builddirs.add(builddir)
return builddirs
def run(self):
self.remove_ext()
# force a build with build_ext
self.run_command("build")
# get lib dirs from build object
libdirs = self.get_lib_dirs()
# add lib dirs to Python's search path
env = os.environ.copy()
env["PYTHONPATH"] = env["DEFUSED_EXPAT"] = os.pathsep.join(libdirs)
# and finally run the test command
errno = subprocess.check_call([sys.executable, "tests.py"], env=env)
raise SystemExit(errno)
if sys.version_info[0:2] >= (3, 4):
moddir = "Modules34"
else:
moddir = "Modules%i%i" % sys.version_info[0:2]
exts = []
expat_inc = [os.path.join(os.getcwd(), 'expat')]
define_macros = [
('HAVE_EXPAT_CONFIG_H', '1'),
#('XML_DEFAULT_MAX_ENTITY_INDIRECTIONS', '40'),
#('XML_DEFAULT_MAX_ENTITY_EXPANSIONS', str(8*1024*1024)),
#('XML_DTD_RESET_FLAG_DEFAULT', '0'),
]
if sys.platform == "win32":
define_macros.extend([
("PYEXPAT_EXPORTS", "1"),
("HAVE_EXPAT_H", "1"),
("XML_NS", "1"),
("XML_DTD", "1"),
("BYTEORDER", "1234"),
("XML_CONTEXT_BYTES", "1024"),
("XML_STATIC", "1"),
("HAVE_MEMMOVE", "1"),
])
expat_lib = []
expat_sources = ['expat/xmlparse.c',
'expat/xmlrole.c',
'expat/xmltok.c']
expat_depends = ['expat/ascii.h',
'expat/asciitab.h',
'expat/expat.h',
'expat/expat_config.h',
'expat/expat_external.h',
'expat/internal.h',
'expat/latin1tab.h',
'expat/utf8tab.h',
'expat/xmlrole.h',
'expat/xmltok.h',
'expat/xmltok_impl.h',
os.path.join(moddir, 'pyexpat.h')
]
exts.append(Extension('pyexpat',
define_macros=define_macros,
include_dirs=expat_inc,
libraries=expat_lib,
sources=[os.path.join(moddir, 'pyexpat.c')] + expat_sources,
depends=expat_depends,
))
define_macros.append(('USE_PYEXPAT_CAPI', None))
exts.append(Extension('_elementtree',
define_macros=define_macros,
include_dirs=expat_inc,
libraries=expat_lib,
sources=[os.path.join(moddir, '_elementtree.c')],
depends=[os.path.join(moddir, 'pyexpat.c')] +
expat_sources + expat_depends,
))
long_description = []
with open("README.txt") as f:
long_description.append(f.read())
with open("CHANGES.txt") as f:
long_description.append(f.read())
setup(
name="defusedexpat",
version="0.4",
ext_modules=exts,
py_modules=["defusedexpat"],
cmdclass={"test": TestCommand},
author="Christian Heimes",
author_email="[email protected]",
maintainer="Christian Heimes",
maintainer_email="[email protected]",
url="https://bitbucket.org/tiran/defusedexpat",
download_url="http://pypi.python.org/pypi/defusedexpat",
keywords="xml expat",
platforms="POSIX, Windows",
license="PSFL",
description="XML bomb protection with modified expat parser",
long_description="\n".join(long_description),
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: Python Software Foundation License",
"Natural Language :: English",
"Operating System :: POSIX",
"Operating System :: Microsoft :: Windows",
"Programming Language :: C",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.1",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
# "Programming Language :: Python :: 3.4",
"Topic :: Text Processing :: Markup :: XML",
],
)