source: sasview/run.py @ eea3ffa

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 eea3ffa was d7b46e71, checked in by ajj, 11 years ago

"fix" to run.py to solve crashing problem with import of park shared library

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