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