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