forked from cihologramas/pyoptools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
138 lines (123 loc) · 5.11 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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys, os, commands
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
try:
from Cython.Distutils import build_ext
except:
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 containig arrayobject.h
#Necessary for non-unix systems
def contains_arrayobject_h(path):
"""
Returns True iff 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):
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!="build":
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"
pxdPath = extName.replace(".", os.path.sep)+".pxd"
if os.path.isfile(pxdPath):
flist=[extPath,pxdPath]
else:
flist=[extPath]
return Extension(
extName,
[extPath],
include_dirs = [".",include_numpy_array], # adding the '.' to include_dirs is CRUCIAL!!
extra_compile_args = ["-O3", "-Wall"],
#extra_link_args = ['-g'],
#libraries = ["dv",],
)
#Check the availability of arrayobject.h
valid_paths = 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 xrange(0, len(valid_paths))]
s = -1
print string.join(l, '\n')
# Prompt the user with a list of selections.
while not (s >= 1 and s <= len(valid_paths)):
s = input('Selection [default=1]:' % s)
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.0.0",
packages=findpackages("./"),
scripts=['ipyoptools'],
#The names from pipy are used, not the deb package names
requires = ['numpy',
'cython',
'PyOpenGl',
'ipython',
'scipy',
],
package_data= {
'pyoptools.raytrace.mat_lib':['data/*.rtgl'],
'pyoptools.raytrace.library':['Edmund/*.cmp'],
},
author= 'Ricardo Amezquita Orozco',
author_email='ramezquitao@cihologramas.com',
description='Optical ray tracing simulation system',
license='BSD',
url='',
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"])]
)