Changeset 6c497b7 in sasview for run.py


Ignore:
Timestamp:
Apr 16, 2017 1:01:30 PM (7 years ago)
Author:
Paul Kienzle <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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
f94a935
Parents:
de99a5f0 (diff), e5cbbce (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into log_binning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • run.py

    r168d359 r6c497b7  
     1# -*- coding: utf-8 -*- 
    12#!/usr/bin/env python 
     3 
    24""" 
    35Run sasview in place.  This allows sasview to use the python 
     
    1416""" 
    1517 
     18import imp 
    1619import os 
    1720import sys 
    18 import imp 
    19 import logging 
    20 import logging.config 
    21  
    2221from contextlib import contextmanager 
    23 from os.path import abspath, dirname, join as joinpath 
     22from os.path import join as joinpath 
     23from os.path import abspath, dirname 
    2424 
    2525 
    26 LOGGER_CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'sasview/logging.ini') 
    27 logging.config.fileConfig(LOGGER_CONFIG_FILE, disable_existing_loggers=True) 
    28 logger = logging.getLogger(__name__) 
    29  
    30 def update_all_logs_to_debug(logger): 
    31     ''' 
    32     This updates all loggers and respective handlers to DEBUG 
    33     ''' 
    34     for handler in logger.handlers or logger.parent.handlers: 
    35         handler.setLevel(logging.DEBUG) 
    36     for name,_ in logging.Logger.manager.loggerDict.items(): 
    37         logging.getLogger(name).setLevel(logging.DEBUG) 
    38          
    3926def addpath(path): 
    4027    """ 
     
    5037    sys.path.insert(0, path) 
    5138 
     39 
    5240@contextmanager 
    5341def cd(path): 
     
    6048    os.chdir(old_dir) 
    6149 
     50 
    6251def import_package(modname, path): 
    6352    """Import a package into a particular point in the python namespace""" 
    6453    logger.debug("Dynamicly importing: %s", path) 
    65     mod = imp.load_source(modname, abspath(joinpath(path,'__init__.py'))) 
     54    mod = imp.load_source(modname, abspath(joinpath(path, '__init__.py'))) 
    6655    sys.modules[modname] = mod 
    6756    mod.__path__ = [abspath(path)] 
    6857    return mod 
     58 
    6959 
    7060def import_dll(modname, build_path): 
     
    7363    ext = sysconfig.get_config_var('SO') 
    7464    # build_path comes from context 
    75     path = joinpath(build_path, *modname.split('.'))+ext 
    76     #print "importing", modname, "from", path 
     65    path = joinpath(build_path, *modname.split('.')) + ext 
     66    # print "importing", modname, "from", path 
    7767    return imp.load_dynamic(modname, path) 
     68 
    7869 
    7970def prepare(): 
     
    8778    from distutils.util import get_platform 
    8879    root = abspath(dirname(__file__)) 
    89     platform = '%s-%s'%(get_platform(),sys.version[:3]) 
    90     build_path = joinpath(root, 'build','lib.'+platform) 
     80    platform = '%s-%s' % (get_platform(), sys.version[:3]) 
     81    build_path = joinpath(root, 'build', 'lib.' + platform) 
    9182 
    9283    # Notify the help menu that the Sphinx documentation is in a different 
     
    9990    #if not os.path.exists(mplconfig): os.mkdir(mplconfig) 
    10091    #import matplotlib 
    101     #matplotlib.use('Agg') 
    102     #print matplotlib.__file__ 
     92    # matplotlib.use('Agg') 
     93    # print matplotlib.__file__ 
    10394    #import pylab; pylab.hold(False) 
    10495    # add periodictable to the path 
    105     try: import periodictable 
    106     except: addpath(joinpath(root, '..','periodictable')) 
     96    try: 
     97        import periodictable 
     98    except: 
     99        addpath(joinpath(root, '..', 'periodictable')) 
    107100 
    108     try: import bumps 
    109     except: addpath(joinpath(root, '..','bumps')) 
     101    try: 
     102        import bumps 
     103    except: 
     104        addpath(joinpath(root, '..', 'bumps')) 
    110105 
    111106    # select wx version 
     
    127122    # be better to just store the package in src/sas/sasview. 
    128123    import sas 
    129     sas.sasview = import_package('sas.sasview', joinpath(root,'sasview')) 
     124    sas.sasview = import_package('sas.sasview', joinpath(root, 'sasview')) 
    130125 
    131126    # The sas.models package Compiled Model files should be pulled in from the build directory even though 
     
    136131    import sas.sascalc.pr 
    137132    sas.sascalc.pr.core = import_package('sas.sascalc.pr.core', 
    138                                   joinpath(build_path, 'sas', 'sascalc', 'pr', 'core')) 
     133                                         joinpath(build_path, 'sas', 'sascalc', 'pr', 'core')) 
    139134 
    140135    # Compiled modules need to be pulled from the build directory. 
     
    142137    import sas.sascalc.file_converter 
    143138    sas.sascalc.file_converter.core = import_package('sas.sascalc.file_converter.core', 
    144                                   joinpath(build_path, 'sas', 'sascalc', 'file_converter', 'core'))                     
     139                                                     joinpath(build_path, 'sas', 'sascalc', 'file_converter', 'core')) 
    145140 
    146141    # Compiled modules need to be pulled from the build directory. 
     
    148143    import sas.sascalc.calculator 
    149144    sas.sascalc.calculator.core = import_package('sas.sascalc.calculator.core', 
    150                                   joinpath(build_path, 'sas', 'sascalc', 'calculator', 'core')) 
     145                                                 joinpath(build_path, 'sas', 'sascalc', 'calculator', 'core')) 
    151146 
    152147    sys.path.append(build_path) 
    153148 
    154     #print "\n".join(sys.path) 
     149    # print "\n".join(sys.path) 
     150 
    155151 
    156152if __name__ == "__main__": 
    157     update_all_logs_to_debug(logger) 
     153    # Need to add absolute path before actual prepare call, 
     154    # so logging can be done during initialization process too 
     155    root = abspath(dirname(__file__)) 
     156    addpath(joinpath(root, 'sasview')) 
     157    from logger_config import SetupLogger 
     158    logger = SetupLogger(__name__).config_development() 
     159 
     160    logger.debug("Starting SASVIEW in debug mode.") 
    158161    prepare() 
    159162    from sas.sasview.sasview import run 
    160163    run() 
    161      
     164    logger.debug("Ending SASVIEW in debug mode.") 
Note: See TracChangeset for help on using the changeset viewer.