source: sasview/run.py @ 95d58d3

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 95d58d3 was 95d58d3, checked in by pkienzle, 10 years ago

fix fit line test for bumps/scipy/park and enable it as part of test suite

  • Property mode set to 100755
File size: 4.2 KB
Line 
1#!/usr/bin/env python
2"""
3Run sasview in place.  This allows sasview to use the python
4files in the source tree without having to call setup.py install
5first.  A rebuild is still necessary when working on sans models
6or c modules.
7
8Usage:
9
10./run.py [(module|script) args...]
11
12Without arguments run.py runs sasview.  With arguments, run.py will run
13the given module or script.
14"""
15
16import os
17import sys
18import imp
19from glob import glob
20from contextlib import contextmanager
21from os.path import abspath, dirname, join as joinpath
22
23
24def addpath(path):
25    """
26    Add a directory to the python path environment, and to the PYTHONPATH
27    environment variable for subprocesses.
28    """
29    path = abspath(path)
30    if 'PYTHONPATH' in os.environ:
31        PYTHONPATH = path + os.pathsep + os.environ['PYTHONPATH']
32    else:
33        PYTHONPATH = path
34    os.environ['PYTHONPATH'] = PYTHONPATH
35    sys.path.insert(0, path)
36
37@contextmanager
38def cd(path):
39    """
40    Change directory for duration of "with" context.
41    """
42    old_dir = os.getcwd()
43    os.chdir(path)
44    yield
45    os.chdir(old_dir)
46
47def import_package(modname, path):
48    """Import a package into a particular point in the python namespace"""
49    mod = imp.load_source(modname, abspath(joinpath(path,'__init__.py')))
50    sys.modules[modname] = mod
51    mod.__path__ = [abspath(path)]
52    return mod
53
54def import_dll(modname):
55    """Import a DLL from the build directory"""
56    # build_path comes from context
57    path = glob(joinpath(build_path, *modname.split('.'))+'.*')[0]
58    #print "importing", modname, "from", path
59    return imp.load_dynamic(modname, path)
60
61def prepare():
62    # Don't create *.pyc files
63    sys.dont_write_bytecode = True
64
65    # Debug numpy warnings
66    #import numpy; numpy.seterr(all='raise')
67
68    # find the directories for the source and build
69    from distutils.util import get_platform
70    root = abspath(dirname(__file__))
71    platform = '%s-%s'%(get_platform(),sys.version[:3])
72    build_path = joinpath(root, 'build','lib.'+platform)
73
74    # Make sure that we have a private version of mplconfig
75    mplconfig = joinpath(abspath(dirname(__file__)), '.mplconfig')
76    os.environ['MPLCONFIGDIR'] = mplconfig
77    if not os.path.exists(mplconfig): os.mkdir(mplconfig)
78    #import matplotlib
79    #matplotlib.use('Agg')
80    #print matplotlib.__file__
81    #import pylab; pylab.hold(False)
82    # add periodictable to the path
83    try: import periodictable
84    except: addpath(joinpath(root, '..','periodictable'))
85
86    try: import bumps
87    except: addpath(joinpath(root, '..','bumps'))
88
89    # select wx version
90    #addpath(os.path.join(root, '..','wxPython-src-3.0.0.0','wxPython'))
91
92    # Build project if the build directory does not already exist.
93    if not os.path.exists(build_path):
94        import subprocess
95        with cd(root):
96            subprocess.call((sys.executable, "setup.py", "build"), shell=False)
97
98    # Put the source trees on the path
99    addpath(joinpath(root, 'src'))
100    addpath(joinpath(root, 'park-1.2.1'))
101
102    # Import the sansview package from root/sansview as sans.sansview.  It would
103    # be better to just store the package in src/sans/sansview.
104    import sans
105    sans.sansview = import_package('sans.sansview', joinpath(root,'sansview'))
106
107    # The sans.models package Compiled Model files should be pulled in from the build directory even though
108    # the source is stored in src/sans/models.
109
110    # Compiled modules need to be pulled from the build directory.
111    # Some packages are not where they are needed, so load them explicitly.
112    import sans.pr
113    sans.pr.core = import_package('sans.pr.core',
114                                  joinpath(build_path, 'sans', 'pr', 'core'))
115    #import_dll('park._modeling')
116
117    #park = import_package('park',os.path.join(build_path,'park'))
118
119    # Pull the entire sans.models package from the build directory since it contains
120    # a mixture of autogenerated python and C.  Any changes in models will require
121    # a rebuild with setup.py build
122    sans.models = import_package('sans.models', joinpath(build_path, 'sans', 'models'))
123
124    sys.path.append(build_path)
125
126    #print "\n".join(sys.path)
127    #from sans.models import SphereModel
128
129if __name__ == "__main__":
130    prepare()
131    from sans.sansview.sansview import run
132    run()
Note: See TracBrowser for help on using the repository browser.