[f2d6445] | 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 | """ |
---|
[22bb59b] | 10 | import sys |
---|
| 11 | import os |
---|
| 12 | from distutils.core import setup |
---|
| 13 | from distutils.core import Extension |
---|
[f2d6445] | 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 | |
---|
[aa61e49] | 28 | # Top package name |
---|
| 29 | #pck_top = "sansModeling" |
---|
[356c602] | 30 | pck_top = "sansrealspace_modeling" |
---|
[bf47f2d] | 31 | pck_dir = os.path.join("src","sans", "simulation") |
---|
[f2d6445] | 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 |
---|
[bf47f2d] | 41 | pck_dirs = {pck_top:pck_dir} |
---|
[f2d6445] | 42 | |
---|
| 43 | # List of modules to install, will be extende below |
---|
[aa61e49] | 44 | pck_list = [pck_top] |
---|
[f2d6445] | 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: |
---|
[bf47f2d] | 66 | temp_path = os.path.join(pck_dir, module, module) |
---|
[22bb59b] | 67 | pck_dirs["%s.%s" % (pck_top, module)] = temp_path |
---|
[aa61e49] | 68 | pck_list.append("%s.%s" % (pck_top, module)) |
---|
[f2d6445] | 69 | |
---|
[bf47f2d] | 70 | src_m = os.path.join(pck_dir, module, "%smodule" %(module)) |
---|
| 71 | src_l = os.path.join(pck_dir, module, "lib%s" % (module)) |
---|
[f2d6445] | 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 | |
---|
[bf47f2d] | 79 | for f in get_c_files(os.path.join(pck_dir, dep, "lib%s" % dep)): |
---|
[f2d6445] | 80 | index = f.rindex('.') |
---|
| 81 | if os.name=='nt': |
---|
| 82 | fo = f[:index]+'.obj' |
---|
| 83 | else: |
---|
| 84 | fo = f[:index]+'.o' |
---|
[bf47f2d] | 85 | libs[module].append("%s/%s" %(tempdir, fo)) |
---|
[f2d6445] | 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: |
---|
[aa61e49] | 94 | exts.append( Extension("%s.%s.%s" % (pck_top, module, module), |
---|
[f2d6445] | 95 | sources = file_list[module], |
---|
| 96 | extra_objects=libs[module], |
---|
| 97 | include_dirs=incl_dirs) ) |
---|
| 98 | |
---|
| 99 | setup( |
---|
[3bf406e9] | 100 | name="sansrealspace_modeling", |
---|
[f2d6445] | 101 | version = "0.2", |
---|
| 102 | description = "Python module for SANS simulation", |
---|
| 103 | author = "University of Tennessee", |
---|
| 104 | url = "http://danse.us/trac/sans", |
---|
| 105 | package_dir = pck_dirs, |
---|
| 106 | packages = pck_list, |
---|
| 107 | ext_modules = exts) |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | |
---|