forked from mongodb/bson-numpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
157 lines (126 loc) · 4.96 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
import glob
import os
import subprocess
import sys
# Suppress warnings during shutdown, http://bugs.python.org/issue15881
try:
import multiprocessing
except ImportError:
pass
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as _build_ext
# Single source the version.
version_file = os.path.realpath(os.path.join(
os.path.dirname(__file__), 'bsonnumpy', 'version.py'))
version = {}
with open(version_file) as fp:
exec(fp.read(), version)
try:
from sphinx.setup_command import BuildDoc
from sphinx.cmd import build as sphinxbuild
HAVE_SPHINX = True
except Exception:
HAVE_SPHINX = False
# Hack that ensures NumPy is installed prior to the build commencing.
# See http://stackoverflow.com/questions/19919905 for details.
class build_ext(_build_ext):
def finalize_options(self):
_build_ext.finalize_options(self)
try:
# Prevent numpy from thinking it is still in its setup process:
__builtins__.__NUMPY_SETUP__ = False
except Exception as exc:
print("Warning: %s" % exc)
import numpy
self.include_dirs.append(numpy.get_include())
CMDCLASS = {'build_ext': build_ext}
# Enables building docs and running doctests from setup.py
if HAVE_SPHINX:
class build_sphinx(BuildDoc):
description = "generate or test documentation"
user_options = [("test", "t",
"run doctests instead of generating documentation")]
boolean_options = ["test"]
def initialize_options(self):
self.test = False
super().initialize_options()
def run(self):
# Run in-place build before Sphinx doc build.
ret = subprocess.call(
[sys.executable, sys.argv[0], 'build_ext', '-i'])
if ret != 0:
raise RuntimeError("Building BSON-Numpy failed!")
if not HAVE_SPHINX:
raise RuntimeError("You must install Sphinx to build or test "
"the documentation.")
if self.test:
path = os.path.join(
os.path.abspath('.'), "doc", "_build", "doctest")
mode = "doctest"
else:
path = os.path.join(
os.path.abspath('.'), "doc", "_build", version)
mode = "html"
try:
os.makedirs(path)
except:
pass
sphinx_args = ["-E", "-b", mode, "doc", path]
status = sphinxbuild.main(sphinx_args)
if status:
raise RuntimeError("Documentation step '%s' failed" % (mode,))
msg = "\nDocumentation step '{}' performed, results here:\n {}\n"
sys.stdout.write(msg.format(mode, path))
CMDCLASS["doc"] = build_sphinx
def setup_package():
with open('README.rst') as f:
readme_content = f.read()
build_requires = ["numpy>=1.17.0"]
tests_require = build_requires + ["pymongo>=3.9.0,<4"]
install_requires = build_requires + ["pymongo>=3.6.0,<4"]
libraries = []
if sys.platform == "win32":
libraries.append("ws2_32")
elif sys.platform != "darwin":
# librt may be needed for clock_gettime()
libraries.append("rt")
setup(
name='BSON-NumPy',
version=version['__version__'],
description='Module for converting directly from BSON to NumPy '
'ndarrays',
long_description=readme_content,
author='Anna Herlihy',
author_email='[email protected]',
url='https://github.com/mongodb/bson-numpy',
keywords=["mongo", "mongodb", "pymongo", "numpy", "bson"],
license="Apache License, Version 2.0",
python_requires=">=3.5",
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Database"],
setup_requires=build_requires,
ext_modules=[
Extension(
'bsonnumpy._cbsonnumpy',
sources=(glob.glob("bsonnumpy/*.c") +
glob.glob("bsonnumpy/*/*.c")),
include_dirs=["bsonnumpy", "bsonnumpy/bson"],
define_macros=[("BSON_COMPILATION", 1)],
libraries=libraries)],
install_requires=install_requires,
test_suite="test",
tests_require=tests_require,
cmdclass=CMDCLASS,
packages=["bsonnumpy"])
if __name__ == '__main__':
setup_package()