-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.py
More file actions
178 lines (137 loc) · 5.01 KB
/
setup.py
File metadata and controls
178 lines (137 loc) · 5.01 KB
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
import os
import posixpath
import shutil
import subprocess
import urllib2
from distutils.command.build_ext import build_ext as _build_ext
from distutils.core import setup, Extension
DEFAULT_DISCOUNT_VERSION = '1.6.6'
DEFAULT_DISCOUNT_DOWNLOAD_URL = (
'http://github.com/Orc/discount/tarball/v%s'
) % DEFAULT_DISCOUNT_VERSION
DEFAULT_DISCOUNT_CONFIGURE_OPTS = (
# DL tag extension
'--enable-dl-tag '
# Use pandoc-style header blocks
'--enable-pandoc-header '
# A^B becomes A<sup>B</sup>
'--enable-superscript '
# underscores aren'\''t special in the middle of words
'--relaxed-emphasis '
# Set tabstops to N characters (default is 4)
'--with-tabstops=4 '
# Enable >%id% divisions
'--enable-div '
# Enable (a)/(b)/(c) lists
'--enable-alpha-list '
# Enable memory allocation debugging
# '--enable-amalloc '
# Turn on all stable optional features
# '--enable-all-features '
)
class build_ext(_build_ext):
user_options = _build_ext.user_options + [
('discount-src-path=', None,
'Path to discount source files.'),
('discount-download-url=', None,
'Download url of the discount source files.'),
('discount-configure-opts=', None,
'Default options passed to ./configure.sh'),
]
def initialize_options(self):
_build_ext.initialize_options(self)
self.discount_src_path = None
self.discount_download_url = DEFAULT_DISCOUNT_DOWNLOAD_URL
self.discount_configure_opts = DEFAULT_DISCOUNT_CONFIGURE_OPTS
def build_extension(self, ext):
if self.discount_src_path is None:
filepath = os.path.join(self.build_temp, 'discount.tar.gz')
if not os.path.lexists(self.build_temp):
os.makedirs(self.build_temp)
if not os.path.exists(filepath):
print 'Downloading %s...' % self.discount_download_url
data = urllib2.urlopen(self.discount_download_url)
fp = open(filepath, 'wb')
fp.write(data.read())
fp.close()
print 'Extracting %s...' % filepath
subprocess.call(
['tar', 'xzf', filepath, '-C', self.build_temp]
)
# find extracted source dir
for name in os.listdir(self.build_temp):
candidate_path = os.path.join(self.build_temp, name)
if (os.path.isdir(candidate_path) and
os.path.exists(os.path.join(candidate_path, 'markdown.h'))):
discount_src_path = candidate_path
else:
discount_src_path = self.discount_src_path
if not os.path.exists(
os.path.join(discount_src_path, 'config.h')):
current_dir = os.getcwd()
os.chdir(discount_src_path)
subprocess.call(
['./configure.sh',] + self.discount_configure_opts.split(),
env=os.environ
)
os.chdir(current_dir)
ext.sources = [
os.path.join(discount_src_path, s) for s in ext.sources
]
ext.extra_compile_args += [
'-I%s' % discount_src_path,
'-DVERSION="%s"' % open(
os.path.join(discount_src_path, 'VERSION')
).read().strip()
]
_build_ext.build_extension(self, ext)
ext_filename = self.get_ext_filename(ext.name)
if not os.path.exists(ext_filename):
# Copy the shared library to same dir as setup.py for
# convenience, helpful for running test suite without
# installing package.
shutil.copy(
os.path.join(self.build_lib, ext_filename),
ext_filename
)
setup(
name='discount',
license='BSD',
version='0.2.1STABLE',
author='Trapeze',
author_email='tkemenczy@trapeze.com',
url="http://github.com/trapeze/python-discount",
download_url='http://pypi.python.org/pypi/discount',
description='A Python interface for Discount, the C Markdown parser',
long_description=open('README.rst').read(),
keywords='markdown discount ctypes',
provides=[
'discount',
],
py_modules=[
'discount',
'discount.libmarkdown',
],
ext_modules=[
Extension(
'_discount',
sources=[
'amalloc.c', 'Csio.c', 'css.c', 'docheader.c',
'dumptree.c', 'generate.c', 'markdown.c', 'mkdio.c',
'resource.c', 'toc.c', 'version.c', 'xml.c', 'xmlpage.c',
'basename.c', 'emmatch.c', 'tags.c', 'html5.c',
],
)
],
cmdclass={
'build_ext': build_ext
},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Programming Language :: C',
'Programming Language :: Python',
'Topic :: Text Processing :: Markup'
],
)