|
1 |
| -#! /usr/bin/env python |
2 |
| -# -*- coding: utf-8 -*- |
3 |
| -# from __future__ import absolute_import, unicode_literals, division |
4 |
| -from os import path |
5 |
| -from pkgutil import get_importer |
6 |
| -from setuptools import setup, Extension |
7 |
| -from functools import wraps |
| 1 | +from __future__ import print_function |
8 | 2 |
|
| 3 | +import glob |
| 4 | +import os |
| 5 | +import pkgconfig |
| 6 | +from setuptools import setup |
| 7 | +from setuptools import Extension |
| 8 | +import sys |
9 | 9 |
|
10 |
| -def lazy(function): |
| 10 | +import lxml |
11 | 11 |
|
12 |
| - @wraps(function) |
13 |
| - def wrapped(*args, **kwargs): |
| 12 | +__name__ = "xmlsec" |
| 13 | +__version__ = "1.0.1" |
| 14 | +__description__ = "Python bindings for the XML Security Library" |
14 | 15 |
|
15 |
| - class LazyProxy(Extension): |
16 |
| - __arguments = dict() |
17 | 16 |
|
18 |
| - def __init__(self, function, args, kwargs): |
19 |
| - self.__arguments["function"] = function |
20 |
| - self.__arguments["args"] = args |
21 |
| - self.__arguments["kwargs"] = kwargs |
22 |
| - self.__arguments["result"] = None |
| 17 | +def is_debug(): |
| 18 | + return bool(os.getenv("PYXMLSEC_DEBUG")) |
23 | 19 |
|
24 |
| - def __getattr__(self, item): |
25 |
| - if self.__arguments["result"] is None: |
26 |
| - self.__arguments["result"] = self.__arguments["function"](*self.__arguments["args"], |
27 |
| - **self.__arguments["kwargs"]) |
28 | 20 |
|
29 |
| - return getattr(self.__arguments["result"], item) |
| 21 | +macroses = [("MODULE_NAME", __name__), ("MODULE_VERSION", __version__), ("MODULE_DOC", __description__)] |
| 22 | +cflags = ["-g", "-std=c99", "-fno-strict-aliasing", "-Wno-error=declaration-after-statement", "-Werror=implicit-function-declaration"] |
30 | 23 |
|
31 |
| - def __setattr__(self, name, value): |
32 |
| - if self.__arguments["result"] is None: |
33 |
| - self.__arguments["result"] = self.__arguments["function"](*self.__arguments["args"], |
34 |
| - **self.__arguments["kwargs"]) |
35 | 24 |
|
36 |
| - setattr(self.__arguments["result"], name, value) |
| 25 | +if is_debug(): |
| 26 | + macroses.append(("PYXMLSEC_ENABLE_DEBUG", 1)) |
| 27 | + cflags.extend(["-Wall", "-O0"]) |
| 28 | +else: |
| 29 | + cflags.extend(["-Os"]) |
37 | 30 |
|
38 |
| - return LazyProxy(function, args, kwargs) |
39 | 31 |
|
40 |
| - return wrapped |
| 32 | +config = pkgconfig.parse("xmlsec1") |
41 | 33 |
|
42 | 34 |
|
43 |
| -@lazy |
44 |
| -def make_extension(name, cython=True): |
45 |
| - from pkgconfig import parse |
| 35 | +def add_to_config(key, args): |
| 36 | + value = list(config.get(key, [])) |
| 37 | + value.extend(args) |
| 38 | + config[key] = value |
46 | 39 |
|
47 |
| - # Declare the crypto implementation. |
48 |
| - xmlsec_crypto = 'openssl' |
49 | 40 |
|
50 |
| - # Process the `pkg-config` utility and discover include and library |
51 |
| - # directories. |
52 |
| - config = {} |
53 |
| - for lib in ['libxml-2.0', 'xmlsec1-%s' % xmlsec_crypto]: |
54 |
| - config.update(parse(lib)) |
| 41 | +add_to_config('define_macros', macroses) |
| 42 | +add_to_config('include_dirs', lxml.get_include()) |
55 | 43 |
|
56 |
| - config['extra_compile_args'] = ['-DXMLSEC_CRYPTO_OPENSSL=1', '-DXMLSEC_NO_CRYPTO_DYNAMIC_LOADING=1'] |
| 44 | +print(config, file=sys.stderr) |
57 | 45 |
|
58 |
| - # List-ify config for setuptools. |
59 |
| - for key in config: |
60 |
| - config[key] = list(config[key]) |
61 | 46 |
|
62 |
| - if 'include_dirs' not in config: |
63 |
| - config['include_dirs'] = [] |
| 47 | +def find_sources(path): |
| 48 | + return glob.glob(os.path.join(path, "*.c")) |
64 | 49 |
|
65 |
| - # Add the source directories for inclusion. |
66 |
| - import lxml |
67 |
| - config['include_dirs'].insert(0, path.dirname(lxml.__file__)) |
68 |
| - config['include_dirs'].insert(0, path.join(path.dirname(lxml.__file__), 'includes')) |
69 |
| - config['include_dirs'].insert(0, 'src') |
70 |
| - |
71 |
| - # Resolve extension location from name. |
72 |
| - location = path.join('src', *name.split('.')) |
73 |
| - location += '.pyx' if cython else '.c' |
74 |
| - |
75 |
| - # Create and return the extension. |
76 |
| - return Extension(name, [location], **config) |
77 |
| - |
78 |
| - |
79 |
| -# Navigate, import, and retrieve the metadata of the project. |
80 |
| -meta = get_importer('src/xmlsec').find_module('meta').load_module('meta') |
81 | 50 |
|
| 51 | +_xmlsec = Extension( |
| 52 | + __name__, |
| 53 | + sources=find_sources("./src"), |
| 54 | + extra_compile_args=cflags, |
| 55 | + libraries=list(config.get('libraries', [])), |
| 56 | + library_dirs=list(config.get('library_dirs', [])), |
| 57 | + include_dirs=list(config.get('include_dirs', [])), |
| 58 | + define_macros=config['define_macros'] |
| 59 | +) |
82 | 60 |
|
83 | 61 | setup(
|
84 |
| - name='xmlsec', |
85 |
| - version=meta.version, |
86 |
| - description=meta.description, |
| 62 | + name=__name__, |
| 63 | + version=__version__, |
| 64 | + description=__description__, |
| 65 | + ext_modules=[_xmlsec], |
| 66 | + author="Ryan Leckey", |
| 67 | + |
| 68 | + maintainer='Bulat Gaifullin', |
| 69 | + maintainer_email='[email protected]', |
| 70 | + url='https://github.com/mehcode/python-xmlsec', |
| 71 | + download_url="https://github.com/mehcode/python-xmlsec/archive/v%s.tar.gz" % __version__, |
| 72 | + license='MIT', |
| 73 | + keywords=["xmlsec"], |
87 | 74 | classifiers=[
|
88 | 75 | 'Development Status :: 3 - Alpha',
|
89 | 76 | 'Intended Audience :: Developers',
|
90 | 77 | 'Intended Audience :: System Administrators',
|
91 | 78 | 'License :: OSI Approved :: MIT License',
|
92 | 79 | 'Operating System :: OS Independent',
|
93 |
| - 'Programming Language :: Cython', |
| 80 | + 'Programming Language :: C', |
94 | 81 | 'Programming Language :: Python :: 2.7',
|
95 | 82 | 'Programming Language :: Python :: 3',
|
96 | 83 | 'Programming Language :: Python :: 3.3',
|
97 | 84 | 'Programming Language :: Python :: 3.4',
|
98 | 85 | 'Topic :: Text Processing :: Markup :: XML'
|
99 | 86 | ],
|
100 |
| - author='Ryan Leckey', |
101 |
| - |
102 |
| - url='https://github.com/mehcode/python-xmlsec', |
103 |
| - setup_requires=[ |
104 |
| - 'setuptools_cython', |
105 |
| - 'pkgconfig', |
106 |
| - 'lxml >= 3.0', |
107 |
| - ], |
108 |
| - install_requires=[ |
109 |
| - 'lxml >= 3.0', |
110 |
| - ], |
111 |
| - extras_require={ |
112 |
| - 'test': ['pytest'] |
113 |
| - }, |
114 |
| - package_dir={'xmlsec': 'src/xmlsec'}, |
115 |
| - packages=['xmlsec'], |
116 |
| - ext_modules=[ |
117 |
| - make_extension('xmlsec.constants'), |
118 |
| - make_extension('xmlsec.utils'), |
119 |
| - make_extension('xmlsec.tree'), |
120 |
| - make_extension('xmlsec.key'), |
121 |
| - make_extension('xmlsec.ds'), |
122 |
| - make_extension('xmlsec.enc'), |
123 |
| - make_extension('xmlsec.template'), |
124 |
| - ] |
125 | 87 | )
|
0 commit comments