-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
setup.py
110 lines (87 loc) · 2.93 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
import sys
import os
import re
from setuptools import setup, Extension
with open('fastrlock/__init__.py') as f:
VERSION = re.search(
r'^__version__ \s* = \s* ["\'] ([0-9ab.]+) ["\']',
f.read(), re.MULTILINE|re.VERBOSE).group(1)
BASEDIR = os.path.dirname(__file__)
PKGNAME = 'fastrlock'
PKGDIR = os.path.join(BASEDIR, PKGNAME)
MODULES = [filename[:-4] for filename in os.listdir(PKGDIR)
if filename.endswith('.pyx')]
def has_option(name):
if name in sys.argv[1:]:
sys.argv.remove(name)
return True
return False
ext_args = {
'define_macros': [('CYTHON_CLINE_IN_TRACEBACK', '1')],
}
if has_option('--without-assert'):
ext_args['define_macros'].append(('CYTHON_WITHOUT_ASSERTIONS', None))
use_cython = has_option('--with-cython')
if not use_cython:
if not all(os.path.isfile(os.path.join(PKGDIR, module_name+'.c'))
for module_name in MODULES):
print("NOTE: generated sources not available, need Cython to build")
use_cython = True
cythonize = None
if use_cython:
try:
from Cython.Build import cythonize
import Cython.Compiler.Version
print("building with Cython " + Cython.Compiler.Version.version)
source_extension = ".pyx"
except ImportError:
print("WARNING: trying to build with Cython, but it is not installed")
cythonize = None
source_extension = ".c"
else:
print("building without Cython")
source_extension = ".c"
ext_modules = [
Extension(
'%s.%s' % (PKGNAME, module_name),
sources=[os.path.join(PKGNAME, module_name+source_extension)],
**ext_args)
for module_name in MODULES]
if cythonize is not None:
ext_modules = cythonize(ext_modules)
def read_file(filename):
f = open(os.path.join(BASEDIR, filename))
try:
return f.read()
finally:
f.close()
long_description = '\n\n'.join([
read_file(text_file)
for text_file in ['README.rst', 'CHANGES.rst']])
setup(
name="fastrlock",
version=VERSION,
author="Stefan Behnel",
author_email="stefan_ml@behnel.de",
url="https://github.com/scoder/fastrlock",
license='MIT style',
description="Fast, re-entrant optimistic lock implemented in Cython",
long_description=long_description,
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'License :: OSI Approved :: MIT License',
'Programming Language :: Cython',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Operating System :: OS Independent',
'Topic :: Software Development',
],
packages=[PKGNAME],
package_data={PKGNAME: ['*.pxd', '*.pxi']},
ext_modules=ext_modules,
zip_safe=False,
# support 'test' target if setuptools/distribute is available
test_suite='fastrlock.tests.suite',
)