-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
executable file
·430 lines (356 loc) · 16.5 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
#!/usr/bin/python
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is a Python binding for Network Security Services (NSS).
#
# The Initial Developer of the Original Code is Red Hat, Inc.
# (Author: John Dennis <jdennis@redhat.com>)
#
# Portions created by the Initial Developer are Copyright (C) 2008,2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
import sys
import os
import re
import subprocess
import re
from distutils.core import setup, Extension, Command
from distutils.spawn import find_executable, spawn
from distutils import log
from distutils.filelist import FileList
from distutils.util import subst_vars, change_root
from distutils.command.build_py import build_py as _build_py
from distutils.command.sdist import sdist as _sdist
version = "0.13"
doc_manifest = [
[['include README LICENSE* doc/ChangeLog',
'recursive-include doc *.py *.txt',],
[('^doc/', '')], None],
[['recursive-include test *.py *.txt',],
None , None],
[['recursive-include lib *.py *.txt',],
[('^lib/', '')] , 'examples'],
[['recursive-include build/doc/html *'],
[('^build/doc/', 'api/')], None],
]
def update_version():
"""If the version string in __init__.py doesn't match the current
version then edit the file replacing the version string
with the current version."""
version_file = 'src/__init__.py'
tmp_file = 'src/__init__.tmp'
version_re = re.compile("^\s*__version__\s*=\s*['\"]([^'\"]*)['\"]")
need_to_update = False
version_found = False
f = open(tmp_file, "w")
for line in open(version_file):
match = version_re.search(line)
if match:
version_found = True
file_version = match.group(1)
if file_version != version:
need_to_update = True
f.write("__version__ = '%s'\n" % version)
else:
f.write(line)
if not version_found:
need_to_update = True
f.write("__version__ = '%s'\n" % version)
if need_to_update:
print "Updating version in \"%s\" to \"%s\"" % (version_file, version)
os.rename(tmp_file, version_file)
else:
os.unlink(tmp_file)
def find_include_dir(dir_names, include_files, include_roots=['/usr/include', '/usr/local/include']):
'''
Locate an include directory on the system which contains the specified include files.
You must provide a list of directory basenames to search. You may optionally provide
a list of include roots. The search proceeds by iterating over each root and appending
each directory basename to it. If the resulting directory path contains all the include
files that directory is returned. If no directory is found containing all the include
files a ValueError is raised.
'''
if len(dir_names) == 0:
raise ValueError("directory search list is empty")
if len(include_files) == 0:
raise ValueError("header file list is empty")
for include_root in include_roots:
for dir_name in dir_names:
include_dir = os.path.join(include_root, dir_name)
if os.path.isdir(include_dir):
for include_file in include_files:
found = True
file_path = os.path.join(include_dir, include_file)
if not os.path.exists(file_path):
found = False
break
if found:
return include_dir
raise ValueError("unable to locate include directory containing header files %s" % include_files)
class BuildPy(_build_py):
"""Specialized Python source builder."""
def run(self):
update_version()
_build_py.run(self)
class SDist(_sdist):
"""Specialized Python source builder."""
def run(self):
update_version()
_sdist.run(self)
class BuildDoc(Command):
description = 'generate documentation'
user_options = [('docdir=', 'd', "directory root for documentation"),
]
def has_epydoc (self):
if find_executable('epydoc'):
return True
else:
return False
sub_commands = [('build_api_doc', has_epydoc),
]
def initialize_options(self):
self.build_base = None
self.build_lib = None
self.docdir = None
def finalize_options(self):
self.set_undefined_options('build',
('build_base', 'build_base'),
('build_lib', 'build_lib'))
if self.docdir is None:
self.docdir = change_root(self.build_base, 'doc')
def run(self):
self.run_command('build')
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
class BuildApiDoc(Command):
description = 'generate the API documentation'
user_options = [('docdir=', 'd', "directory root for documentation"),
('action=', 'a', "epydoc action (html, latex, dvi, ps, pdf, check, pickle"),
('htmldir', 'H', "directory to locate the API HTML files under"),
]
def initialize_options(self):
self.build_base = None
self.build_lib = None
self.docdir = None
self.action = None
self.htmldir = None
def finalize_options(self):
self.set_undefined_options('build',
('build_base', 'build_base'),
('build_lib', 'build_lib'))
if self.action is None:
self.action = 'html'
if self.docdir is None:
if self.action == 'html':
self.docdir = change_root(self.get_finalized_command('build_doc').docdir, 'html')
else:
self.docdir = self.get_finalized_command('build_doc').docdir
def run(self):
prog = find_executable('epydoc')
pkg_dirs = [change_root(self.build_lib, pkg) for pkg in self.distribution.packages]
cmd = [prog, '-v', '--%s' % self.action, '--docformat', 'restructuredtext', '-o', self.docdir]
#if self.verbose: cmd.append('-v')
cmd.extend(pkg_dirs)
self.mkpath(self.docdir)
spawn(cmd)
class InstallDoc(Command):
description = 'install documentation'
user_options = [('docdir=', 'd', "directory root for documentation"),
('root=', None,
"install everything relative to this alternate root directory"),
('skip-build', None,
"skip rebuilding everything (for testing/debugging)"),
]
def initialize_options(self):
self.root = None
self.build_base = None
self.docdir = None
self.skip_build = False
def finalize_options(self):
self.set_undefined_options('install',
('root', 'root'))
self.set_undefined_options('build',
('build_base', 'build_base'))
if self.docdir is None:
self.docdir = change_root(self.build_base, 'doc')
def run(self):
if not self.skip_build:
self.run_command('build_doc')
dst_root = change_root(self.root, self.docdir)
self.copy_transformed_tree(doc_manifest,
dst_root=dst_root,
substitutions={'docdir' : self.docdir})
def copy_transformed_tree(self, install_specs, dst_root=None, src_root=None, substitutions={}):
"""
Copy parts of a source tree to a destination tree with a
different tree structure and/or names.
The basic idea: given a set of source files, copy them to a
destination directory, let's call this operation an
install_spec. A sequence of install_spec's allows one to build
up the destrination tree in any structure desired.
Each install_spec consists of 3 components
(manifest_template, dst_xforms, dst_dir):
The manifest_template is a sequence where each item is identical
to a line in the MANIFEST.in template described in distutils. This
gives you ability to easily specify a set of source files in a
compact abstract manner (with recursion, exclusion, etc.) The
manifest_template yields a sequence of source paths.
dst_xforms is a sequence of regular expression substitutions
applied to the each source path to yield a rewritten destination
path. Each transform is expressed as a two-valued sequence
(pattern, replacement)
dst_dir is a destination directory where the destinations paths
are written to. dst_dir is always relative to the dst_root.
All input may be parametrized via variable substitutions
supplied by a substitution dict. Any use of $name will cause
name to be looked up first in the substitution dict and then
if its not found there in the enviorment. If found it will be
replaced with it's value.
The pseudo code algorithm for processing an install_spec is:
substitute all variables in manifest template
src_list = evaluate manifest template
for each src_path in src_list:
dst_path = src_path
for each xform in dst_xform:
apply xform to dst_path
copy src_root+src_path to dst_root+dest_dir+dest_path
This process is repeated for each install spec. The src_root and
dst_root are also subject to variable substitution.
Examples:
Copy all text files in build/doc to doc:
copy_transformed_tree([[["include build/doc *.txt"], None, 'doc']])
Copy all html files found under build to doc/html and change the extension from
.html to .htm
copy_transformed_tree([[["include build *.html"], [('\.html$','.htm')], 'doc']])
"""
if src_root is not None: src_root = subst_vars(src_root, substitutions)
if dst_root is not None: dst_root = subst_vars(dst_root, substitutions)
filelist = FileList()
if src_root is None:
filelist.findall()
else:
filelist.findall(src_root)
for manifest_template, dst_xforms, dst_dir in install_specs:
if dst_dir is not None: dst_dir = subst_vars(dst_dir, substitutions)
filelist.files = [] # reinitialize to empty
for line in manifest_template:
filelist.process_template_line(subst_vars(line, substitutions))
for src_path in filelist.files:
dst_path = src_path
if dst_xforms:
for dst_xform in dst_xforms:
dst_path = re.sub(dst_xform[0], dst_xform[1], dst_path)
if dst_dir is not None:
dst_path = change_root(dst_dir, dst_path)
if dst_root is None:
full_dst_path = dst_path
else:
full_dst_path = change_root(dst_root, dst_path)
full_dst_dir = os.path.dirname(full_dst_path)
self.mkpath(full_dst_dir)
self.copy_file(src_path, full_dst_path)
#------------------------------------------------------------------------------
def main(argv):
long_description='''
Python bindings for Network Security Services (NSS) and Netscape Portable Runtime (NSPR).
'''
debug_compile_args = ['-O0', '-g']
extra_compile_args = []
for arg in argv:
if arg in ('-d', '--debug'):
print "compiling with debug"
extra_compile_args = debug_compile_args
argv.remove(arg)
nss_include_dir = find_include_dir(['nss3', 'nss'], ['nss.h', 'pk11pub.h'])
nspr_include_dir = find_include_dir(['nspr4', 'nspr'], ['nspr.h', 'prio.h'])
nss_error_extension = \
Extension('nss.error',
sources = ['src/py_nspr_error.c'],
include_dirs = [nss_include_dir, nspr_include_dir],
depends = ['src/py_nspr_common.h', 'src/py_nspr_error.h'],
libraries = ['nspr4'],
extra_compile_args = extra_compile_args,
)
nss_io_extension = \
Extension('nss.io',
sources = ['src/py_nspr_io.c'],
include_dirs = [nss_include_dir, nspr_include_dir],
depends = ['src/py_nspr_common.h', 'src/py_nspr_error.h', 'src/py_nspr_io.h'],
libraries = ['nspr4'],
extra_compile_args = extra_compile_args,
)
nss_nss_extension = \
Extension('nss.nss',
sources = ['src/py_nss.c'],
include_dirs = ['src', nss_include_dir, nspr_include_dir],
depends = ['src/py_nspr_common.h', 'src/py_nspr_error.h', 'src/py_nss.h'],
libraries = ['nspr4', 'ssl3', 'nss3', 'smime3'],
extra_compile_args = extra_compile_args,
)
nss_ssl_extension = \
Extension('nss.ssl',
sources = ['src/py_ssl.c'],
include_dirs = ['src', nss_include_dir, nspr_include_dir],
depends = ['src/py_nspr_common.h', 'src/py_nspr_error.h', 'src/py_nspr_io.h',
'src/py_ssl.h', 'src/py_nss.h'],
libraries = ['nspr4', 'ssl3'],
extra_compile_args = extra_compile_args,
)
#bug_enter = 'https://bugzilla.redhat.com/buglist.cgi?submit&component=python-nss&product=Fedora&classification=Fedora'
#bug_tracker = 'https://bugzilla.redhat.com/enter_bug.cgi?component=python-nss&product=Fedora&classification=Fedora',
setup(name = 'python-nss',
version = version,
description = 'Python bindings for Network Security Services (NSS) and Netscape Portable Runtime (NSPR)',
long_description = long_description,
author = 'John Dennis',
author_email = 'jdennis@redhat.com',
maintainer = 'John Dennis',
maintainer_email = 'jdennis@redhat.com',
license = 'MPLv1.1 or GPLv2+ or LGPLv2+',
platforms = 'posix',
url = 'http://www.mozilla.org/projects/security/pki/python-nss',
download_url = '',
ext_modules = [nss_error_extension,
nss_io_extension,
nss_nss_extension,
nss_ssl_extension,
],
package_dir = {'nss':'src'},
packages = ['nss'],
cmdclass = {'build_doc' : BuildDoc,
'build_api_doc' : BuildApiDoc,
'install_doc' : InstallDoc,
'build_py' : BuildPy,
'sdist' : SDist,
},
)
return 0
#------------------------------------------------------------------------------
if __name__ == "__main__":
sys.exit(main(sys.argv))