source: sasview/sansmodels/setup.py @ 2636188

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 2636188 was 0f282a5, checked in by Jae Cho <jhjcho@…>, 13 years ago

fixed a bug; trying to compiles the files that are not c or cpp

  • Property mode set to 100644
File size: 5.9 KB
Line 
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"""
12import sys
13if len(sys.argv) == 1:
14    sys.argv.append('install')
15import os
16
17   
18from numpy.distutils.misc_util import get_numpy_include_dirs
19numpy_incl_path = os.path.join(get_numpy_include_dirs()[0], "numpy")
20
21def 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:"
34    content += "  SANS/DANSE Group (University of Tennessee), for the DANSE project\n\n"
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
44def 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:
52        odb = open("src/sans/models/pyre/%s.odb" % name, 'w')
53        odb.write(createODBcontent(name))
54        odb.close()
55        print "src/sans/models/pyre/%s.odb created" % name
56       
57#
58# Proceed with installation
59#
60
61# First, create the odb files
62if 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
72from distutils.core import Extension, setup
73#from setuptools import setup#, find_packages
74
75# Build the module name
76srcdir  = os.path.join("src", "sans", "models", "c_extensions")
77igordir = os.path.join("src","sans", "models", "libigor")
78c_model_dir = os.path.join("src", "sans", "models", "c_models")
79smear_dir  = os.path.join("src", "sans", "models", "c_smearer")
80print "Installing SANS models"
81
82
83IGNORED_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"]
95IGNORED_EXTENSIONS = [".h", ".txt", ".def", ".mm", ".hh", ".py"]
96EXTENSIONS = [".c", ".cpp"]
97
98def 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)
105            if ext.lower() in EXTENSIONS and f not in IGNORED_FILES:
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)
113                    if ext.lower() in EXTENSIONS and\
114                         new_f not in IGNORED_FILES:
115                        file_list.append(os.path.join(sub_dir, new_f)) 
116       
117model_sources = []
118append_file(file_list=model_sources, dir_path=srcdir)
119append_file(file_list=model_sources, dir_path=igordir)
120append_file(file_list=model_sources, dir_path=c_model_dir)
121smear_sources = []
122append_file(file_list=smear_sources, dir_path=smear_dir)
123
124
125dist = setup(
126    name="sans.models",
127    version = "0.9.1",
128    description = "Python module for SANS scattering models",
129    author = "SANS/DANSE",
130    author_email = "sansdanse@gmail.gov",
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
137    package_dir = {"sans":os.path.join("src", "sans"),
138                   "sans.models":os.path.join("src", "sans", "models"),
139                   "sans.models.sans_extension":srcdir,
140                  },
141    package_data={'sans.models': [os.path.join('media', "*")]},
142    packages = ["sans","sans.models",
143                "sans.models.sans_extension","sans.models.pyre",],
144   
145    ext_modules = [ Extension("sans.models.sans_extension.c_models",
146             sources=model_sources,                 
147     
148        include_dirs=[igordir, srcdir, c_model_dir, numpy_incl_path]),       
149        # Smearer extension
150        Extension("sans.models.sans_extension.smearer",
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]),
155        Extension("sans.models.sans_extension.smearer2d_helper",
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]
160        )
161        ]
162    )
163       
Note: See TracBrowser for help on using the repository browser.