-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·241 lines (219 loc) · 8.08 KB
/
setup.py
File metadata and controls
executable file
·241 lines (219 loc) · 8.08 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# Copyright (C) 2004-2012 J. David Ibáñez <jdavid.ibp@gmail.com>
# Copyright (C) 2008 David Versmisse <versmisse@lil.univ-littoral.fr>
# Copyright (C) 2009 Hervé Cauwelier <herve@oursours.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from os.path import join as join_path
from subprocess import Popen, PIPE
from sys import stderr
# Requirements
from setuptools import setup
from setuptools import Extension
def get_pipe(command, cwd=None):
"""Wrapper around 'subprocess.Popen'
"""
popen = Popen(command, stdout=PIPE, stderr=PIPE, cwd=cwd)
stdoutdata, stderrdata = popen.communicate()
if popen.returncode != 0:
raise OSError(popen.returncode, stderrdata)
return stdoutdata
def get_compile_flags(command):
include_dirs = []
extra_compile_args = []
library_dirs = []
libraries = []
if isinstance(command, str):
command = command.split()
data = get_pipe(command)
for line in data.splitlines():
for token in line.split():
flag, value = token[:2].decode("utf-8"), token[2:].decode("utf-8")
if flag == '-I':
include_dirs.append(value)
elif flag == '-f':
extra_compile_args.append(token)
elif flag == '-L':
library_dirs.append(value)
elif flag == '-l':
libraries.append(value)
return {'include_dirs': include_dirs,
'extra_compile_args': extra_compile_args,
'library_dirs': library_dirs,
'libraries': libraries}
def generate_mo_files(po_file_names):
"""
Generate mo files from po files located on /itools/locale/
:param po_file_names: An array of po files location
:return: An array of mo files location
"""
mo_files = []
for po_file in po_file_names:
# Compute mo file name
mo_file = po_file.replace('.po', '.mo')
# Generate mo file
try:
Popen(['msgfmt', po_file, '-o', mo_file])
except OSError:
# Check msgfmt is properly installed
print("[ERROR] 'msgfmt' not found, aborting...", file=stderr)
return []
mo_files.append(mo_file)
return mo_files
if __name__ == '__main__':
itools_is_available = False
try:
# TODO FIXME Try Except hide import errors with Python 3
from itools.core import get_abspath
from itools.pkg.utils import setup as itools_setup
itools_is_available = True
print('[OK] itools is available')
except ImportError:
print('[Warning] itools is not available')
ext_modules = []
filenames = [x.strip() for x in open('MANIFEST').readlines()]
if not itools_is_available:
# In case itools is not yet install, build won't work
# thus we need to make sure mo files will be generated
po_files = [x for x in filenames if x.endswith('.po') and not x.startswith('docs/')]
# Generate mo files
mo_files = generate_mo_files(po_files)
# Append mo_files to filenames
filenames.extend(mo_files)
# Check whether pkg-config is installed
try:
get_pipe(['pkg-config', '--version'])
except OSError:
print("[ERROR] 'pkg-config' not found, aborting...", file=stderr)
raise
# XML Parser
try:
flags = get_compile_flags('pkg-config --cflags --libs glib-2.0')
except OSError:
print("[ERROR] Glib 2.0 library or headers not found, aborting...", file=stderr)
raise
else:
sources = [
'itools/xml/parser.c', 'itools/xml/doctype.c', 'itools/xml/arp.c',
'itools/xml/pyparser.c']
extension = Extension('itools.xml.parser', sources=sources, **flags)
ext_modules.append(extension)
print('[INFO] itools.xml.parser will be built')
# DOC indexation
try:
flags = get_compile_flags('wv2-config --cflags --libs')
except OSError:
print("[WARNING] wv2 not found, DOC indexation won't work", file=stderr)
else:
sources = ['itools/office/doctotext.cc']
extension = Extension('itools.office.doctotext', sources, **flags)
ext_modules.append(extension)
print('[INFO] itools.office.doctotext will be built')
# Ok
if itools_is_available:
itools_setup(get_abspath(''), ext_modules=ext_modules)
exit(0)
# Ok
description = """The itools library offers a collection of packages covering a wide
range of capabilities. Including support for many file formats (XML,
CSV, HTML, etc.), a virtual file system (itools.fs), the simple
template language (STL), an index and search engine, and much more."""
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Programming Language :: Python',
'Topic :: Internet',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Software Development',
'Topic :: Software Development :: Internationalization',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Software Development :: Localization',
'Topic :: Text Processing',
'Topic :: Text Processing :: Markup',
'Topic :: Text Processing :: Markup :: XML"',
]
packages = [
"itools",
"itools.core",
"itools.csv",
"itools.database",
"itools.database.backends",
"itools.datatypes",
"itools.fs",
"itools.gettext",
"itools.handlers",
"itools.html",
"itools.i18n",
"itools.ical",
"itools.loop",
"itools.odf",
"itools.office",
"itools.pdf",
"itools.pkg",
"itools.python",
"itools.relaxng",
"itools.rss",
"itools.srx",
"itools.stl",
"itools.tmx",
"itools.uri",
"itools.validators",
"itools.web",
"itools.workflow",
"itools.xliff",
"itools.xml",
"itools.xmlfile"]
scripts = [
"scripts/idb-inspect.py",
"scripts/igettext-build.py",
"scripts/igettext-extract.py",
"scripts/igettext-merge.py",
"scripts/ipkg-build.py",
"scripts/ipkg-docs.py",
"scripts/ipkg-quality.py",
"scripts/ipkg-update-locale.py"]
with open('requirements.txt', 'r') as f:
install_requires = [line.strip() for line in f if line.strip() and not line.startswith('#')]
# The data files
package_data = {'itools': []}
filenames = [ x for x in filenames if not x.endswith('.py') ]
for line in filenames:
if not line.startswith('itools/'):
continue
path = line.split('/')
subpackage = f'itools.{path[1]}'
if subpackage in packages:
files = package_data.setdefault(subpackage, [])
files.append(join_path(*path[2:]))
else:
package_data['itools'].append(join_path(*path[1:]))
setup(name="itools",
version="0.80.4",
# Metadata
author="J. David Ibáñez",
author_email="jdavid.ibp@gmail.com",
license="GNU General Public License (GPL)",
url="http://www.hforge.org/itools",
description=description,
long_description="",
classifiers=classifiers,
install_requires=install_requires,
# Packages
packages=packages,
package_data=package_data,
# Scripts
scripts=scripts,
# C extensions
ext_modules=ext_modules)