[ae3ce4e] | 1 | """ |
---|
[3a39c2e] | 2 | Installation script for SAS models |
---|
[ae3ce4e] | 3 | """ |
---|
[d7a2531] | 4 | |
---|
[f88624d] | 5 | import sys |
---|
| 6 | import os |
---|
[0b082f3] | 7 | import platform |
---|
[b72b595] | 8 | from numpy.distutils.misc_util import get_numpy_include_dirs |
---|
[6c13861] | 9 | numpy_incl_path = os.path.join(get_numpy_include_dirs()[0], "numpy") |
---|
[0abf7bf] | 10 | |
---|
[ae3ce4e] | 11 | # Then build and install the modules |
---|
[87615a48] | 12 | from distutils.core import Extension, setup |
---|
[13f00a0] | 13 | from distutils.command.build_ext import build_ext |
---|
| 14 | |
---|
[592cb156] | 15 | # Manage version number ###################################### |
---|
[3a39c2e] | 16 | sys.path.append(os.path.join("src", "sas")) |
---|
[592cb156] | 17 | import models |
---|
| 18 | VERSION = models.__version__ |
---|
| 19 | print "Building models v%s" % VERSION |
---|
| 20 | ############################################################## |
---|
| 21 | |
---|
[13f00a0] | 22 | # Options to enable OpenMP |
---|
[ebdb833] | 23 | copt = {'msvc': ['/openmp'], |
---|
| 24 | 'mingw32' : ['-fopenmp'], |
---|
| 25 | 'unix' : ['-fopenmp']} |
---|
| 26 | lopt = {'msvc': ['/MANIFEST'], |
---|
| 27 | 'mingw32' : ['-fopenmp'], |
---|
| 28 | 'unix' : ['-lgomp']} |
---|
| 29 | |
---|
| 30 | # Options for non-openmp builds. MSVC always needs MANIFEST |
---|
[5c77050] | 31 | if sys.argv[-1] == "-nomp": |
---|
[8b8a03f] | 32 | copt = {} |
---|
[ebdb833] | 33 | lopt = {'msvc': ['/MANIFEST']} |
---|
[13f00a0] | 34 | |
---|
| 35 | class build_ext_subclass( build_ext ): |
---|
| 36 | def build_extensions(self): |
---|
| 37 | # Get 64-bitness |
---|
[d9673d7a] | 38 | if sys.version_info >= (2, 6): |
---|
| 39 | is_64bits = sys.maxsize > 2**32 |
---|
| 40 | else: |
---|
| 41 | # 'sys.maxsize' and 64bit: Not supported for python2.5 |
---|
| 42 | is_64bits = False |
---|
[13f00a0] | 43 | c = self.compiler.compiler_type |
---|
| 44 | print "Compiling with %s (64bit=%s)" % (c, str(is_64bits)) |
---|
[ebdb833] | 45 | |
---|
[13f00a0] | 46 | if not (sys.platform=='darwin' and not is_64bits): |
---|
| 47 | if copt.has_key(c): |
---|
| 48 | for e in self.extensions: |
---|
| 49 | e.extra_compile_args = copt[ c ] |
---|
| 50 | if lopt.has_key(c): |
---|
| 51 | for e in self.extensions: |
---|
| 52 | e.extra_link_args = lopt[ c ] |
---|
| 53 | |
---|
| 54 | build_ext.build_extensions(self) |
---|
[ae3ce4e] | 55 | |
---|
| 56 | # Build the module name |
---|
[503a972] | 57 | includedir = "include" |
---|
[67424cd] | 58 | igordir = os.path.join("src", "libigor") |
---|
| 59 | c_model_dir = os.path.join("src", "c_models") |
---|
| 60 | smear_dir = os.path.join("src", "c_smearer") |
---|
[26e0249] | 61 | wrapper_dir = os.path.join("src", "python_wrapper", "generated") |
---|
[592cb156] | 62 | if not os.path.isdir(wrapper_dir): |
---|
| 63 | os.makedirs(wrapper_dir) |
---|
[ae3ce4e] | 64 | |
---|
[26e0249] | 65 | sys.path.append(os.path.join("src", "python_wrapper")) |
---|
[0ba3b08] | 66 | from wrapping import generate_wrappers |
---|
[886dde6b] | 67 | generate_wrappers(header_dir=includedir, |
---|
[3a39c2e] | 68 | output_dir=os.path.join("src", "sas", "models"), |
---|
[0ba3b08] | 69 | c_wrapper_dir=wrapper_dir) |
---|
[ae3ce4e] | 70 | |
---|
[101065a] | 71 | IGNORED_FILES = [".svn"] |
---|
[f9303b6] | 72 | if not os.name=='nt': |
---|
| 73 | IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"]) |
---|
| 74 | |
---|
[0f282a5] | 75 | EXTENSIONS = [".c", ".cpp"] |
---|
[0a51f0d8] | 76 | |
---|
| 77 | def append_file(file_list, dir_path): |
---|
| 78 | """ |
---|
| 79 | Add sources file to sources |
---|
| 80 | """ |
---|
| 81 | for f in os.listdir(dir_path): |
---|
| 82 | if os.path.isfile(os.path.join(dir_path, f)): |
---|
| 83 | _, ext = os.path.splitext(f) |
---|
[0f282a5] | 84 | if ext.lower() in EXTENSIONS and f not in IGNORED_FILES: |
---|
[0a51f0d8] | 85 | file_list.append(os.path.join(dir_path, f)) |
---|
| 86 | elif os.path.isdir(os.path.join(dir_path, f)) and \ |
---|
| 87 | not f.startswith("."): |
---|
| 88 | sub_dir = os.path.join(dir_path, f) |
---|
| 89 | for new_f in os.listdir(sub_dir): |
---|
| 90 | if os.path.isfile(os.path.join(sub_dir, new_f)): |
---|
| 91 | _, ext = os.path.splitext(new_f) |
---|
[0f282a5] | 92 | if ext.lower() in EXTENSIONS and\ |
---|
[0a51f0d8] | 93 | new_f not in IGNORED_FILES: |
---|
| 94 | file_list.append(os.path.join(sub_dir, new_f)) |
---|
| 95 | |
---|
| 96 | model_sources = [] |
---|
| 97 | append_file(file_list=model_sources, dir_path=igordir) |
---|
| 98 | append_file(file_list=model_sources, dir_path=c_model_dir) |
---|
[67424cd] | 99 | append_file(file_list=model_sources, dir_path=wrapper_dir) |
---|
[0a51f0d8] | 100 | smear_sources = [] |
---|
| 101 | append_file(file_list=smear_sources, dir_path=smear_dir) |
---|
| 102 | |
---|
| 103 | |
---|
[f9303b6] | 104 | smearer_sources = [os.path.join(smear_dir, "smearer.cpp"), |
---|
| 105 | os.path.join(smear_dir, "smearer_module.cpp")] |
---|
| 106 | if os.name=='nt': |
---|
| 107 | smearer_sources.append(os.path.join(igordir, "winFuncs.c")) |
---|
| 108 | |
---|
[87615a48] | 109 | dist = setup( |
---|
[3a39c2e] | 110 | name="sasmodels", |
---|
[592cb156] | 111 | version = VERSION, |
---|
[3a39c2e] | 112 | description = "Python module for SAS scattering models", |
---|
[038ccfe6] | 113 | author = "SasView Team", |
---|
| 114 | author_email = "developers@sasview.org", |
---|
| 115 | url = "https://github.com/SasView/sasview.git", |
---|
[ae3ce4e] | 116 | |
---|
[3a39c2e] | 117 | # Place this module under the sas package |
---|
| 118 | #ext_package = "sas", |
---|
[ae3ce4e] | 119 | |
---|
| 120 | # Use the pure python modules |
---|
[3a39c2e] | 121 | package_dir = {"sas":os.path.join("src", "sas"), |
---|
| 122 | "sas.models":os.path.join("src", "sas", "models"), |
---|
| 123 | "sas.models.sas_extension":os.path.join("src", "sas", "models", "sas_extension"), |
---|
[42c974f] | 124 | }, |
---|
[3a39c2e] | 125 | package_data={'sas.models': [os.path.join('media', "*")]}, |
---|
| 126 | packages = ["sas","sas.models", |
---|
| 127 | "sas.models.sas_extension",], |
---|
[ae3ce4e] | 128 | |
---|
[67424cd] | 129 | ext_modules = [ |
---|
| 130 | |
---|
[3a39c2e] | 131 | Extension("sas.models.sas_extension.c_models", |
---|
[67424cd] | 132 | sources=model_sources, |
---|
[886dde6b] | 133 | include_dirs=[igordir, includedir, c_model_dir, numpy_incl_path], |
---|
[67424cd] | 134 | ), |
---|
| 135 | |
---|
[87615a48] | 136 | # Smearer extension |
---|
[3a39c2e] | 137 | Extension("sas.models.sas_extension.smearer", |
---|
[f9303b6] | 138 | sources = smearer_sources, |
---|
[13f00a0] | 139 | include_dirs=[igordir, smear_dir, numpy_incl_path], |
---|
| 140 | ), |
---|
| 141 | |
---|
[3a39c2e] | 142 | Extension("sas.models.sas_extension.smearer2d_helper", |
---|
[0a51f0d8] | 143 | sources = [os.path.join(smear_dir, |
---|
| 144 | "smearer2d_helper_module.cpp"), |
---|
| 145 | os.path.join(smear_dir, "smearer2d_helper.cpp"),], |
---|
[0b082f3] | 146 | include_dirs=[smear_dir,numpy_incl_path], |
---|
[13f00a0] | 147 | ) |
---|
| 148 | ], |
---|
| 149 | cmdclass = {'build_ext': build_ext_subclass } |
---|
[87615a48] | 150 | ) |
---|
[b72b595] | 151 | |
---|