-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup.py
109 lines (83 loc) · 2.98 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
import io
import os
import re
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as _build_ext
try:
from Cython.Build import cythonize
USE_CYTHON = True
except ImportError:
USE_CYTHON = False
ext = ".pyx" if USE_CYTHON else ".cpp"
def find_boost(hint=None, verbose=True):
""" Find the boost include directory,
returns ``None`` if not found.
This is based upon the version in https://github.com/dfm/transit/
Copyright (c) 2014 Daniel Foreman-Mackey
which is licenced under the MIT licence.
"""
search_dirs = [] if hint is None else hint
if "BOOST_DIR" in os.environ:
search_dirs.append(os.path.join(os.environ["BOOST_DIR"], "include"))
if "CONDA_PREFIX" in os.environ:
search_dirs.append(os.path.join(os.environ["CONDA_PREFIX"], "include"))
search_dirs += [
"/usr/include",
"/usr/local/include",
"/usr/local/homebrew/include",
"/opt/local/include",
"/data/sljg2/software/boost/include",
]
for d in search_dirs:
path = os.path.join(d, "boost", "geometry", "index", "rtree.hpp")
if os.path.exists(path):
vf = os.path.join(d, "boost", "version.hpp")
src = open(vf, "r").read()
v = re.findall('#define BOOST_LIB_VERSION "(.+)"', src)
if not len(v):
continue
v = v[0]
if verbose:
print("Found Boost version {0} in: {1}".format(v, d))
return d
return None
class build_ext(_build_ext):
def build_extension(self, ext):
dirs = ext.include_dirs + self.compiler.include_dirs
boost_include = find_boost(hint=dirs)
if boost_include is None:
raise RuntimeError("Boost not found, see the README for possible solutions")
ext.include_dirs.append(boost_include)
import numpy as np
ext.include_dirs.append(np.get_include())
_build_ext.build_extension(self, ext)
# read the contents of your README file
this_directory = os.path.abspath(os.path.dirname(__file__))
with io.open(os.path.join(this_directory, "README.md"), encoding="utf-8") as f:
long_description = f.read()
extensions = [
Extension(
"pyfof",
sources=["pyfof/pyfof" + ext, "pyfof/fof.cc", "pyfof/fof_brute.cc"],
extra_compile_args=["-std=c++11", "-Wno-return-type"],
language="c++",
)
]
if USE_CYTHON:
extensions = cythonize(extensions)
setup(
name="pyfof",
version="0.2-dev",
description="Friends-of-friends cluster finding in python",
author="Simon Gibbons",
author_email="[email protected]",
url="https://github.com/simongibbons/pyfof",
license="MIT",
keywords=["clustering", "friends-of-friends"],
install_requires=["numpy"],
setup_requires=["numpy", "cython"],
cmdclass={"build_ext": build_ext},
ext_modules=extensions,
long_description=long_description,
long_description_content_type="text/markdown",
)