forked from userzimmermann/carefree-objects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libcfo.py
168 lines (139 loc) · 5.22 KB
/
libcfo.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# carefree-objects
#
# a thread-safe object manager extension for c++
#
# Copyright (C) 2011-2015 Stefan Zimmermann <[email protected]>
#
# carefree-objects is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# carefree-objects is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with carefree-objects. If not, see <http://www.gnu.org/licenses/>.
"""libcfo
.. moduleauthor:: Stefan Zimmermann <[email protected]>
"""
__all__ = ['PREFIX', 'INCLUDE_PATH', 'LIB_PATH']
import sys
import os
from subprocess import Popen
from pkg_resources import parse_requirements
from path import Path
PREFIX = Path(__file__).abspath().dirname()
with PREFIX:
__version__ = open('VERSION').read().strip()
__requires__ = []
with open('requirements.txt') as f:
for req in f.readlines():
req = req.strip()
if req:
__requires__.append(req)
del f, req
__requires__ = list(parse_requirements(__requires__))
if Path('SConstruct').exists():
import zcons
env = dict(os.environ, PYTHONPATH=os.pathsep.join(sys.path))
try:
import libarray_ptr
except ImportError:
pass
else:
env['CPPFLAGS'] = '-I%s %s' % (
str(libarray_ptr.INCLUDE_PATH), env.get('CPPFLAGS', ''))
# if Popen(['scons', 'DEBUG=yes', 'SHARED=yes', 'STATIC=yes',
# 'TESTS=yes'],
# env=env).wait():
# raise RuntimeError
zcons.scons(env_update=env, stdout=sys.__stderr__,
DEBUG=True, SHARED=True, STATIC=True)
del env
INCLUDE_PATH = PREFIX / 'include'
LIB_PATH = PREFIX / 'lib'
def setup_keywords(dist):
"""Create libcarefree_objects data file lists
and add to setup keywords.
"""
import zcons
PYTHON_SHORT_VERSION = '%i%i' % tuple(sys.version_info[:2])
LIB_PACKAGE = 'libcfo'
LIB_PACKAGE_DIR = '.'
# Also gets the lib/header files if building an egg
LIB_PACKAGE_DATA = ['VERSION', 'requirements.txt']
# Gets the lib/header files for installing to sys.prefix
# if doing normal build/install
LIB_DATA_FILES = []
LIB_PACKAGES = [LIB_PACKAGE]
try:
import libarray_ptr
except ImportError:
pass
else:
os.environ['CPPFLAGS'] = '-I%s %s' % (
str(libarray_ptr.INCLUDE_PATH), os.environ.get('CPPFLAGS', ''))
# Process the header templates and compile the libs
env = dict(os.environ, PYTHONPATH=os.pathsep.join(sys.path))
# for cmd in [
# ## ['scons', '-c', 'SHARED=yes', 'STATIC=yes'],
# ['scons', 'DEBUG=yes', 'SHARED=yes', 'STATIC=yes', 'TESTS=yes'],
# ## 'PYTHON=%s' % sys.executable],
# ]:
# print(' '.join(cmd))
# if Popen(cmd, env=env).wait():
# sys.exit(1)
zcons.scons(env_update=env, stdout=sys.__stderr__,
DEBUG=True, SHARED=True, STATIC=True)
LIB_PACKAGE_DIR = Path(LIB_PACKAGE_DIR)
if 'install' in sys.argv:
PREFIX = Path(sys.prefix).abspath()
# Store sys.prefix location (where data_files are installed)
# as part of package_data.
# Can later be accessed with libcarefree_objects.PREFIX
with open('PREFIX', 'w') as f:
f.write(PREFIX)
LIB_PACKAGE_DATA.append('PREFIX')
INCLUDE_FILES = []
with Path('include'):
for dirpath, dirnames, filenames in os.walk('.'):
if filenames:
abspath = Path(dirpath).abspath()
INCLUDE_FILES.append((dirpath, [
abspath / fn for fn in filenames]))
LIB_FILES = []
with Path('lib'):
for suffix in [
'types',
'python-py%s' % PYTHON_SHORT_VERSION,
]:
LIB_FILES.extend(
Path('libcarefree-%s.%s' % (suffix, ext)
).abspath()
for ext in ('a', 'so'))
if 'install' in sys.argv:
# Install libs/headers as data_files to sys.prefix
for dirpath, filenames in INCLUDE_FILES:
LIB_DATA_FILES.append(
(PREFIX / 'include' / dirpath, filenames))
LIB_DATA_FILES.append((PREFIX / 'lib', LIB_FILES))
else:
# Install libs/headers as package_data
for dirpath, filepaths in INCLUDE_FILES:
for path in filepaths:
LIB_PACKAGE_DATA.append(LIB_PACKAGE_DIR.relpathto(path))
for path in LIB_FILES:
LIB_PACKAGE_DATA.append(LIB_PACKAGE_DIR.relpathto(path))
dist.package_dir[LIB_PACKAGE] = LIB_PACKAGE_DIR
dist.packages = list(dist.packages) + LIB_PACKAGES
if 'sdist' not in sys.argv:
dist.package_data = {
'cfo.jinja.macros': [
'cfo',
],
LIB_PACKAGE: LIB_PACKAGE_DATA,
}
dist.data_files = LIB_DATA_FILES