Changeset bbd97e5 in sasview for run.py


Ignore:
Timestamp:
Apr 3, 2014 8:59:01 PM (10 years ago)
Author:
pkienzle
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
eea06fe
Parents:
27b7acc
Message:

Allow tests to be run without installing sasview

File:
1 edited

Legend:

Unmodified
Added
Removed
  • run.py

    r2f2d9d0 rbbd97e5  
    1515import imp 
    1616from glob import glob 
     17from contextlib import contextmanager 
     18from os.path import abspath, dirname, join as joinpath 
    1719 
    18 # find the directories for the source and build 
    19 from distutils.util import get_platform 
    20 root = os.path.abspath(os.path.dirname(__file__)) 
    21 platform = '%s-%s'%(get_platform(),sys.version[:3]) 
    22 build_path = os.path.join(root, 'build','lib.'+platform) 
    23  
    24 # Make sure that we have a private version of mplconfig 
    25 mplconfig = os.path.join(os.getcwd(), '.mplconfig') 
    26 os.environ['MPLCONFIGDIR'] = mplconfig 
    27 if 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) 
    3220 
    3321def addpath(path): 
     
    3624    environment variable for subprocesses. 
    3725    """ 
    38     path = os.path.abspath(path) 
     26    path = abspath(path) 
    3927    if 'PYTHONPATH' in os.environ: 
    4028        PYTHONPATH = path + os.pathsep + os.environ['PYTHONPATH'] 
     
    4432    sys.path.insert(0, path) 
    4533 
    46 from contextlib import contextmanager 
    4734@contextmanager 
    4835def cd(path): 
     
    5744def import_package(modname, path): 
    5845    """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'))) 
     46    mod = imp.load_source(modname, abspath(joinpath(path,'__init__.py'))) 
    6047    sys.modules[modname] = mod 
    61     mod.__path__ = [os.path.abspath(path)] 
     48    mod.__path__ = [abspath(path)] 
    6249    return mod 
    6350 
     
    6552    """Import a DLL from the build directory""" 
    6653    # build_path comes from context 
    67     path = glob(os.path.join(build_path, *modname.split('.'))+'.*')[0] 
     54    path = glob(joinpath(build_path, *modname.split('.'))+'.*')[0] 
    6855    #print "importing", modname, "from", path 
    6956    return imp.load_dynamic(modname, path) 
    7057 
     58def prepare(): 
     59    # Don't create *.pyc files 
     60    sys.dont_write_bytecode = True 
    7161 
    72 # Don't create *.pyc files 
    73 sys.dont_write_bytecode = True 
     62    # Debug numpy warnings 
     63    #import numpy; numpy.seterr(all='raise') 
    7464 
    75 # Debug numpy warnings 
    76 #import numpy; numpy.seterr(all='raise') 
     65    # find the directories for the source and build 
     66    from distutils.util import get_platform 
     67    root = abspath(dirname(__file__)) 
     68    platform = '%s-%s'%(get_platform(),sys.version[:3]) 
     69    build_path = joinpath(root, 'build','lib.'+platform) 
    7770 
    78 # add periodictable to the path 
    79 try: import periodictable 
    80 except: addpath(os.path.join(root, '..','periodictable')) 
     71    # Make sure that we have a private version of mplconfig 
     72    mplconfig = joinpath(abspath(dirname(__file__)), '.mplconfig') 
     73    os.environ['MPLCONFIGDIR'] = mplconfig 
     74    if not os.path.exists(mplconfig): os.mkdir(mplconfig) 
     75    #import matplotlib 
     76    #matplotlib.use('Agg') 
     77    #print matplotlib.__file__ 
     78    #import pylab; pylab.hold(False) 
     79    # add periodictable to the path 
     80    try: import periodictable 
     81    except: addpath(joinpath(root, '..','periodictable')) 
    8182 
    82 # select wx version 
    83 #addpath(os.path.join(root, '..','wxPython-src-3.0.0.0','wxPython')) 
     83    # select wx version 
     84    #addpath(os.path.join(root, '..','wxPython-src-3.0.0.0','wxPython')) 
    8485 
    85 # Build project if the build directory does not already exist. 
    86 if not os.path.exists(build_path): 
    87     import subprocess 
    88     with cd(root): 
    89         subprocess.call((sys.executable, "setup.py", "build"), shell=False) 
     86    # Build project if the build directory does not already exist. 
     87    if not os.path.exists(build_path): 
     88        import subprocess 
     89        with cd(root): 
     90            subprocess.call((sys.executable, "setup.py", "build"), shell=False) 
    9091 
    91 # Put the source trees on the path 
    92 addpath(os.path.join(root, 'src')) 
    93 addpath(os.path.join(root, 'park-1.2.1')) 
     92    # Put the source trees on the path 
     93    addpath(joinpath(root, 'src')) 
     94    addpath(joinpath(root, 'park-1.2.1')) 
    9495 
    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. 
    97 import sans 
    98 sans.sansview = import_package('sans.sansview', os.path.join(root,'sansview')) 
     96    # Import the sansview package from root/sansview as sans.sansview.  It would 
     97    # be better to just store the package in src/sans/sansview. 
     98    import sans 
     99    sans.sansview = import_package('sans.sansview', joinpath(root,'sansview')) 
    99100 
    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. 
     101    # The sans.models package Compiled Model files should be pulled in from the build directory even though 
     102    # the source is stored in src/sans/models. 
    102103 
    103 # Compiled modules need to be pulled from the build directory. 
    104 # Some packages are not where they are needed, so load them explicitly. 
    105 import sans.pr 
    106 sans.pr.core = import_package('sans.pr.core', 
    107                               os.path.join(build_path, 'sans', 'pr', 'core')) 
    108 #import_dll('park._modeling') 
     104    # Compiled modules need to be pulled from the build directory. 
     105    # Some packages are not where they are needed, so load them explicitly. 
     106    import sans.pr 
     107    sans.pr.core = import_package('sans.pr.core', 
     108                                  joinpath(build_path, 'sans', 'pr', 'core')) 
     109    #import_dll('park._modeling') 
    109110 
    110 #park = import_package('park',os.path.join(build_path,'park')) 
     111    #park = import_package('park',os.path.join(build_path,'park')) 
    111112 
    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 
    115 sans.models = import_package('sans.models', os.path.join(build_path, 'sans', 'models')) 
     113    # Pull the entire sans.models package from the build directory since it contains 
     114    # a mixture of autogenerated python and C.  Any changes in models will require 
     115    # a rebuild with setup.py build 
     116    sans.models = import_package('sans.models', joinpath(build_path, 'sans', 'models')) 
    116117 
    117 sys.path.append(build_path) 
     118    sys.path.append(build_path) 
    118119 
    119 #print "\n".join(sys.path) 
    120 #from sans.models import SphereModel 
     120    #print "\n".join(sys.path) 
     121    #from sans.models import SphereModel 
    121122 
    122 # Won't need freeze support when running from the source tree 
    123 #import multiprocessing 
    124 #multiprocessing.freeze_support() 
    125  
    126 # start sasview 
    127 from sans.sansview.sansview import SasView 
    128 SasView() 
     123if __name__ == "__main__": 
     124    # start sasview 
     125    #import multiprocessing 
     126    #multiprocessing.freeze_support() 
     127    prepare() 
     128    from sans.sansview.sansview import SasView 
     129    SasView() 
Note: See TracChangeset for help on using the changeset viewer.