-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup.py
119 lines (96 loc) · 3.21 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
# -*- coding: utf-8 -*-
"""
Installation script for the freeDOM project
"""
from __future__ import absolute_import
from pkg_resources import DistributionNotFound, get_distribution
from setuptools import setup, Extension, find_packages
from ctypes.util import find_library
import os
def get_dist(pkgname):
try:
return get_distribution(pkgname)
except DistributionNotFound:
return None
# the bare minimum required to run an LLH client
install_requires = [
"scipy",
"numpy",
"pyzmq",
"spherical_opt @ git+https://github.com/philippeller/spherical_opt.git",
]
# the full installation
full_requires = [
"matplotlib>=2.0",
"tensorflow>=2.1.0",
"sklearn",
"pyzmq>=19.0.1",
"pandas",
]
# If tensorflow-gpu is installed, use that
if get_dist("tensorflow") is None and get_dist("tensorflow-gpu") is not None:
full_requires = [
pkg.replace("tensorflow", "tensorflow-gpu") for pkg in full_requires
]
extras_require = {"full": full_requires}
# handle cython extension
# adapted from https://stackoverflow.com/questions/2379898/make-distutils-look-for-numpy-header-files-in-the-correct-place
try:
from Cython.Distutils import build_ext
except:
# If we couldn't import Cython, use the normal setuptools
# and look for a pre-compiled .c file instead of a .pyx file
from setuptools.command.build_ext import build_ext
ext = ".c"
else:
# If we successfully imported Cython, look for a .pyx file
ext = ".pyx"
zmq_lib_path = None
extra_link_args = []
zmq_lib = find_library("zmq")
if zmq_lib is not None:
zmq_lib_path = os.path.dirname(zmq_lib)
zmq_lib = os.path.basename(zmq_lib)
extra_link_args = [f"-l:{zmq_lib}"]
extensions = [
Extension(
"freedom.llh_service.llh_cython",
["freedom/llh_service/llh_cython" + ext],
extra_link_args=extra_link_args,
optional=True,
)
]
class CustomBuildExtCommand(build_ext):
"""build_ext command for use when numpy headers are needed."""
def run(self):
# Import numpy here, only when headers are needed
import numpy
import zmq
# Add numpy/zmq headers to include_dirs
self.include_dirs.append(numpy.get_include())
self.include_dirs.extend(zmq.get_includes())
if zmq_lib_path is not None and zmq_lib_path != "":
self.library_dirs.append(zmq_lib_path)
# Call original build_ext command
build_ext.run(self)
setup(
name="freedom",
description=(
"approximate likelihood reconstruction for arbitrary detector geometries"
),
author="Philipp Eller et al.",
author_email="[email protected]",
url="https://github.com/philippeller/freeDOM",
license="Apache 2.0",
version="0.1",
python_requires=">=3.6",
setup_requires=["pip>=1.8", "setuptools>18.5", "numpy>=1.11", "pyzmq>=19.0.1",],
install_requires=install_requires,
extras_require=extras_require,
packages=find_packages(),
package_data={"freedom.resources": ["*.npy", "*.csv", "*.pkl", "*.hdf5"],},
zip_safe=False,
cmdclass={"build_ext": CustomBuildExtCommand},
ext_modules=extensions,
entry_points={"console_scripts": ["freedom_crs_reco = freedom.reco.crs_reco:main"]},
)