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