-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup.py
136 lines (114 loc) · 4.41 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
import os
import re
import sys
try:
import setuptools
except ImportError:
pass
from distutils.core import setup, Extension
ext_modules = [
Extension("quicktions", ["src/quicktions.pyx"]),
]
try:
sys.argv.remove("--with-profile")
except ValueError:
enable_profiling = False
else:
enable_profiling = True
enable_coverage = os.environ.get("WITH_COVERAGE") == "1"
force_rebuild = os.environ.get("FORCE_REBUILD") == "1"
try:
sys.argv.remove("--with-cython")
except ValueError:
pass # legacy option
cythonize = None
try:
sys.argv.remove("--no-cython")
except ValueError:
try:
from Cython.Build import cythonize
from Cython import __version__ as cython_version
import Cython.Compiler.Options as cython_options
cython_options.annotate = True
except ImportError:
print("Cython not found, building without Cython")
cythonize = None
else:
print("Building with Cython %s" % cython_version)
compiler_directives = {}
if enable_profiling:
compiler_directives['profile'] = True
if enable_coverage:
compiler_directives['linetrace'] = True
ext_modules = cythonize(
ext_modules, compiler_directives=compiler_directives, force=force_rebuild)
# Fix compiler warning due to missing pragma-push in Cython 3.0.9.
for ext in ext_modules:
for source_file in ext.sources:
with open(source_file, 'rb') as f:
lines = f.readlines()
if b'Generated by Cython 3.0.9' not in lines[0]:
continue
modified = False
temp_file = source_file + ".tmp"
with open(temp_file, 'wb') as f:
last_was_push = False
for line in lines:
if b'#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"' in line and not last_was_push:
f.write(b"#pragma GCC diagnostic push\n")
modified = True
last_was_push = b'#pragma GCC diagnostic push' in line
f.write(line)
if modified:
print("Fixed Cython 3.0.9 generated source file " + source_file)
os.unlink(source_file)
os.rename(temp_file, source_file)
else:
os.unlink(temp_file)
if cythonize is None:
for ext_module in ext_modules:
ext_module.sources[:] = [m.replace('.pyx', '.c') for m in ext_module.sources]
elif enable_coverage:
for ext_module in ext_modules:
ext_module.extra_compile_args += [
"-DCYTHON_TRACE_NOGIL=1",
]
if sys.platform == "darwin":
try:
if int(os.environ.get("MACOSX_DEPLOYMENT_TARGET", "0").split(".", 1)[0]) >= 11:
if "-arch" not in os.environ.get("CFLAGS", ""):
os.environ["CFLAGS"] = os.environ.get("CFLAGS", "") + " -arch arm64 -arch x86_64"
os.environ["LDFLAGS"] = os.environ.get("LDFLAGS", "") + " -arch arm64 -arch x86_64"
except ValueError:
pass # probably cannot parse "MACOSX_DEPLOYMENT_TARGET"
with open('src/quicktions.pyx') as f:
version = re.search(r"__version__\s*=\s*'([^']+)'", f.read(2048)).group(1)
with open('README.rst') as f:
long_description = ''.join(f.readlines()[3:]).strip()
with open('CHANGES.rst') as f:
long_description += '\n\n' + f.read()
setup(
name="quicktions",
version=version,
description="Fast fractions data type for rational numbers. "
"Cythonized version of 'fractions.Fraction'.",
long_description=long_description,
author="Stefan Behnel",
author_email="[email protected]",
url="https://github.com/scoder/quicktions",
#bugtrack_url="https://github.com/scoder/quicktions/issues",
ext_modules=ext_modules,
package_dir={'': 'src'},
classifiers=[
"Development Status :: 6 - Mature",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Programming Language :: Cython",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Office/Business :: Financial",
"License :: OSI Approved :: Python Software Foundation License",
],
)