Skip to content

Commit bc3c7fa

Browse files
authored
Merge pull request #40 from bgaifullin/master
Fixed installation via pip #39
2 parents 1f4f851 + ee6f184 commit bc3c7fa

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

setup.py

+41-18
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
import glob
44
import os
5-
import pkgconfig
65
from setuptools import setup
76
from setuptools import Extension
8-
import sys
7+
from setuptools.command import build_ext
98

10-
import lxml
119

1210
__name__ = "xmlsec"
13-
__version__ = "1.0.1"
11+
__version__ = "1.0.2"
1412
__description__ = "Python bindings for the XML Security Library"
1513

1614

@@ -29,40 +27,65 @@ def is_debug():
2927
cflags.extend(["-Os"])
3028

3129

32-
config = pkgconfig.parse("xmlsec1")
30+
def add_to_list(target, up):
31+
if up is None:
32+
return target
3333

34+
value = set(target)
35+
value.update(up)
36+
target[:] = list(value)
3437

35-
def add_to_config(key, args):
36-
value = list(config.get(key, []))
37-
value.extend(args)
38-
config[key] = value
3938

39+
def find_sources(path):
40+
return glob.glob(os.path.join(path, "*.c"))
4041

41-
add_to_config('define_macros', macroses)
42-
add_to_config('include_dirs', lxml.get_include())
4342

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
4550

4651

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())
4969

5070

5171
_xmlsec = Extension(
5272
__name__,
5373
sources=find_sources("./src"),
5474
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
5979
)
6080

6181
setup(
6282
name=__name__,
6383
version=__version__,
6484
description=__description__,
6585
ext_modules=[_xmlsec],
86+
cmdclass={'build_ext': BuildExt},
87+
setup_requires=parse_requirements('requirements.txt'),
88+
install_requires=parse_requirements('requirements.txt'),
6689
author="Ryan Leckey",
6790
author_email='[email protected]',
6891
maintainer='Bulat Gaifullin',

0 commit comments

Comments
 (0)