forked from sdss/kaiju
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
135 lines (108 loc) · 3.96 KB
/
Copy pathsetup.py
File metadata and controls
135 lines (108 loc) · 3.96 KB
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
import os
import sys
import urllib.request
from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext as _build_ext
COORDIO_BASE = 'https://raw.githubusercontent.com/sdss/coordio/master/'
class getPybindInclude(object):
"""Helper class to determine the pybind11 include path
The purpose of this class is to postpone importing pybind11
until it is actually installed, so that the ``get_include()``
method can be invoked.
https://github.com/pybind/python_example/blob/master/setup.py
"""
def __init__(self, user=False):
self.user = user
def __str__(self):
import pybind11
return pybind11.get_include(self.user)
def getIncludes():
return [
'python/kaiju/include',
getPybindInclude(),
getPybindInclude(user=True),
]
def getVersion():
with open("python/kaiju/__version__.py", "r") as f:
lines = f.readlines()
for line in lines:
if line.startswith("__version__"):
v = line.split("=")[-1].strip().strip('"').strip("'")
return v
def getSources():
return [
'src/cKaiju.cpp',
'src/robot.cpp',
'src/robotGrid.cpp',
'src/utils.cpp',
'src/target.cpp',
'src/fiducial.cpp',
'src/gfa.cpp',
'src/conv.cpp'
]
extra_compile_args = ["--std=c++11", "-fPIC", "-v", "-O3"]
extra_link_args = []
if sys.platform == 'darwin':
extra_compile_args += ['-stdlib=libc++', '-mmacosx-version-min=10.9']
extra_link_args = ["-v", '-mmacosx-version-min=10.9', '-L.']
from distutils import sysconfig
vars = sysconfig.get_config_vars()
vars['LDSHARED'] = vars['LDSHARED'].replace('-bundle', '-dynamiclib')
extensions = [
Extension(
'kaiju.cKaiju',
include_dirs=getIncludes(),
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
sources=getSources())
]
# cKaiju relies on some funcitons defined in libcoordio in coordio. Since linking against
# that library directly is painful, we just download the latest files from GitHub
# and add them to cKaiju ...
class build_ext(_build_ext):
def run(self):
DIRNAME = os.path.dirname(__file__)
with urllib.request.urlopen(COORDIO_BASE + 'src/coordio/include/coordio.h') as r:
data = r.read()
with open(os.path.join(DIRNAME, 'python/kaiju/include/coordio.h'), 'wb') as f:
f.write(data)
with urllib.request.urlopen(COORDIO_BASE + 'cextern/conv.cpp') as r:
data = r.read()
with open(os.path.join(DIRNAME, 'src/conv.cpp'), 'wb') as f:
f.write(data)
super().run()
def runSetup(packages, requirements):
setup(
name="sdss-kaiju",
version=getVersion(),
license="BSD3",
author="Conor Sayres",
author_email="csayres@uw.edu",
description="Collision Avoidance for SDSS-V Positioners",
long_description=open('README.rst').read(),
packages=packages,
cmdclass={'build_ext': build_ext},
package_dir={'': 'python'},
package_data={'kaiju': ['python/kaiju/include/*']},
include_package_data=True,
url="https://github.com/sdss/kaiju",
keywords="astronomy software",
ext_modules=extensions,
install_requires=requirements,
setup_requires=[
"sdss-coordio>=1.2.1",
"pybind11>=2.2.4"
],
classifiers=[
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
]
)
requirementsFile = os.path.join(os.path.dirname(__file__), "requirements.txt")
requirements = [line.strip() for line in open(requirementsFile)]
packages = find_packages(where="python")
print("found packages", packages)
runSetup(packages, requirements)