forked from cihologramas/pyoptools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
157 lines (139 loc) · 5.26 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
from setuptools import setup
from setuptools.extension import Extension
try:
from Cython.Build import cythonize
from Cython.Distutils import build_ext
except ImportError:
print("You don't seem to have Cython installed. Please get a")
print("copy from www.cython.org and install it")
sys.exit(1)
# Look for paths containing arrayobject.h
# Necessary for non-unix systems
def contains_arrayobject_h(path):
"""
Returns True if the python path string contains the arrayobject.h
include file where it is supposed to be.
"""
f = False
try:
_s = os.stat(os.path.join(path, 'numpy', 'core', 'include',
'numpy', 'arrayobject.h'))
f = True
except OSError:
pass
return f
# scan the directory for extension files, converting
# them to extension names in dotted notation
def scandir(dir_, files=[]):
for file in os.listdir(dir_):
if file =="venv": continue
path = os.path.join(dir_, file)
if os.path.isfile(path) and path.endswith(".pyx"):
files.append(path.replace(os.path.sep, ".")[2:-4])
elif os.path.isdir(path):
scandir(path, files)
return files
def findpackages(dir_, files=[]):
for file in os.listdir(dir_):
if file in ["build", "venv"]:
continue
path = os.path.join(dir_, file)
if os.path.isdir(path): # and path.endswith(".py"):
for file1 in os.listdir(path):
if file1 == "__init__.py":
files.append(path.replace(os.path.sep, ".")[2:])
findpackages(path, files)
return files
# generate an Extension object from its dotted name
def makeExtension(extName):
extPath = extName.replace(".", os.path.sep)+".pyx"
return Extension(
extName,
[extPath],
# adding the '.' to include_dirs is CRUCIAL!!
include_dirs=[".", include_numpy_array],
extra_compile_args=["-O3", "-Wall"],
# extra_link_args = ['-g'],
# libraries = ["dv",],
)
# Check the availability of arrayobject.h
valid_paths = list(filter(contains_arrayobject_h, sys.path))
if len(valid_paths) == 0:
print("No paths in the python path contain numpy/arrayobject.h")
sys.exit(0)
# The base path is by default the first python path with arrayobject.h in it.
include_numpy_array = valid_paths[0]
if len(valid_paths) > 1:
print("There are several valid include directories"
"containing numpy/arrayobject.h")
l = [('%d: %s' % (i+1, valid_paths[i])) for i in
range(0, len(valid_paths))]
s = -1
print('\n'.join(l))
# Prompt the user with a list of selections.
# Fix input for Python 3-3
try:
input = raw_input
except NameError:
pass
while not (s >= 1 and s <= len(valid_paths)):
try:
s = input('Selection [default=1]: ')
except EOFError:
s=1
print('Selection is',s)
continue
if s == '':
s = 1
else:
s = int(s)
include_numpy_array = valid_paths[s-1]
# Add the children directory path suffix to the base path.
include_numpy_array = os.path.join(include_numpy_array, 'numpy', 'core',
'include')
# Need to create a pyOpTools package
extNames = scandir("./")
# and build up the set of Extension objects
extensions = [makeExtension(name) for name in extNames]
setup(name="pyoptools",
version="0.1.1",
packages=findpackages("./"),
scripts=['ipyoptools'],
# The names from pipy are used, not the deb package names
#requires=['numpy',
# 'cython',
# 'PyOpenGl',
# 'ipython',
# 'scipy',
# 'six',
# ],
package_data={
#'pyoptools.raytrace.mat_lib': ['data/*.mat'],
'pyoptools.raytrace.mat_lib': ['data/glass/*','data/glass/*/*',
'data/glass/*/*/*', 'data/main*',
'data/main/*/*', 'data/aliases.cfg'],
'pyoptools.raytrace.library': ['Edmund/*.cmp','Thorlabs/*.cmp'],
},
author='Ricardo Amezquita Orozco',
author_email='[email protected]',
description='Optical ray tracing simulation system',
license='GPLv3',
url='https://github.com/cihologramas/pyoptools/',
download_url='https://github.com/cihologramas/pyoptools/archive/v0.1.1.zip',
ext_modules=cythonize(extensions),
cmdclass={'build_ext': build_ext},
# data_files=[("share/doc/pyoptools/examples/basic_course",
# ["examples/basic_course/00-Introducción.ipynb",
# "examples/basic_course/03-SimpleComponents.ipynb",
# "examples/basic_course/05-Autocollimator.ipynb",
# "examples/basic_course/01-IntroPython.ipynb",
# "examples/basic_course/04-PredefinedComponents.ipynb",
# "examples/basic_course/06-GeomWF.ipynb",
# "examples/basic_course/02-Surfaces.ipynb",
# "examples/basic_course/04-Simple RayTraces.ipynb",
# "examples/basic_course/07-SimpleEODs.ipynb"])]
)