[ae3ce4e] | 1 | """ |
---|
| 2 | Installation script for SANS models |
---|
| 3 | """ |
---|
[d7a2531] | 4 | |
---|
[f88624d] | 5 | import sys |
---|
[5c77050] | 6 | |
---|
[f88624d] | 7 | import os |
---|
[0b082f3] | 8 | import platform |
---|
[b72b595] | 9 | from numpy.distutils.misc_util import get_numpy_include_dirs |
---|
[6c13861] | 10 | numpy_incl_path = os.path.join(get_numpy_include_dirs()[0], "numpy") |
---|
[0abf7bf] | 11 | |
---|
[ae3ce4e] | 12 | # Then build and install the modules |
---|
[87615a48] | 13 | from distutils.core import Extension, setup |
---|
[13f00a0] | 14 | from distutils.command.build_ext import build_ext |
---|
| 15 | |
---|
| 16 | # Options to enable OpenMP |
---|
[5c77050] | 17 | if sys.argv[-1] == "-nomp": |
---|
[8b8a03f] | 18 | # Disable OpenMP |
---|
| 19 | copt = {} |
---|
| 20 | lopt = {} |
---|
| 21 | else: |
---|
| 22 | print "openmp ENABLED" |
---|
| 23 | copt = {'msvc': ['/openmp'], |
---|
| 24 | 'mingw32' : ['-fopenmp'], |
---|
| 25 | 'unix' : ['-fopenmp']} |
---|
| 26 | lopt = {'msvc': ['/MANIFEST'], |
---|
| 27 | 'mingw32' : ['-fopenmp'], |
---|
| 28 | 'unix' : ['-lgomp']} |
---|
[13f00a0] | 29 | |
---|
| 30 | class build_ext_subclass( build_ext ): |
---|
| 31 | def build_extensions(self): |
---|
| 32 | # Get 64-bitness |
---|
[d9673d7a] | 33 | if sys.version_info >= (2, 6): |
---|
| 34 | is_64bits = sys.maxsize > 2**32 |
---|
| 35 | else: |
---|
| 36 | # 'sys.maxsize' and 64bit: Not supported for python2.5 |
---|
| 37 | is_64bits = False |
---|
[13f00a0] | 38 | c = self.compiler.compiler_type |
---|
[8b8a03f] | 39 | |
---|
[13f00a0] | 40 | print "Compiling with %s (64bit=%s)" % (c, str(is_64bits)) |
---|
| 41 | if not (sys.platform=='darwin' and not is_64bits): |
---|
| 42 | if copt.has_key(c): |
---|
| 43 | for e in self.extensions: |
---|
| 44 | e.extra_compile_args = copt[ c ] |
---|
| 45 | if lopt.has_key(c): |
---|
| 46 | for e in self.extensions: |
---|
| 47 | e.extra_link_args = lopt[ c ] |
---|
| 48 | |
---|
| 49 | build_ext.build_extensions(self) |
---|
[ae3ce4e] | 50 | |
---|
| 51 | # Build the module name |
---|
[0a51f0d8] | 52 | srcdir = os.path.join("src", "sans", "models", "c_extensions") |
---|
| 53 | igordir = os.path.join("src","sans", "models", "libigor") |
---|
| 54 | c_model_dir = os.path.join("src", "sans", "models", "c_models") |
---|
| 55 | smear_dir = os.path.join("src", "sans", "models", "c_smearer") |
---|
[ae3ce4e] | 56 | print "Installing SANS models" |
---|
| 57 | |
---|
| 58 | |
---|
[0a51f0d8] | 59 | IGNORED_FILES = ["a.exe", |
---|
| 60 | "__init__.py" |
---|
| 61 | ".svn", |
---|
| 62 | "lineparser.py", |
---|
| 63 | "run.py", |
---|
| 64 | "CGaussian.cpp", |
---|
| 65 | "CLogNormal.cpp", |
---|
| 66 | "CLorentzian.cpp", |
---|
| 67 | "CSchulz.cpp", |
---|
| 68 | "WrapperGenerator.py", |
---|
[f9303b6] | 69 | "wrapping.py" |
---|
| 70 | ] |
---|
| 71 | if not os.name=='nt': |
---|
| 72 | IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"]) |
---|
| 73 | |
---|
[0f282a5] | 74 | EXTENSIONS = [".c", ".cpp"] |
---|
[0a51f0d8] | 75 | |
---|
| 76 | def append_file(file_list, dir_path): |
---|
| 77 | """ |
---|
| 78 | Add sources file to sources |
---|
| 79 | """ |
---|
| 80 | for f in os.listdir(dir_path): |
---|
| 81 | if os.path.isfile(os.path.join(dir_path, f)): |
---|
| 82 | _, ext = os.path.splitext(f) |
---|
[0f282a5] | 83 | if ext.lower() in EXTENSIONS and f not in IGNORED_FILES: |
---|
[0a51f0d8] | 84 | file_list.append(os.path.join(dir_path, f)) |
---|
| 85 | elif os.path.isdir(os.path.join(dir_path, f)) and \ |
---|
| 86 | not f.startswith("."): |
---|
| 87 | sub_dir = os.path.join(dir_path, f) |
---|
| 88 | for new_f in os.listdir(sub_dir): |
---|
| 89 | if os.path.isfile(os.path.join(sub_dir, new_f)): |
---|
| 90 | _, ext = os.path.splitext(new_f) |
---|
[0f282a5] | 91 | if ext.lower() in EXTENSIONS and\ |
---|
[0a51f0d8] | 92 | new_f not in IGNORED_FILES: |
---|
| 93 | file_list.append(os.path.join(sub_dir, new_f)) |
---|
| 94 | |
---|
| 95 | model_sources = [] |
---|
| 96 | append_file(file_list=model_sources, dir_path=srcdir) |
---|
| 97 | append_file(file_list=model_sources, dir_path=igordir) |
---|
| 98 | append_file(file_list=model_sources, dir_path=c_model_dir) |
---|
| 99 | smear_sources = [] |
---|
| 100 | append_file(file_list=smear_sources, dir_path=smear_dir) |
---|
| 101 | |
---|
| 102 | |
---|
[f9303b6] | 103 | smearer_sources = [os.path.join(smear_dir, "smearer.cpp"), |
---|
| 104 | os.path.join(smear_dir, "smearer_module.cpp")] |
---|
| 105 | if os.name=='nt': |
---|
| 106 | smearer_sources.append(os.path.join(igordir, "winFuncs.c")) |
---|
| 107 | |
---|
[87615a48] | 108 | dist = setup( |
---|
[5953b77] | 109 | name="sansmodels", |
---|
[a2898df] | 110 | version = "1.0.0", |
---|
[ae3ce4e] | 111 | description = "Python module for SANS scattering models", |
---|
[87615a48] | 112 | author = "SANS/DANSE", |
---|
| 113 | author_email = "sansdanse@gmail.gov", |
---|
[ae3ce4e] | 114 | url = "http://danse.us/trac/sans", |
---|
| 115 | |
---|
| 116 | # Place this module under the sans package |
---|
| 117 | #ext_package = "sans", |
---|
| 118 | |
---|
| 119 | # Use the pure python modules |
---|
[0a51f0d8] | 120 | package_dir = {"sans":os.path.join("src", "sans"), |
---|
| 121 | "sans.models":os.path.join("src", "sans", "models"), |
---|
| 122 | "sans.models.sans_extension":srcdir, |
---|
[42c974f] | 123 | }, |
---|
| 124 | package_data={'sans.models': [os.path.join('media', "*")]}, |
---|
| 125 | packages = ["sans","sans.models", |
---|
[0abf7bf] | 126 | "sans.models.sans_extension",], |
---|
[ae3ce4e] | 127 | |
---|
[c089120] | 128 | ext_modules = [ Extension("sans.models.sans_extension.c_models", |
---|
[0b082f3] | 129 | sources=model_sources, |
---|
| 130 | include_dirs=[igordir, srcdir, c_model_dir, numpy_incl_path], |
---|
| 131 | ), |
---|
| 132 | |
---|
[87615a48] | 133 | # Smearer extension |
---|
[c089120] | 134 | Extension("sans.models.sans_extension.smearer", |
---|
[f9303b6] | 135 | sources = smearer_sources, |
---|
[13f00a0] | 136 | include_dirs=[igordir, smear_dir, numpy_incl_path], |
---|
| 137 | ), |
---|
| 138 | |
---|
[c089120] | 139 | Extension("sans.models.sans_extension.smearer2d_helper", |
---|
[0a51f0d8] | 140 | sources = [os.path.join(smear_dir, |
---|
| 141 | "smearer2d_helper_module.cpp"), |
---|
| 142 | os.path.join(smear_dir, "smearer2d_helper.cpp"),], |
---|
[0b082f3] | 143 | include_dirs=[smear_dir,numpy_incl_path], |
---|
[13f00a0] | 144 | ) |
---|
| 145 | ], |
---|
| 146 | cmdclass = {'build_ext': build_ext_subclass } |
---|
[87615a48] | 147 | ) |
---|
[b72b595] | 148 | |
---|