forked from concordusapps/python-xmlsec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
144 lines (111 loc) · 4.05 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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# from __future__ import absolute_import, unicode_literals, division
from os import path
from pkgutil import get_importer
from setuptools import setup, Extension
from functools import wraps
def lazy(function):
@wraps(function)
def wrapped(*args, **kwargs):
class LazyProxy(object):
def __init__(self, function, args, kwargs):
self._function = function
self._args = args
self._kwargs = kwargs
self._result = None
def __getattribute__(self, name):
if name in ['_function', '_args', '_kwargs', '_result']:
return super(LazyProxy, self).__getattribute__(name)
if self._result is None:
self._result = self._function(*self._args, **self._kwargs)
return object.__getattribute__(self._result, name)
def __setattr__(self, name, value):
if name in ['_function', '_args', '_kwargs', '_result']:
super(LazyProxy, self).__setattr__(name, value)
return
if self._result is None:
self._result = self._function(*self._args, **self._kwargs)
setattr(self._result, name, value)
return LazyProxy(function, args, kwargs)
return wrapped
class Extension(Extension, object):
lxml_extended = False
@property
def include_dirs(self):
dirs = self.__dict__['include_dirs']
if self.lxml_extended:
return dirs
# Resolve lxml include directories.
import lxml
lxml_base = path.dirname(lxml.__file__)
lxml_include = path.join(lxml_base, 'includes')
dirs.insert(0, lxml_include)
dirs.insert(0, lxml_base)
self.lxml_extended = True
return dirs
@include_dirs.setter
def include_dirs(self, dirs):
self.__dict__['include_dirs'] = dirs
@lazy
def make_extension(name, cython=True):
from pkgconfig import parse
# Declare the crypto implementation.
XMLSEC_CRYPTO = 'openssl'
# Process the `pkg-config` utility and discover include and library
# directories.
config = {}
for lib in ['libxml-2.0', 'xmlsec1-%s' % XMLSEC_CRYPTO]:
config.update(parse(lib))
# List-ify config for setuptools.
for key in config:
config[key] = list(config[key])
# Add the source directories for inclusion.
config['include_dirs'].insert(0, 'src')
# Resolve extension location from name.
location = path.join('src', *name.split('.'))
location += '.pyx' if cython else '.c'
# Create and return the extension.
return Extension(name, [location], **config)
# Navigate, import, and retrieve the metadata of the project.
meta = get_importer('src/xmlsec').find_module('meta').load_module('meta')
setup(
name='xmlsec',
version=meta.version,
description=meta.description,
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Cython',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Topic :: Text Processing :: Markup :: XML'
],
author='Concordus Applications',
author_email='[email protected]',
url='https://github.com/concordusapps/python-xmlsec',
setup_requires=[
'setuptools_cython',
'pkgconfig',
'lxml >= 3.0',
],
install_requires=[
'lxml >= 3.0',
],
extras_require={
'test': ['pytest']
},
package_dir={'xmlsec': 'src/xmlsec'},
packages=['xmlsec'],
ext_modules=[
make_extension('xmlsec.constants'),
make_extension('xmlsec.utils'),
make_extension('xmlsec.tree'),
make_extension('xmlsec.key'),
make_extension('xmlsec.ds'),
make_extension('xmlsec.template'),
]
)