[ae3ce4e] | 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 | - To create odb files: |
---|
| 9 | python setup.py odb |
---|
| 10 | |
---|
| 11 | """ |
---|
[f88624d] | 12 | import sys |
---|
[0f282a5] | 13 | if len(sys.argv) == 1: |
---|
| 14 | sys.argv.append('install') |
---|
[f88624d] | 15 | import os |
---|
[0a51f0d8] | 16 | |
---|
[87615a48] | 17 | |
---|
[b72b595] | 18 | from numpy.distutils.misc_util import get_numpy_include_dirs |
---|
[6c13861] | 19 | numpy_incl_path = os.path.join(get_numpy_include_dirs()[0], "numpy") |
---|
[b72b595] | 20 | |
---|
[ae3ce4e] | 21 | def createODBcontent(class_name): |
---|
| 22 | """ |
---|
| 23 | Return the content of the Pyre odb file for a given class |
---|
| 24 | @param class_name: Name of the class to write an odb file for [string] |
---|
| 25 | @return: content of the file [string] |
---|
| 26 | """ |
---|
| 27 | content = "\"\"\"\n" |
---|
| 28 | content += " Facility for SANS model\n\n" |
---|
| 29 | content += " WARNING: THIS FILE WAS AUTOGENERATED AT INSTALL TIME\n" |
---|
| 30 | content += " DO NOT MODIFY\n\n" |
---|
| 31 | content += " This code was written as part of the DANSE project\n" |
---|
| 32 | content += " http://danse.us/trac/sans/\n" |
---|
| 33 | content += " @copyright 2007:" |
---|
[25579e8] | 34 | content += " SANS/DANSE Group (University of Tennessee), for the DANSE project\n\n" |
---|
[ae3ce4e] | 35 | content += "\"\"\"\n" |
---|
| 36 | content += "def model():\n" |
---|
| 37 | content += " from ScatteringIntensityFactory import ScatteringIntensityFactory\n" |
---|
| 38 | content += " from sans.models.%s import %s\n" % (class_name, class_name) |
---|
| 39 | content += " return ScatteringIntensityFactory(%s)('%s')\n"\ |
---|
| 40 | % (class_name, class_name) |
---|
| 41 | |
---|
| 42 | return content |
---|
| 43 | |
---|
| 44 | def createODBfiles(): |
---|
| 45 | """ |
---|
| 46 | Create odb files for all available models |
---|
| 47 | """ |
---|
| 48 | from sans.models.ModelFactory import ModelFactory |
---|
| 49 | |
---|
| 50 | class_list = ModelFactory().getAllModels() |
---|
| 51 | for name in class_list: |
---|
[0f282a5] | 52 | odb = open("src/sans/models/pyre/%s.odb" % name, 'w') |
---|
[ae3ce4e] | 53 | odb.write(createODBcontent(name)) |
---|
| 54 | odb.close() |
---|
[0f282a5] | 55 | print "src/sans/models/pyre/%s.odb created" % name |
---|
[ae3ce4e] | 56 | |
---|
| 57 | # |
---|
| 58 | # Proceed with installation |
---|
| 59 | # |
---|
| 60 | |
---|
| 61 | # First, create the odb files |
---|
| 62 | if len(sys.argv) > 1 and sys.argv[1].lower() == 'odb': |
---|
| 63 | print "Creating odb files" |
---|
| 64 | try: |
---|
| 65 | createODBfiles() |
---|
| 66 | except: |
---|
| 67 | print "ERROR: could not create odb files" |
---|
| 68 | print sys.exc_value |
---|
| 69 | sys.exit() |
---|
| 70 | |
---|
| 71 | # Then build and install the modules |
---|
[87615a48] | 72 | from distutils.core import Extension, setup |
---|
| 73 | #from setuptools import setup#, find_packages |
---|
[ae3ce4e] | 74 | |
---|
| 75 | # Build the module name |
---|
[0a51f0d8] | 76 | srcdir = os.path.join("src", "sans", "models", "c_extensions") |
---|
| 77 | igordir = os.path.join("src","sans", "models", "libigor") |
---|
| 78 | c_model_dir = os.path.join("src", "sans", "models", "c_models") |
---|
| 79 | smear_dir = os.path.join("src", "sans", "models", "c_smearer") |
---|
[ae3ce4e] | 80 | print "Installing SANS models" |
---|
| 81 | |
---|
| 82 | |
---|
[0a51f0d8] | 83 | IGNORED_FILES = ["a.exe", |
---|
| 84 | "__init__.py" |
---|
| 85 | ".svn", |
---|
| 86 | "lineparser.py", |
---|
| 87 | "run.py", |
---|
| 88 | "CGaussian.cpp", |
---|
| 89 | "CLogNormal.cpp", |
---|
| 90 | "CLorentzian.cpp", |
---|
| 91 | "CSchulz.cpp", |
---|
| 92 | "WrapperGenerator.py", |
---|
| 93 | "wrapping.py", |
---|
| 94 | "winFuncs.c"] |
---|
| 95 | IGNORED_EXTENSIONS = [".h", ".txt", ".def", ".mm", ".hh", ".py"] |
---|
[0f282a5] | 96 | EXTENSIONS = [".c", ".cpp"] |
---|
[0a51f0d8] | 97 | |
---|
| 98 | def append_file(file_list, dir_path): |
---|
| 99 | """ |
---|
| 100 | Add sources file to sources |
---|
| 101 | """ |
---|
| 102 | for f in os.listdir(dir_path): |
---|
| 103 | if os.path.isfile(os.path.join(dir_path, f)): |
---|
| 104 | _, ext = os.path.splitext(f) |
---|
[0f282a5] | 105 | if ext.lower() in EXTENSIONS and f not in IGNORED_FILES: |
---|
[0a51f0d8] | 106 | file_list.append(os.path.join(dir_path, f)) |
---|
| 107 | elif os.path.isdir(os.path.join(dir_path, f)) and \ |
---|
| 108 | not f.startswith("."): |
---|
| 109 | sub_dir = os.path.join(dir_path, f) |
---|
| 110 | for new_f in os.listdir(sub_dir): |
---|
| 111 | if os.path.isfile(os.path.join(sub_dir, new_f)): |
---|
| 112 | _, ext = os.path.splitext(new_f) |
---|
[0f282a5] | 113 | if ext.lower() in EXTENSIONS and\ |
---|
[0a51f0d8] | 114 | new_f not in IGNORED_FILES: |
---|
| 115 | file_list.append(os.path.join(sub_dir, new_f)) |
---|
| 116 | |
---|
| 117 | model_sources = [] |
---|
| 118 | append_file(file_list=model_sources, dir_path=srcdir) |
---|
| 119 | append_file(file_list=model_sources, dir_path=igordir) |
---|
| 120 | append_file(file_list=model_sources, dir_path=c_model_dir) |
---|
| 121 | smear_sources = [] |
---|
| 122 | append_file(file_list=smear_sources, dir_path=smear_dir) |
---|
| 123 | |
---|
| 124 | |
---|
[87615a48] | 125 | dist = setup( |
---|
[ca3072fb] | 126 | name="sans.models", |
---|
[87615a48] | 127 | version = "0.9.1", |
---|
[ae3ce4e] | 128 | description = "Python module for SANS scattering models", |
---|
[87615a48] | 129 | author = "SANS/DANSE", |
---|
| 130 | author_email = "sansdanse@gmail.gov", |
---|
[ae3ce4e] | 131 | url = "http://danse.us/trac/sans", |
---|
| 132 | |
---|
| 133 | # Place this module under the sans package |
---|
| 134 | #ext_package = "sans", |
---|
| 135 | |
---|
| 136 | # Use the pure python modules |
---|
[0a51f0d8] | 137 | package_dir = {"sans":os.path.join("src", "sans"), |
---|
| 138 | "sans.models":os.path.join("src", "sans", "models"), |
---|
| 139 | "sans.models.sans_extension":srcdir, |
---|
[42c974f] | 140 | }, |
---|
| 141 | package_data={'sans.models': [os.path.join('media', "*")]}, |
---|
| 142 | packages = ["sans","sans.models", |
---|
| 143 | "sans.models.sans_extension","sans.models.pyre",], |
---|
[ae3ce4e] | 144 | |
---|
[c089120] | 145 | ext_modules = [ Extension("sans.models.sans_extension.c_models", |
---|
[0a51f0d8] | 146 | sources=model_sources, |
---|
| 147 | |
---|
| 148 | include_dirs=[igordir, srcdir, c_model_dir, numpy_incl_path]), |
---|
[87615a48] | 149 | # Smearer extension |
---|
[c089120] | 150 | Extension("sans.models.sans_extension.smearer", |
---|
[0a51f0d8] | 151 | sources = [os.path.join(smear_dir, |
---|
| 152 | "smearer.cpp"), |
---|
| 153 | os.path.join(smear_dir, "smearer_module.cpp"),], |
---|
| 154 | include_dirs=[smear_dir, numpy_incl_path]), |
---|
[c089120] | 155 | Extension("sans.models.sans_extension.smearer2d_helper", |
---|
[0a51f0d8] | 156 | sources = [os.path.join(smear_dir, |
---|
| 157 | "smearer2d_helper_module.cpp"), |
---|
| 158 | os.path.join(smear_dir, "smearer2d_helper.cpp"),], |
---|
| 159 | include_dirs=[smear_dir,numpy_incl_path] |
---|
[87615a48] | 160 | ) |
---|
| 161 | ] |
---|
| 162 | ) |
---|
[b72b595] | 163 | |
---|