2
2
3
3
import glob
4
4
import os
5
- import pkgconfig
6
5
from setuptools import setup
7
6
from setuptools import Extension
8
- import sys
7
+ from setuptools . command import build_ext
9
8
10
- import lxml
11
9
12
10
__name__ = "xmlsec"
13
- __version__ = "1.0.1 "
11
+ __version__ = "1.0.2 "
14
12
__description__ = "Python bindings for the XML Security Library"
15
13
16
14
@@ -29,40 +27,65 @@ def is_debug():
29
27
cflags .extend (["-Os" ])
30
28
31
29
32
- config = pkgconfig .parse ("xmlsec1" )
30
+ def add_to_list (target , up ):
31
+ if up is None :
32
+ return target
33
33
34
+ value = set (target )
35
+ value .update (up )
36
+ target [:] = list (value )
34
37
35
- def add_to_config (key , args ):
36
- value = list (config .get (key , []))
37
- value .extend (args )
38
- config [key ] = value
39
38
39
+ def find_sources (path ):
40
+ return glob .glob (os .path .join (path , "*.c" ))
40
41
41
- add_to_config ('define_macros' , macroses )
42
- add_to_config ('include_dirs' , lxml .get_include ())
43
42
44
- print (config , file = sys .stderr )
43
+ def parse_requirements (filename , __cache = {}):
44
+ try :
45
+ return __cache [filename ]
46
+ except KeyError :
47
+ with open (filename ) as stream :
48
+ result = __cache [filename ] = [x for x in (y .strip () for y in stream ) if x and not x .startswith ('#' )]
49
+ return result
45
50
46
51
47
- def find_sources (path ):
48
- return glob .glob (os .path .join (path , "*.c" ))
52
+ class BuildExt (build_ext .build_ext ):
53
+ def run (self ):
54
+ self .patch_xmlsec ()
55
+ build_ext .build_ext .run (self )
56
+
57
+ def patch_xmlsec (self ):
58
+ # at this moment all setup_requires are installed and we can safety import them
59
+ pkgconfig = __import__ ("pkgconfig" )
60
+ lxml = __import__ ("lxml" )
61
+
62
+ ext = self .ext_map [__name__ ]
63
+ config = pkgconfig .parse ("xmlsec1" )
64
+ # added build flags from pkg-config
65
+ for item in ('define_macros' , 'libraries' , 'library_dirs' , 'include_dirs' ):
66
+ add_to_list (getattr (ext , item ), config .get (item ))
67
+
68
+ add_to_list (ext .include_dirs , lxml .get_include ())
49
69
50
70
51
71
_xmlsec = Extension (
52
72
__name__ ,
53
73
sources = find_sources ("./src" ),
54
74
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' ]
75
+ libraries = [] ,
76
+ library_dirs = [] ,
77
+ include_dirs = [] ,
78
+ define_macros = macroses
59
79
)
60
80
61
81
setup (
62
82
name = __name__ ,
63
83
version = __version__ ,
64
84
description = __description__ ,
65
85
ext_modules = [_xmlsec ],
86
+ cmdclass = {'build_ext' : BuildExt },
87
+ setup_requires = parse_requirements ('requirements.txt' ),
88
+ install_requires = parse_requirements ('requirements.txt' ),
66
89
author = "Ryan Leckey" ,
67
90
68
91
maintainer = 'Bulat Gaifullin' ,
0 commit comments