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 | """ |
---|
12 | import sys |
---|
13 | |
---|
14 | def createODBcontent(class_name): |
---|
15 | """ |
---|
16 | Return the content of the Pyre odb file for a given class |
---|
17 | @param class_name: Name of the class to write an odb file for [string] |
---|
18 | @return: content of the file [string] |
---|
19 | """ |
---|
20 | content = "\"\"\"\n" |
---|
21 | content += " Facility for SANS model\n\n" |
---|
22 | content += " WARNING: THIS FILE WAS AUTOGENERATED AT INSTALL TIME\n" |
---|
23 | content += " DO NOT MODIFY\n\n" |
---|
24 | content += " This code was written as part of the DANSE project\n" |
---|
25 | content += " http://danse.us/trac/sans/\n" |
---|
26 | content += " @copyright 2007:" |
---|
27 | content += " Mathieu Doucet (University of Tennessee), for the DANSE project\n\n" |
---|
28 | content += "\"\"\"\n" |
---|
29 | content += "def model():\n" |
---|
30 | content += " from ScatteringIntensityFactory import ScatteringIntensityFactory\n" |
---|
31 | content += " from sans.models.%s import %s\n" % (class_name, class_name) |
---|
32 | content += " return ScatteringIntensityFactory(%s)('%s')\n"\ |
---|
33 | % (class_name, class_name) |
---|
34 | |
---|
35 | return content |
---|
36 | |
---|
37 | def createODBfiles(): |
---|
38 | """ |
---|
39 | Create odb files for all available models |
---|
40 | """ |
---|
41 | from sans.models.ModelFactory import ModelFactory |
---|
42 | |
---|
43 | class_list = ModelFactory().getAllModels() |
---|
44 | for name in class_list: |
---|
45 | odb = open("sans/models/pyre/%s.odb" % name, 'w') |
---|
46 | odb.write(createODBcontent(name)) |
---|
47 | odb.close() |
---|
48 | print "sans/models/pyre/%s.odb created" % name |
---|
49 | |
---|
50 | # |
---|
51 | # Proceed with installation |
---|
52 | # |
---|
53 | |
---|
54 | # First, create the odb files |
---|
55 | if len(sys.argv) > 1 and sys.argv[1].lower() == 'odb': |
---|
56 | print "Creating odb files" |
---|
57 | try: |
---|
58 | createODBfiles() |
---|
59 | except: |
---|
60 | print "ERROR: could not create odb files" |
---|
61 | print sys.exc_value |
---|
62 | sys.exit() |
---|
63 | |
---|
64 | # Then build and install the modules |
---|
65 | from distutils.core import setup, Extension |
---|
66 | |
---|
67 | |
---|
68 | # Build the module name |
---|
69 | srcdir = "sans/models/c_extensions" |
---|
70 | igordir = "libigor" |
---|
71 | |
---|
72 | print "Installing SANS models" |
---|
73 | |
---|
74 | |
---|
75 | setup( |
---|
76 | name="models", |
---|
77 | version = "0.1", |
---|
78 | description = "Python module for SANS scattering models", |
---|
79 | author = "Mathieu Doucet", |
---|
80 | author_email = "doucet@nist.gov", |
---|
81 | url = "http://danse.us/trac/sans", |
---|
82 | |
---|
83 | # Place this module under the sans package |
---|
84 | #ext_package = "sans", |
---|
85 | |
---|
86 | # Use the pure python modules |
---|
87 | package_dir = {"sans_extension":"sans/models/c_extensions"}, |
---|
88 | |
---|
89 | packages = ["sans","sans.models","sans.models.test", |
---|
90 | "sans_extension","sans.models.pyre"], |
---|
91 | |
---|
92 | ext_modules = [ Extension("sans_extension.c_models", |
---|
93 | sources = [ |
---|
94 | srcdir+"/c_models.c", |
---|
95 | srcdir+"/CSphereModel.c", |
---|
96 | srcdir+"/sphere.c", |
---|
97 | srcdir+"/CCylinderModel.c", |
---|
98 | srcdir+"/cylinder.c", |
---|
99 | srcdir+"/CCoreShellCylinderModel.c", |
---|
100 | srcdir+"/core_shell_cylinder.c", |
---|
101 | srcdir+"/CCoreShellModel.c", |
---|
102 | srcdir+"/core_shell.c", |
---|
103 | srcdir+"/CEllipsoidModel.c", |
---|
104 | srcdir+"/ellipsoid.c", |
---|
105 | srcdir+"/CEllipticalCylinderModel.c", |
---|
106 | srcdir+"/elliptical_cylinder.c", |
---|
107 | srcdir+"/disperser.c", |
---|
108 | igordir+"/libCylinder.c", |
---|
109 | igordir+"/libSphere.c", |
---|
110 | srcdir+"/gaussian.c", |
---|
111 | srcdir+"/CGaussian.c", |
---|
112 | srcdir+"/lorentzian.c", |
---|
113 | srcdir+"/CLorentzian.c" |
---|
114 | ], |
---|
115 | include_dirs=[igordir])]) |
---|
116 | |
---|