1 | """ |
---|
2 | Installation script for SANS models |
---|
3 | |
---|
4 | - To compile and install: |
---|
5 | python setup.py install |
---|
6 | - To create distribution: |
---|
7 | python setup.py bdist_wininst |
---|
8 | |
---|
9 | """ |
---|
10 | import sys, os |
---|
11 | from distutils.core import setup, Extension |
---|
12 | from distutils import util |
---|
13 | from distutils import sysconfig |
---|
14 | |
---|
15 | def get_c_files(path): |
---|
16 | """ |
---|
17 | Utility function to return all files |
---|
18 | to be compiled in a directory |
---|
19 | """ |
---|
20 | clist = [] |
---|
21 | for file in os.listdir(path): |
---|
22 | if file.endswith(".cc") or file.endswith(".c"): |
---|
23 | clist.append("%s/%s" % (path, file)) |
---|
24 | return clist |
---|
25 | |
---|
26 | # The temp directory that the compiled files will be put in |
---|
27 | tempdir = "build/temp."+util.get_platform()+'-'+sysconfig.get_python_version() |
---|
28 | if os.name=='nt': |
---|
29 | tempdir += "/Release" |
---|
30 | |
---|
31 | # List of sub modules |
---|
32 | mod_list = ["iqPy", "geoshapespy", "pointsmodelpy", "analmodelpy"] |
---|
33 | |
---|
34 | # Define package directors, will be extended below |
---|
35 | pck_dirs = {"sansModeling":"."} |
---|
36 | |
---|
37 | # List of modules to install, will be extende below |
---|
38 | pck_list = ["sansModeling"] |
---|
39 | |
---|
40 | # List of python extensions, will be extended below |
---|
41 | exts = [] |
---|
42 | |
---|
43 | # List of include dirs, will be extended below |
---|
44 | incl_dirs = ["iqPy/libiqPy/tnt"] |
---|
45 | |
---|
46 | # List of files to compile, per module, will be extended below |
---|
47 | file_list = {} |
---|
48 | |
---|
49 | # List of dependencies |
---|
50 | deps = {} |
---|
51 | deps["iqPy"] = [] |
---|
52 | deps["geoshapespy"] = ["iqPy"] |
---|
53 | deps["analmodelpy"] = ["iqPy", "geoshapespy"] |
---|
54 | deps["pointsmodelpy"] = ["iqPy", "geoshapespy"] |
---|
55 | |
---|
56 | # List of extra objects to link with, per module, will be extended below |
---|
57 | libs = {} |
---|
58 | |
---|
59 | for module in mod_list: |
---|
60 | pck_dirs["sansModeling.%s" % module] = "%s/%s" % (module, module) |
---|
61 | pck_list.append("sansModeling.%s" % module) |
---|
62 | |
---|
63 | src_m = "%s/%smodule" % (module, module) |
---|
64 | src_l = "%s/lib%s" % (module, module) |
---|
65 | |
---|
66 | files = get_c_files(src_m) |
---|
67 | list_lib = get_c_files(src_l) |
---|
68 | |
---|
69 | libs[module] = [] |
---|
70 | for dep in deps[module]: |
---|
71 | |
---|
72 | for f in get_c_files("%s/lib%s" % (dep, dep)): |
---|
73 | index = f.rindex('.') |
---|
74 | if os.name=='nt': |
---|
75 | fo = f[:index]+'.obj' |
---|
76 | else: |
---|
77 | fo = f[:index]+'.o' |
---|
78 | libs[module].append("%s/%s" %(tempdir,fo)) |
---|
79 | |
---|
80 | files.extend(list_lib) |
---|
81 | file_list[module] = files |
---|
82 | |
---|
83 | incl_dirs.append(src_m) |
---|
84 | incl_dirs.append(src_l) |
---|
85 | |
---|
86 | for module in mod_list: |
---|
87 | exts.append( Extension("sansModeling.%s.%s" % (module, module), |
---|
88 | sources = file_list[module], |
---|
89 | extra_objects=libs[module], |
---|
90 | include_dirs=incl_dirs) ) |
---|
91 | |
---|
92 | setup( |
---|
93 | name="realspacesimulation", |
---|
94 | version = "0.2", |
---|
95 | description = "Python module for SANS simulation", |
---|
96 | author = "University of Tennessee", |
---|
97 | url = "http://danse.us/trac/sans", |
---|
98 | |
---|
99 | package_dir = pck_dirs, |
---|
100 | packages = pck_list, |
---|
101 | |
---|
102 | ext_modules = exts) |
---|
103 | |
---|
104 | |
---|
105 | |
---|