-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathsetup.py
136 lines (112 loc) · 5.12 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
from __future__ import print_function, division, absolute_import
import os
import sys
import subprocess
import numpy
from setuptools import setup, Extension, find_packages
from Cython.Build import cythonize
# Determine find_packages function to use depending on Python version
find_packages_func = find_packages
# If in Python 3.3 or later, load find_namespace_packages()
if sys.version_info >= (3, 3):
from setuptools import find_namespace_packages
find_packages_func = find_namespace_packages
kht_module = Extension("kht_module",
sources = ["Native/Hough/kht.cpp",
"Native/Hough/buffer_2d.cpp",
"Native/Hough/eigen.cpp",
"Native/Hough/linking.cpp",
"Native/Hough/peak_detection.cpp",
"Native/Hough/subdivision.cpp",
"Native/Hough/voting.cpp"],
include_dirs = ["Native/Hough/"],
extra_compile_args=["-O3", "-Wall"])
def isPackageInstalled(package_name):
"""Check if a package is installed."""
try:
print("Checking if {:s} is installed...".format(package_name))
subprocess.check_call([sys.executable, '-c', 'import {:s}'.format(package_name)])
print("{:s} is already installed.".format(package_name))
return True
except subprocess.CalledProcessError:
print("{:s} is not installed.".format(package_name))
return False
def attemptInstall(package):
"""Attempt to install a package using pip."""
try:
print("Attempting to install {:s}...".format(package))
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
print("Successfully installed {:s}.".format(package))
return True
except subprocess.CalledProcessError:
print("Failed to install {:s}.".format(package))
return False
# Check if TensorFlow is already installed
if not isPackageInstalled('tensorflow'):
# Attempt to install tflite-runtime
if not attemptInstall('tflite-runtime'):
# If tflite-runtime fails, install TensorFlow
attemptInstall('tensorflow')
# Read requirements file
with open('requirements.txt') as f:
requirements = f.read().splitlines()
# drop unsupported git refs for install_requires https://github.com/pypa/setuptools/issues/1052
for requirement in requirements:
if requirement.startswith("git+"):
requirements.remove(requirement)
### Add rawpy is running on Windows or Linux (not the Pi) ###
# Check if running on Windows
if 'win' in sys.platform and "darwin" not in sys.platform:
requirements.append("rawpy")
# Check if running on Linux
else:
# Check if running on the Pi
if 'arm' in os.uname()[4]:
print("Not installing rawpy because it is not available on the Pi...")
else:
requirements.append("rawpy")
# Cython modules which will be compiled on setup
cython_modules = [
Extension('RMS.Astrometry.CyFunctions', sources=['RMS/Astrometry/CyFunctions.pyx'], \
include_dirs=[numpy.get_include()]),
Extension('RMS.Routines.BinImageCy', sources=['RMS/Routines/BinImageCy.pyx'], \
include_dirs=[numpy.get_include()]),
Extension('RMS.Routines.DynamicFTPCompressionCy', sources=['RMS/Routines/DynamicFTPCompressionCy.pyx'], \
include_dirs=[numpy.get_include()]),
Extension('RMS.Routines.Grouping3Dcy', sources=['RMS/Routines/Grouping3Dcy.pyx'], \
include_dirs=[numpy.get_include()]),
Extension('RMS.Routines.MorphCy', sources=['RMS/Routines/MorphCy.pyx'], \
include_dirs=[numpy.get_include()]),
Extension('RMS.CompressionCy', sources=['RMS/CompressionCy.pyx'], \
include_dirs=[numpy.get_include()]),
Extension('Utils.SaturationTools', sources=['Utils/SaturationTools.pyx'], \
include_dirs=[numpy.get_include()])
]
# Get all data files
dir_path = os.path.split(os.path.abspath(__file__))[0]
catalog_files = [
os.path.join('Catalogs', file_name) for file_name in os.listdir(os.path.join(dir_path, 'Catalogs'))
]
share_files = [
os.path.join('share', file_name) for file_name in os.listdir(os.path.join(dir_path, 'share'))
if os.path.isfile(os.path.join(dir_path, 'share', file_name))
]
platepar_templates = [
os.path.join('share', 'platepar_templates', file_name)
for file_name in os.listdir(os.path.join(dir_path, 'share', 'platepar_templates'))
if os.path.isfile(os.path.join(dir_path, 'share', 'platepar_templates', file_name))
]
setup (name = "RMS",
version = "0.1",
description = "Raspberry Pi Meteor Station",
setup_requires=["numpy",
# Setuptools 18.0 properly handles Cython extensions.
'setuptools>=18.0',
'cython'],
install_requires=requirements,
data_files=[('Catalogs', catalog_files), ('share', share_files), ('share/platepar_templates', platepar_templates)],
ext_modules = [kht_module] + cythonize(cython_modules),
packages=find_packages_func(),
include_package_data=True,
include_dirs=[numpy.get_include()]
)