-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.py
More file actions
171 lines (135 loc) · 4.84 KB
/
setup.py
File metadata and controls
171 lines (135 loc) · 4.84 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages, Extension
from pkgutil import get_importer
from collections import defaultdict
from functools import wraps
from distutils import sysconfig
import re
from fnmatch import fnmatch
from os.path import join
import os
def find(directory, patterns):
result = []
for node, _, filenames in os.walk(directory):
for filename in filenames:
for pattern in patterns:
if fnmatch(filename, pattern):
result.append(join(node, filename))
return result
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 __len__(self):
return self.__len__()
def __iter__(self):
return self.__iter__()
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
# Navigate, import, and retrieve the metadata of the project.
meta = get_importer('src/hummus').find_module('meta').load_module('meta')
def make_config():
from pkgconfig import parse
# Process the `pkg-config` utility and discover include and library
# directories.
config = defaultdict(set)
for lib in ['zlib', 'libtiff-4', 'freetype2']:
for key, value in parse(lib).items():
config[key].update(value)
# Add libjpeg (no .pc file).
config['libraries'].add('jpeg')
# List-ify config for setuptools.
for key in config:
config[key] = list(config[key])
# Add hummus.
config['include_dirs'].insert(0, 'lib/hummus/PDFWriter')
config['include_dirs'].insert(0, 'lib/python')
# Add local library.
config['include_dirs'].insert(0, 'src')
# Return built config.
return config
@lazy
def make_extension(name, sources=None, cython=True):
# Resolve extension location from name.
location = join('src', *name.split('.'))
location += '.pyx' if cython else '.cpp'
# NOTE: Performing black magic hacks to remove --as-needed from the linker
# flags if present.
sysconfig.get_config_vars()
lds = sysconfig._config_vars['LDSHARED']
sysconfig._config_vars['LDSHARED'] = re.sub(r',?--as-needed,??', '', lds)
config = make_config()
config['libraries'].insert(0, 'hummus')
# Create and return the extension.
return Extension(
name=name,
sources=sources + [location] if sources else [location],
language='c++',
**config)
@lazy
def make_library(name, directory):
patterns = ['*.cxx', '*.cpp']
return [name, dict(sources=find(directory, patterns), **make_config())]
setup(
name='hummus',
version=meta.version,
description=meta.description,
author='Concordus Applications',
author_email='support@concordusapps.com',
url='https://github.com/concordusapps/python-hummus',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.3',
],
package_dir={'hummus': 'src/hummus'},
packages=find_packages('src'),
setup_requires=[
'setuptools_cython',
'pkgconfig'
],
install_requires=[
'six',
'wand',
],
extras_require={
'test': ['pytest'],
},
libraries=[
make_library('hummus', 'lib/hummus/PDFWriter'),
],
ext_modules=[
make_extension('hummus.reader'),
make_extension('hummus.writer'),
make_extension('hummus.rectangle'),
make_extension('hummus.page'),
make_extension('hummus.context'),
make_extension('hummus.text'),
make_extension('hummus.image'),
make_extension(
name='hummus.interface',
sources=find('lib/python/interface', ['*.cxx'])),
]
)