forked from kuralabs/flowbber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·464 lines (363 loc) · 12.1 KB
/
setup.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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017-2019 KuraLabs S.R.L
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""
Usage:
::
./setup.py sdist
./setup.py bdist_wheel
./setup.py bdist_wheel --binary
"""
from setuptools import setup
def check_directory():
"""
You must always change directory to the parent of this file before
executing the setup.py script. setuptools will fail reading files,
including and excluding files from the MANIFEST.in, defining the library
path, etc, if not.
"""
from os import getcwd
from os.path import dirname, abspath
return getcwd() == abspath(dirname(__file__))
assert check_directory(), 'Call setup.py from its parent directory'
#####################
# Utilities #
#####################
def read(filename):
"""
Read the content of a file.
:param str filename: The file to read.
:return: The content of the file.
:rtype: str
"""
with open(filename, mode='r', encoding='utf-8') as fd:
return fd.read()
def find_files(search_path, include=('*', ), exclude=('.*', )):
"""
Find files in a directory.
:param str search_path: Path to search for files.
:param tuple include: Patterns of files to include.
:param tuple exclude: Patterns of files to exclude.
:return: List of files found that matched the include collection but didn't
matched the exclude collection.
:rtype: list
"""
from os import walk
from fnmatch import fnmatch
from os.path import join, normpath
def included_in(fname, patterns):
return any(fnmatch(fname, pattern) for pattern in patterns)
files_collected = []
for root, folders, files in walk(search_path):
files_collected.extend(
normpath(join(root, fname)) for fname in files
if included_in(fname, include) and not included_in(fname, exclude)
)
files_collected.sort()
return files_collected
#####################
# Finders #
#####################
def find_version(filename):
"""
Find version of a package.
This will read and parse a Python module that has defined a __version__
variable. This function does not import the file.
::
setup(
...
version=find_version('lib/package/__init__.py'),
...
)
:param str filename: Path to a Python module with a __version__ variable.
:return: The version of the package.
:rtype: str
"""
import re
content = read(filename)
version_match = re.search(
r"^__version__ = ['\"]([^'\"]*)['\"]", content, re.M
)
if not version_match:
raise RuntimeError('Unable to find version string.')
version = version_match.group(1)
print('Version found:')
print(' {}'.format(version))
print('--')
return version
def find_scripts(search_path):
"""
Find scripts in a directory.
::
setup(
...
scripts=find_scripts('bin'),
...
)
:param str search_path: Path to search for scripts.
:return: Scripts found.
:rtype: list
"""
from os import access, X_OK
files_collected = find_files(search_path)
scripts = [fname for fname in files_collected if access(fname, X_OK)]
print('Scripts found:')
for script in scripts:
print(' {}'.format(script))
print('--')
return scripts
def find_requirements(filename):
"""
Finds PyPI compatible requirements in a pip requirements.txt file.
In this way requirements needs to be specified only in one, centralized
place:
::
setup(
...
install_requires=find_requirements('requirements.txt'),
...
)
Supports comments and non PyPI requirements (which are ignored).
:param str filename: Path to a requirements.txt file.
:return: List of requirements with version.
:rtype: list
"""
import string
content = read(filename)
requirements = []
ignored = []
for line in content.splitlines():
line = line.strip()
# Comments
if line.startswith('#') or not line:
continue
if line[:1] not in string.ascii_letters:
ignored.append(line)
continue
requirements.append(line)
print('Requirements found:')
for requirement in requirements:
print(' {}'.format(requirement))
print('--')
print('Requirements ignored:')
for requirement in ignored:
print(' {}'.format(requirement))
print('--')
return requirements
def find_data(package_path, data_path, **kwargs):
"""
Find data files in a package.
::
setup(
...
package_data={
'package': find_data(
'lib/package',
'data',
)
},
...
)
:param str package_path: Path to the root of the package.
:param str data_path: Relative path from the root of the package to the
data directory.
:param kwargs: Function supports inclusion and exclusion patterns as
specified in the find_files function.
:return: List of data files found.
:rtype: list
"""
from os.path import join, relpath
files_collected = find_files(join(package_path, data_path), **kwargs)
data_files = [relpath(fname, package_path) for fname in files_collected]
print('Data files found:')
for data_file in data_files:
print(' {}'.format(data_file))
print('--')
return data_files
def find_packages(lib_directory):
"""
Determine packaging options depending on the packaging mode and flags.
Supports:
- Source distribution.
- Pure Python wheels.
- Cythonized binary wheels.
::
setup(
...
**find_packages('lib')
)
:param str lib_directory: Path to the location of the packages.
:return: A dictionary with options for the setup() call depending on
calling parameters.
:rtype: dict
"""
from sys import argv
from os.path import join
if 'bdist_wheel' in argv and '--binary' in argv:
argv.remove('--binary')
from Cython.Build import cythonize
packaging = {
'ext_modules': cythonize(
join(lib_directory, '**/*.py')
),
}
print('Extension modules found:')
for ext_module in packaging['ext_modules']:
print(' {}'.format(ext_module.name))
print('--')
else:
from setuptools import find_packages as find_source_packages
packaging = {
'package_dir': {'': lib_directory},
'packages': find_source_packages(lib_directory),
}
print('Packages found (under {}):'.format(lib_directory))
for package in sorted(packaging['packages']):
print(' {}'.format(package))
print('--')
return packaging
setup(
name='flowbber',
version=find_version('lib/flowbber/__init__.py'),
# Scripts
scripts=find_scripts('bin'),
# Dependencies
install_requires=find_requirements('requirements.txt'),
# Optional dependencies
extras_require={
###########
# Sources #
###########
# CoberturaSource
'cobertura': ['pycobertura'],
# ConfigSource
'config': [],
# CPUSource
'cpu': ['psutil'],
# EnvSource
'env': [],
# GitSource
'git': [],
# GitHubSource
'github': ['pygithub'],
# JSONSource
'json': [],
# GTestSource
'gtest': [],
# LcovSource
'lcov': ['lcov_cobertura'],
# PyTestSource
'pytest': [],
# SLOCSource
'sloc': ['pygount'],
# SpeedSource
'speed': ['pyspeedtest'],
# TimestampSource
'timestamp': [],
# UserSource
'user': [],
# ValgrindMemcheckSource
'valgrind_memcheck': ['xmltodict'],
###############
# Aggregators #
###############
'expander': [],
'filter': [],
'lcov_merger': ['lcov_cobertura'],
###########
# Sinks #
###########
# ArchiveSink
'archive': [],
# InfluxDBSink
'influx': ['influxdb'],
# LcovHTMLSink
'lcov_html': [],
# MongoDBSink
'mongo': ['pymongo'],
# PrintSink
'print': [],
# TemplateSink
'template': ['jinja2'],
},
# Data files
package_data={
'flowbber': find_data(
'lib/flowbber',
'data',
)
},
# Metadata
author='KuraLabs S.R.L',
author_email='info@kuralabs.io',
description=(
'Flowbber is a generic tool and framework that allows to execute '
'custom pipelines for data gathering, publishing and analysis.'
),
long_description=read('README.rst'),
url='https://docs.kuralabs.io/flowbber/',
keywords='flowbber',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3',
],
# Sphinx autodoc cannot extract the documentation of zipped eggs with the
# ``.. autodata::`` directive, causing chaos in AutoAPI. This disables zip
# installation for correct AutoAPI generation.
zip_safe=False,
# Entry points
entry_points={
'flowbber_plugin_sources_1_0': [
'cobertura = flowbber.plugins.sources.cobertura:CoberturaSource',
'config = flowbber.plugins.sources.config:ConfigSource',
'cpu = flowbber.plugins.sources.cpu:CPUSource',
'env = flowbber.plugins.sources.env:EnvSource',
'git = flowbber.plugins.sources.git:GitSource',
'github = flowbber.plugins.sources.github:GitHubSource',
'json = flowbber.plugins.sources.json:JSONSource',
'gtest = flowbber.plugins.sources.gtest:GTestSource',
'lcov = flowbber.plugins.sources.lcov:LcovSource',
'pytest = flowbber.plugins.sources.pytest:PytestSource',
'sloc = flowbber.plugins.sources.sloc:SLOCSource',
'speed = flowbber.plugins.sources.speed:SpeedSource',
'timestamp = flowbber.plugins.sources.timestamp:TimestampSource',
'user = flowbber.plugins.sources.user:UserSource',
'valgrind_memcheck = flowbber.plugins.sources.valgrind.memcheck:ValgrindMemcheckSource', # noqa
'valgrind_helgrind = flowbber.plugins.sources.valgrind.helgrind:ValgrindHelgrindSource', # noqa
'valgrind_drd = flowbber.plugins.sources.valgrind.drd:ValgrindDrdSource', # noqa
],
'flowbber_plugin_aggregators_1_0': [
'expander = flowbber.plugins.aggregators.expander:ExpanderAggregator', # noqa
'filter = flowbber.plugins.aggregators.filter:FilterAggregator',
'lcov_merger = flowbber.plugins.aggregators.lcov_merger:LcovMergerAggregator', # noqa
],
'flowbber_plugin_sinks_1_0': [
'archive = flowbber.plugins.sinks.archive:ArchiveSink',
'influxdb = flowbber.plugins.sinks.influxdb:InfluxDBSink',
'lcov_html = flowbber.plugins.sinks.lcov_html:LcovHTMLSink',
'mongodb = flowbber.plugins.sinks.mongodb:MongoDBSink',
'print = flowbber.plugins.sinks.print:PrintSink',
'template = flowbber.plugins.sinks.template:TemplateSink',
]
},
# Multiple packaging options
**find_packages('lib')
)