/
setup.py
executable file
·161 lines (143 loc) · 5.94 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
# Monary - Copyright 2011-2014 David J. C. Beach
# Please see the included LICENSE.TXT and NOTICE.TXT for licensing information.
import os
import platform
import sys
import warnings
# Don't force people to install setuptools unless we have to.
try:
from setuptools import setup, Extension
except ImportError:
from ez_setup import use_setuptools
use_setuptools()
from setuptools import setup, Extension
# Set the default location of libmongoc and libbson.
# NOTE: Will only use the default if pkgconfig cannot find anything.
if platform.system() == "Windows":
mongoc_src = os.path.join("C:/", "Program Files", "libmongoc")
bson_src = os.path.join("C:/", "Program Files", "libbson")
libraries = ["bson-1.0", "mongoc-1.0"]
else:
mongoc_src = os.path.join("/usr", "local")
bson_src = os.path.join("/usr", "local")
# Libmongoc MUST be compiled with SSL and SASL.
libraries = ["bson-1.0", "crypto", "ssl", "sasl2", "mongoc-1.0"]
# Check if the user specified the location.
for s in range(len(sys.argv) - 1, -1, -1):
if sys.argv[s] == "--default-libmongoc":
mongoc_src = sys.argv[s + 1]
sys.argv.remove("--default-libmongoc")
sys.argv.remove(mongoc_src)
elif sys.argv[s] == "--default-libbson":
bson_src = sys.argv[s + 1]
sys.argv.remove("--default-libbson")
sys.argv.remove(bson_src)
settings = {
'export_symbols': ["monary_init",
"monary_cleanup",
"monary_connect",
"monary_disconnect",
"monary_use_collection",
"monary_destroy_collection",
"monary_alloc_column_data",
"monary_free_column_data",
"monary_set_column_item",
"monary_query_count",
"monary_init_query",
"monary_init_aggregate",
"monary_load_query",
"monary_close_query",
"monary_create_write_concern",
"monary_destroy_write_concern",
"monary_insert"],
'sources': [os.path.join("monary", "cmonary.c")],
'include_dirs': [os.path.join(mongoc_src, "include", "libmongoc-1.0"),
os.path.join(bson_src, "include", "libbson-1.0")],
'library_dirs': [os.path.join(mongoc_src, "lib"),
os.path.join(bson_src, "lib")],
'libraries': libraries
}
test_requires = []
test_suite = "test"
if sys.version_info[:2] == (2, 6):
test_requires.append("unittest2")
test_suite = "unittest2.collector"
DEBUG = False
VERSION = "0.4.0"
CFLAGS = ["-fPIC", "-O2"]
if not DEBUG:
CFLAGS.append("-DNDEBUG")
# Use pkg-config to find location of libbson and libmongoc.
try:
import pkgconfig
except ImportError:
# Set to default locations for libmongoc and libbson.
warnings.warn(("WARNING: the python package pkgconfig is not installed. "
"If you have pkg-config installed on your system, please "
"install the python's pkgconfig, e.g. \"pip install "
"pkgconfig\". Will use libmongoc=%s and libbson=%s instead."
% (mongoc_src, bson_src)))
else:
try:
# Use pkgconfig to find location of libmongoc or libbson.
if pkgconfig.exists("libmongoc-1.0"):
pkgcfg = pkgconfig.parse("libmongoc-1.0")
settings['include_dirs'] = list(pkgcfg['include_dirs'])
settings['library_dirs'] = list(pkgcfg['library_dirs'])
settings['libraries'] = list(pkgcfg['libraries'])
settings['define_macros'] = list(pkgcfg['define_macros'])
else:
warnings.warn(("WARNING: unable to find libmongoc-1.0 with "
"pkgconfig. Please check that PKG_CONFIG_PATH is "
"set to a path that can find the .pc files for "
"libbson and libmongoc. Will use libmongoc=%s and "
"libbson=%s instead." % (mongoc_src, bson_src)))
except EnvironmentError:
warnings.warn(("WARNING: the system tool pkg-config is not installed. "
"Will use libmongoc=%s and libbson=%s instead."
% (mongoc_src, bson_src)))
module = Extension('monary.libcmonary',
extra_compile_args=CFLAGS,
include_dirs=settings['include_dirs'],
libraries=settings['libraries'],
library_dirs=settings['library_dirs'],
export_symbols=settings['export_symbols'],
sources=settings['sources'])
# Get README info
try:
with open("README.rst") as fd:
readme_content = fd.read()
except:
readme_content = ""
setup(
name="Monary",
version=VERSION,
packages=["monary"],
install_requires=["pymongo", "numpy"],
setup_requires=["pymongo", "numpy"],
tests_require=test_requires,
package_dir={"monary": "monary"},
ext_modules=[module],
author="David J. C. Beach",
author_email="info@djcinnovations.com",
description="Monary performs high-performance column queries on MongoDB",
long_description=readme_content,
keywords="monary pymongo mongo mongodb numpy array",
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Operating System :: Unix",
"Operating System :: Microsoft :: Windows",
"Environment :: Console",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Database"
],
url="http://bitbucket.org/djcbeach/monary/",
test_suite=test_suite,
)